Example #1
0
func TestDrPepper(t *testing.T) {
	r := recurring.Until(
		recurring.Combine(
			recurring.AtTime(10, 0),
			recurring.AtTime(14, 0),
			recurring.AtTime(16, 0)),
		kNow.AddDate(0, 0, 2))
	verifyTimes(
		t,
		r.ForTime(kNow),
		time.Date(2013, 9, 13, 10, 0, 0, 0, time.Local),
		time.Date(2013, 9, 13, 14, 0, 0, 0, time.Local),
		time.Date(2013, 9, 13, 16, 0, 0, 0, time.Local),
		time.Date(2013, 9, 14, 10, 0, 0, 0, time.Local),
		time.Date(2013, 9, 14, 14, 0, 0, 0, time.Local),
		time.Date(2013, 9, 14, 16, 0, 0, 0, time.Local))
}
Example #2
0
func TestAtTime(t *testing.T) {
	firstTime := time.Date(2013, 9, 13, 17, 21, 0, 0, time.Local)
	r := recurring.Until(recurring.AtTime(17, 21), firstTime.AddDate(0, 0, 3))
	verifyTimes(
		t,
		r.ForTime(kNow),
		firstTime,
		firstTime.AddDate(0, 0, 1),
		firstTime.AddDate(0, 0, 2))

	firstTime = time.Date(2013, 9, 12, 17, 22, 0, 0, time.Local)
	r = recurring.Until(recurring.AtTime(17, 22), firstTime.AddDate(0, 0, 3))
	verifyTimes(
		t,
		r.ForTime(kNow),
		firstTime,
		firstTime.AddDate(0, 0, 1),
		firstTime.AddDate(0, 0, 2))
}
Example #3
0
func TestAfterNested(t *testing.T) {
	firstTime := time.Date(2013, 9, 12, 17, 22, 0, 0, time.Local)
	r := recurring.Until(
		recurring.After(
			recurring.After(recurring.AtTime(14, 22), 2*time.Hour),
			time.Hour),
		firstTime.AddDate(0, 0, 2))
	verifyTimes(
		t,
		r.ForTime(kNow),
		firstTime,
		firstTime.AddDate(0, 0, 1))
}
Example #4
0
func ExampleCombine() {
	// Daily at 10:09, 13:05, and 17:13
	r := recurring.Combine(
		recurring.AtTime(10, 9),
		recurring.AtTime(13, 5),
		recurring.AtTime(17, 13))
	stream := r.ForTime(time.Date(2013, 10, 2, 12, 0, 0, 0, time.Local))
	layout := "Jan 2 15:04:05"
	var current time.Time
	for i := 0; i < 8; i++ {
		stream.Next(&current)
		fmt.Println(current.Format(layout))
	}
	// Output:
	// Oct 2 13:05:00
	// Oct 2 17:13:00
	// Oct 3 10:09:00
	// Oct 3 13:05:00
	// Oct 3 17:13:00
	// Oct 4 10:09:00
	// Oct 4 13:05:00
	// Oct 4 17:13:00
}
Example #5
0
func TestOnDays(t *testing.T) {
	firstTime := time.Date(2013, 9, 12, 18, 0, 0, 0, time.Local)
	r := recurring.Until(
		recurring.Filter(
			recurring.AtTime(18, 0),
			recurring.OnDays(recurring.Weekdays)),
		firstTime.AddDate(0, 0, 8))
	verifyTimes(
		t,
		r.ForTime(kNow),
		firstTime,                  // Thursday
		firstTime.AddDate(0, 0, 1), // Friday
		firstTime.AddDate(0, 0, 4), // Monday
		firstTime.AddDate(0, 0, 5), // Tuesday
		firstTime.AddDate(0, 0, 6), // Wednesday
		firstTime.AddDate(0, 0, 7)) // Thursday
}
Example #6
0
func ExampleFilter() {
	// Weekdays at 7:00
	r := recurring.Filter(
		recurring.AtTime(7, 0),
		recurring.OnDays(recurring.Weekdays))
	stream := r.ForTime(time.Date(2013, 10, 1, 7, 0, 0, 0, time.Local))
	layout := "Mon Jan 2 15:04:05"
	var current time.Time
	for i := 0; i < 5; i++ {
		stream.Next(&current)
		fmt.Println(current.Format(layout))
	}
	// Output:
	// Wed Oct 2 07:00:00
	// Thu Oct 3 07:00:00
	// Fri Oct 4 07:00:00
	// Mon Oct 7 07:00:00
	// Tue Oct 8 07:00:00
}
Example #7
0
func TestFilterNested(t *testing.T) {
	firstTime := time.Date(2013, 9, 12, 18, 0, 0, 0, time.Local)
	r := recurring.Until(
		recurring.Filter(
			recurring.Filter(
				recurring.AtTime(18, 0),
				recurring.OnDays(recurring.Weekdays)),
			functional.NewFilterer(func(ptr interface{}) error {
				p := ptr.(*time.Time)
				if p.Day()%2 != 0 {
					return functional.Skipped
				}
				return nil
			})),
		firstTime.AddDate(0, 0, 8))
	verifyTimes(
		t,
		r.ForTime(kNow),
		firstTime,                  // Thursday
		firstTime.AddDate(0, 0, 4), // Monday
		firstTime.AddDate(0, 0, 6)) // Wednesday
}