示例#1
0
func TestCombine3(t *testing.T) {
	r := recurring.Combine(
		recurring.Until(recurring.AtInterval(kNow, 2*time.Hour), kNow),
		recurring.Until(
			recurring.AtInterval(kNow, 3*time.Hour), kNow.Add(9*time.Hour)))
	verifyTimes(
		t,
		r.ForTime(kNow),
		kNow.Add(3*time.Hour),
		kNow.Add(6*time.Hour))
}
示例#2
0
func TestAtInterval(t *testing.T) {
	r := recurring.Until(
		recurring.AtInterval(kNow, time.Hour), kNow.Add(4*time.Hour))
	verifyTimes(
		t,
		r.ForTime(kNow),
		kNow.Add(time.Hour),
		kNow.Add(2*time.Hour),
		kNow.Add(3*time.Hour))
	verifyTimes(
		t,
		r.ForTime(kNow.Add(-1*time.Second)),
		kNow,
		kNow.Add(time.Hour),
		kNow.Add(2*time.Hour),
		kNow.Add(3*time.Hour))
	verifyTimes(
		t,
		r.ForTime(kNow.Add(-2*time.Hour)),
		kNow,
		kNow.Add(time.Hour),
		kNow.Add(2*time.Hour),
		kNow.Add(3*time.Hour))
	verifyTimes(
		t,
		r.ForTime(kNow.Add(time.Hour)),
		kNow.Add(2*time.Hour),
		kNow.Add(3*time.Hour))
	verifyTimes(
		t,
		r.ForTime(kNow.Add(59*time.Minute)),
		kNow.Add(time.Hour),
		kNow.Add(2*time.Hour),
		kNow.Add(3*time.Hour))
}
示例#3
0
func TestRecurringEnded(t *testing.T) {
	tk := tasks.NilTask()
	r := recurring.AtInterval(kNow, time.Hour)
	e := tasks.Start(tasks.RecurringTask(tk, r))
	e.End()
	<-e.Done()
}
示例#4
0
func TestRecurringError(t *testing.T) {
	timeTask := &fakeTask{err: kSomeError}
	r := recurring.AtInterval(kNow, time.Hour)
	tasks.RunForTesting(
		tasks.RecurringTask(timeTask, r), &tasks.ClockForTesting{kNow})
	verifyTimes(
		t, timeTask.timeStamps,
		kNow.Add(time.Hour))
}
示例#5
0
func TestRecurringOverrun(t *testing.T) {
	timeTask := &fakeTask{runDuration: time.Hour}
	r := recurring.Until(
		recurring.AtInterval(kNow, time.Hour), kNow.Add(5*time.Hour))
	tasks.RunForTesting(
		tasks.RecurringTask(timeTask, r), &tasks.ClockForTesting{kNow})
	verifyTimes(
		t, timeTask.timeStamps, kNow.Add(time.Hour), kNow.Add(3*time.Hour))
}
示例#6
0
func TestOnOrBefore5(t *testing.T) {
	startTime := time.Date(2013, 10, 24, 9, 12, 0, 0, kLocation)
	r := tasks_recurring.AtInterval(startTime, 6*time.Hour)
	r = recurring.OnOrBefore(r, 9, 13)
	var atime time.Time
	stream := r.ForTime(startTime)
	stream.Next(&atime)
	verifyTime(t, time.Date(2013, 10, 24, 9, 13, 0, 0, kLocation), atime)
	stream.Next(&atime)
	verifyTime(t, time.Date(2013, 10, 25, 3, 12, 0, 0, kLocation), atime)
	stream.Next(&atime)
	verifyTime(t, time.Date(2013, 10, 25, 9, 12, 0, 0, kLocation), atime)
	stream.Next(&atime)
	verifyTime(t, time.Date(2013, 10, 25, 9, 13, 0, 0, kLocation), atime)
}