ezdate for yyyy-mm-dd for schedule
parent
a51d5e6960
commit
92d76443bc
|
|
@ -37,6 +37,8 @@ func schedulerFactory(s string) scheduler {
|
||||||
} else if scheduleDuePattern.MatchString(s) {
|
} else if scheduleDuePattern.MatchString(s) {
|
||||||
n, _ := strconv.Atoi(s)
|
n, _ := strconv.Atoi(s)
|
||||||
return scheduleDue(n)
|
return scheduleDue(n)
|
||||||
|
} else if scheduleEZDatePattern.MatchString(s) {
|
||||||
|
return scheduleEZDate(s)
|
||||||
}
|
}
|
||||||
return scheduleCron(s)
|
return scheduleCron(s)
|
||||||
}
|
}
|
||||||
|
|
@ -88,3 +90,12 @@ var scheduleDuePattern = regexp.MustCompile(`^[0-9]+$`)
|
||||||
func (due scheduleDue) next(time.Time) (time.Time, error) {
|
func (due scheduleDue) next(time.Time) (time.Time, error) {
|
||||||
return TS(due).time(), nil
|
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))
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,6 +50,7 @@ func TestJSONSchedule(t *testing.T) {
|
||||||
|
|
||||||
func TestSchedulerFactory(t *testing.T) {
|
func TestSchedulerFactory(t *testing.T) {
|
||||||
start := time.Date(2000, 1, 1, 1, 1, 1, 1, time.UTC)
|
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 {
|
cases := map[string]struct {
|
||||||
input string
|
input string
|
||||||
want interface{}
|
want interface{}
|
||||||
|
|
@ -85,6 +86,11 @@ func TestSchedulerFactory(t *testing.T) {
|
||||||
want: scheduleCron(`5 * * * *`),
|
want: scheduleCron(`5 * * * *`),
|
||||||
next: start.Add(time.Duration(-1*start.Nanosecond() + -1*start.Minute() + -1*start.Second())).Add(5 * time.Minute),
|
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 {
|
for name, d := range cases {
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,7 @@ todo:
|
||||||
let git be smart-ish and keep latest? would provide versioning OOTB without touching raw
|
let git be smart-ish and keep latest? would provide versioning OOTB without touching raw
|
||||||
scheduled: []
|
scheduled: []
|
||||||
done:
|
done:
|
||||||
|
- more schedule formats, like just 2022-01-15, for deferring
|
||||||
- from todo-server to pttodo format
|
- from todo-server to pttodo format
|
||||||
- add -tag to search via cli
|
- add -tag to search via cli
|
||||||
- ts to human readable
|
- ts to human readable
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue