-
Notifications
You must be signed in to change notification settings - Fork 2
/
julian_test.go
66 lines (55 loc) · 1.1 KB
/
julian_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package julian
import (
"testing"
"time"
)
const TestJD = 2458520
func TestGregorianConversion(t *testing.T) {
t.Run("from gregorian", func(t *testing.T) {
jd := FromGregorian(2019, 2, 5)
if jd != TestJD {
t.Fail()
}
})
t.Run("from time", func(t *testing.T) {
tmp := time.Date(2019, 2, 5, 12, 0, 0, 0, time.UTC)
jd := FromTime(tmp)
if jd != TestJD {
t.Fail()
}
})
}
func TestJulianConversion(t *testing.T) {
jd := Day(TestJD)
t.Run("to gregorian", func(t *testing.T) {
y, m, d := jd.ToGregorian()
if y != 2019 || m != 2 || d != 5 {
t.Fail()
}
})
t.Run("to time", func(t *testing.T) {
tmp := jd.ToTime(time.UTC)
if tmp.Year() != 2019 || tmp.Month() != time.February || tmp.Day() != 5 || tmp.Hour() != 12 {
t.Fail()
}
})
}
func TestWeekDay(t *testing.T) {
jd := Day(TestJD)
if jd.WeekDay() != 2 { //tuesday
t.Fail()
}
}
func TestArithmetic(t *testing.T) {
jd := Day(TestJD)
t.Run("retreat", func(t *testing.T) {
if jd.Sub(5).Int() != TestJD-5 {
t.Fail()
}
})
t.Run("advance", func(t *testing.T) {
if jd.Add(5).Int() != TestJD+5 {
t.Fail()
}
})
}