-
Notifications
You must be signed in to change notification settings - Fork 4
/
julian_test.go
52 lines (42 loc) · 1021 Bytes
/
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
package isoweek_test
import (
"fmt"
"testing"
"time"
"github.com/snabb/isoweek"
)
func TestJulianToDate(test *testing.T) {
j := isoweek.DateToJulian(1, time.January, 1)
for {
y, m, d := isoweek.JulianToDate(j)
if y >= 4000 {
break
}
if j != isoweek.DateToJulian(y, m, d) {
test.Errorf("mismatch on %04d-%02d-%02d", y, m, d)
}
j++
}
}
func TestDateToJulian(test *testing.T) {
t := time.Date(1, time.January, 1, 0, 0, 0, 0, time.UTC)
for t.Year() < 4000 {
j := isoweek.DateToJulian(t.Date())
y, m, d := isoweek.JulianToDate(j)
if y != t.Year() || m != t.Month() || d != t.Day() {
test.Errorf("mismatch on %s", t.Format("2006-01-02"))
}
if j+1 != isoweek.DateToJulian(y, m, d+1) {
test.Errorf("mismatch 2 on %s", t.Format("2006-01-02"))
}
t = t.AddDate(0, 0, 1)
}
}
func ExampleDateToJulian() {
fmt.Println(isoweek.DateToJulian(2006, 1, 2))
// Output: 2453738
}
func ExampleJulianToDate() {
fmt.Println(isoweek.JulianToDate(2453738))
// Output: 2006 January 2
}