ezdate for yyyy-mm-dd for schedule

master
Bel LaPointe 2022-01-01 17:21:38 -05:00
parent a51d5e6960
commit 92d76443bc
3 changed files with 18 additions and 0 deletions

View File

@ -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))
}

View File

@ -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 {

View File

@ -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