func TestPredicates(t *testing.T) { // The list of case dates must be sorted in ascending order cases := []struct { year int month time.Month day int }{ {-1234, time.February, 5}, {0, time.April, 12}, {1, time.January, 1}, {1946, time.February, 4}, {1970, time.January, 1}, {1976, time.April, 1}, {1999, time.December, 1}, {1111111, time.June, 21}, } for i, ci := range cases { di := date.New(ci.year, ci.month, ci.day) for j, cj := range cases { dj := date.New(cj.year, cj.month, cj.day) p := di.Equal(dj) q := i == j if p != q { t.Errorf("Equal(%v, %v) == %v, want %v", di, dj, p, q) } p = di.Before(dj) q = i < j if p != q { t.Errorf("Before(%v, %v) == %v, want %v", di, dj, p, q) } p = di.After(dj) q = i > j if p != q { t.Errorf("After(%v, %v) == %v, want %v", di, dj, p, q) } p = di == dj q = i == j if p != q { t.Errorf("Equal(%v, %v) == %v, want %v", di, dj, p, q) } p = di != dj q = i != j if p != q { t.Errorf("Equal(%v, %v) == %v, want %v", di, dj, p, q) } } } // Test IsZero zero := date.Date{} if !zero.IsZero() { t.Errorf("IsZero(%v) == false, want true", zero) } today := date.Today() if today.IsZero() { t.Errorf("IsZero(%v) == true, want false", today) } }
func TestToday(t *testing.T) { today := date.Today() now := time.Now() if !same(today, now) { t.Errorf("Today == %v, want date of %v", today, now) } today = date.TodayUTC() now = time.Now().UTC() if !same(today, now) { t.Errorf("TodayUTC == %v, want date of %v", today, now) } cases := []int{-10, -5, -3, 0, 1, 4, 8, 12} for _, c := range cases { location := time.FixedZone("zone", c*60*60) today = date.TodayIn(location) now = time.Now().In(location) if !same(today, now) { t.Errorf("TodayIn(%v) == %v, want date of %v", c, today, now) } } }