Ejemplo n.º 1
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
}
Ejemplo n.º 2
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
}
Ejemplo n.º 3
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
}