Documentation
¶
Overview ¶
Package recurring handles recurring times.
Index ¶
- Constants
- func OnDays(dayMask DaysOfWeek) functional.Filterer
- type DaysOfWeek
- type R
- func After(r R, d time.Duration) R
- func AtInterval(start time.Time, d time.Duration) R
- func AtTime(hour24, minute int) R
- func Combine(rs ...R) R
- func Filter(r R, f functional.Filterer) R
- func Nil() R
- func OnDate(targetTime time.Time) R
- func OnTheHour() R
- func StartAt(r R, startTime time.Time) R
- func Until(r R, t time.Time) R
- type RFunc
Examples ¶
Constants ¶
Variables ¶
This section is empty.
Functions ¶
func OnDays ¶
func OnDays(dayMask DaysOfWeek) functional.Filterer
OnDays filters times by day of week. dayMask is the desired days of the week ored together e.g functional.Monday | functional.Tuesday
Types ¶
type DaysOfWeek ¶
type DaysOfWeek int
const ( Sunday DaysOfWeek = 1 << iota Saturday Friday Thursday Wednesday Tuesday Monday )
type R ¶
type R interface {
// ForTime returns a Stream of time.Time starting at t. The times that
// returned Stream emits shall be after t and be in ascending order.
ForTime(t time.Time) functional.Stream
}
R represents a recurring time such as each Monday at 7:00.
func AtInterval ¶
AtInterval returns a new R instance that represents starting at time start and repeating at d intervals.
func Combine ¶
Combine combines multiple R instances together and returns them as a single one.
Example ¶
package main
import (
"fmt"
"github.com/keep94/tasks/recurring"
"time"
)
func main() {
// 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(¤t)
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
func Filter ¶
func Filter(r R, f functional.Filterer) R
Filter returns a new R instance that filters the time.Time Streams that r creates
Example ¶
package main
import (
"fmt"
"github.com/keep94/tasks/recurring"
"time"
)
func main() {
// 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(¤t)
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
func OnDate ¶
OnDate returns a new R instance that represents happening once on a particular date and time.
func OnTheHour ¶
func OnTheHour() R
OnTheHour returns an R instance that represents repeating at the start of each hour.