diff --git a/main.go b/main.go index 45fc345..ba33ba3 100644 --- a/main.go +++ b/main.go @@ -14,6 +14,7 @@ func main() { InWorkspace("flamingcow.io"). InMyTasksSections("Recently Assigned", "Today", "Meetings", "Maybe Today", "Upcoming", "Later", "Someday"). WhenBetween("America/Los_Angeles", "03:00:00", "17:00:00"). + WhenDayOfWeek("America/Los_Angeles", WeekDays). OnlyIncomplete(). DueInDays(0). WithTagsAnyOf("section=Tonight"). @@ -23,6 +24,16 @@ func main() { InWorkspace("flamingcow.io"). InMyTasksSections("Recently Assigned", "Meetings", "Maybe Today", "Tonight", "Upcoming", "Later", "Someday"). WhenBetween("America/Los_Angeles", "17:00:00", "03:00:00"). + WhenDayOfWeek("America/Los_Angeles", WeekDays). + OnlyIncomplete(). + DueInDays(0). + WithTagsAnyOf("section=Tonight"). + PrintTasks(). + MoveToMyTasksSection("Today") + + InWorkspace("flamingcow.io"). + InMyTasksSections("Recently Assigned", "Meetings", "Maybe Today", "Tonight", "Upcoming", "Later", "Someday"). + WhenDayOfWeek("America/Los_Angeles", WeekendDays). OnlyIncomplete(). DueInDays(0). WithTagsAnyOf("section=Tonight"). diff --git a/rules/rules.go b/rules/rules.go index fa186cb..f439b54 100644 --- a/rules/rules.go +++ b/rules/rules.go @@ -26,6 +26,31 @@ type periodic struct { taskActors []taskActor } +type Weekday = time.Weekday + +const ( + Sunday = time.Sunday + Monday = time.Monday + Tuesday = time.Tuesday + Wednesday = time.Wednesday + Thursday = time.Thursday + Friday = time.Friday + Saturday = time.Saturday +) + +var WeekDays = []Weekday{ + Monday, + Tuesday, + Wednesday, + Thursday, + Friday, +} + +var WeekendDays = []Weekday{ + Saturday, + Sunday, +} + var periodics = []*periodic{} func Loop() { @@ -84,6 +109,27 @@ func (p *periodic) WhenBetween(tz, start, end string) *periodic { return p } +func (p *periodic) WhenDayOfWeek(tz string, days []Weekday) *periodic { + p.gates = append(p.gates, func(wc *client.WorkspaceClient) (bool, error) { + loc, err := time.LoadLocation(tz) + if err != nil { + return false, err + } + + wd := time.Now().In(loc).Weekday() + + for _, d := range days { + if wd == d { + return true, nil + } + } + + return false, nil + }) + + return p +} + // Query mutators func (p *periodic) InMyTasksSections(names ...string) *periodic { p.queryMutators = append(p.queryMutators, func(wc *client.WorkspaceClient, q *client.SearchQuery) error {