Example #1
0
func xTestAddDuration(t *testing.T) {
	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},
	}
	offsets := []PeriodOfDays{-1000000, -9999, -555, -99, -22, -1, 0, 1, 22, 99, 555, 9999, 1000000}
	for _, c := range cases {
		di := New(c.year, c.month, c.day)
		for _, days := range offsets {
			dj := di.AddPeriod(period.New(0, 0, int(days), 0, 0, 0))
			days2 := dj.Sub(di)
			if days2 != days {
				t.Errorf("AddSub(%v,%v) == %v, want %v", di, days, days2, days)
			}
			dk := dj.AddPeriod(period.New(0, 0, -int(days), 0, 0, 0))
			if dk != di {
				t.Errorf("AddNeg(%v,%v) == %v, want %v", di, days, dk, di)
			}
		}
	}
}
Example #2
0
func TestExtendByNegPeriod(t *testing.T) {
	dr := OneDayRange(d0327).ExtendByPeriod(period.New(0, 0, -8, 0, 0, 0))
	//fmt.Printf("\ndr=%#v\n", dr)
	isEq(t, dr.Days(), PeriodOfDays(7))
	isEq(t, dr.Start(), d0320)
	isEq(t, dr.Last(), d0326)
	isEq(t, dr.String(), "7 days from 2015-03-20 to 2015-03-26")
}
Example #3
0
func TestExtendByPosPeriod(t *testing.T) {
	dr := OneDayRange(d0327).ExtendByPeriod(period.New(0, 0, 6, 0, 0, 0))
	isEq(t, dr.Days(), PeriodOfDays(7))
	isEq(t, dr.Start(), d0327)
	isEq(t, dr.Last(), d0402)
	isEq(t, dr.End(), d0403)
	isEq(t, dr.String(), "7 days from 2015-03-27 to 2015-04-02")
}
Example #4
0
func TestShiftByNegPeriod(t *testing.T) {
	dr := NewDateRange(d0403, d0408).ShiftByPeriod(period.New(0, 0, -7, 0, 0, 0))
	isEq(t, dr.Days(), PeriodOfDays(5))
	isEq(t, dr.Start(), d0327)
	isEq(t, dr.Last(), d0331)
}
Example #5
0
func TestShiftByPosPeriod(t *testing.T) {
	dr := NewDateRange(d0327, d0402).ShiftByPeriod(period.New(0, 0, 7, 0, 0, 0))
	isEq(t, dr.Days(), PeriodOfDays(6))
	isEq(t, dr.Start(), d0403)
	isEq(t, dr.Last(), d0408)
}