diff --git a/pttodo/schedule.go b/pttodo/schedule.go index e4f0f2c..9593142 100644 --- a/pttodo/schedule.go +++ b/pttodo/schedule.go @@ -37,6 +37,8 @@ func schedulerFactory(s string) scheduler { } else if scheduleDuePattern.MatchString(s) { n, _ := strconv.Atoi(s) return scheduleDue(n) + } else if scheduleEZDatePattern.MatchString(s) { + return scheduleEZDate(s) } return scheduleCron(s) } @@ -88,3 +90,12 @@ var scheduleDuePattern = regexp.MustCompile(`^[0-9]+$`) func (due scheduleDue) next(time.Time) (time.Time, error) { return TS(due).time(), nil } + +// 2022-01-01 +type scheduleEZDate string + +var scheduleEZDatePattern = regexp.MustCompile(`^[0-9]{4}-[0-9]{2}-[0-9]{2}$`) + +func (ezdate scheduleEZDate) next(time.Time) (time.Time, error) { + return time.Parse("2006-01-02", string(ezdate)) +} diff --git a/pttodo/schedule_test.go b/pttodo/schedule_test.go index 8b25989..417c2f3 100644 --- a/pttodo/schedule_test.go +++ b/pttodo/schedule_test.go @@ -50,6 +50,7 @@ func TestJSONSchedule(t *testing.T) { func TestSchedulerFactory(t *testing.T) { start := time.Date(2000, 1, 1, 1, 1, 1, 1, time.UTC) + someDay := time.Date(2001, 2, 3, 0, 0, 0, 0, time.UTC) cases := map[string]struct { input string want interface{} @@ -85,6 +86,11 @@ func TestSchedulerFactory(t *testing.T) { want: scheduleCron(`5 * * * *`), next: start.Add(time.Duration(-1*start.Nanosecond() + -1*start.Minute() + -1*start.Second())).Add(5 * time.Minute), }, + "ezdate": { + input: `2000-01-03`, + want: scheduleEZDate(`2000-01-03`), + next: someDay, + }, } for name, d := range cases { diff --git a/todo.yaml b/todo.yaml index c3daacc..ec2c4a7 100644 --- a/todo.yaml +++ b/todo.yaml @@ -20,6 +20,7 @@ todo: let git be smart-ish and keep latest? would provide versioning OOTB without touching raw scheduled: [] done: +- more schedule formats, like just 2022-01-15, for deferring - from todo-server to pttodo format - add -tag to search via cli - ts to human readable