From 71c03f3ef531a55ee10d5cd6b06fcff33579c9f8 Mon Sep 17 00:00:00 2001 From: Bel LaPointe Date: Sun, 9 Jan 2022 10:24:40 -0500 Subject: [PATCH] accept THH on ezdate --- pttodo/schedule.go | 5 ++++- pttodo/schedule_test.go | 6 ++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/pttodo/schedule.go b/pttodo/schedule.go index b5ef9d2..0c3b739 100644 --- a/pttodo/schedule.go +++ b/pttodo/schedule.go @@ -94,8 +94,11 @@ func (due scheduleDue) next(time.Time) (time.Time, error) { // 2022-01-01 type scheduleEZDate string -var scheduleEZDatePattern = regexp.MustCompile(`^[0-9]{4}-[0-9]{2}-[0-9]{2}$`) +var scheduleEZDatePattern = regexp.MustCompile(`^[0-9]{4}-[0-9]{2}-[0-9]{2}(T[0-9]{2})?$`) func (ezdate scheduleEZDate) next(time.Time) (time.Time, error) { + if len(ezdate) == len("20xx-xx-xxTxx") { + return time.ParseInLocation("2006-01-02T15", string(ezdate), time.Local) + } return time.ParseInLocation("2006-01-02", string(ezdate), time.Local) } diff --git a/pttodo/schedule_test.go b/pttodo/schedule_test.go index 417c2f3..5482205 100644 --- a/pttodo/schedule_test.go +++ b/pttodo/schedule_test.go @@ -51,11 +51,17 @@ 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) + someHour := time.Date(2001, 2, 3, 15, 0, 0, 0, time.UTC) cases := map[string]struct { input string want interface{} next time.Time }{ + "ezdate with hour": { + input: `2000-01-03T15`, + want: scheduleEZDate(`2000-01-03T15`), + next: someHour, + }, "long dur": { input: `2h1m`, want: scheduleDuration("2h1m"),