accept THH on ezdate
parent
4b8d82c2a0
commit
71c03f3ef5
|
|
@ -94,8 +94,11 @@ func (due scheduleDue) next(time.Time) (time.Time, error) {
|
||||||
// 2022-01-01
|
// 2022-01-01
|
||||||
type scheduleEZDate string
|
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) {
|
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)
|
return time.ParseInLocation("2006-01-02", string(ezdate), time.Local)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -51,11 +51,17 @@ 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)
|
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 {
|
cases := map[string]struct {
|
||||||
input string
|
input string
|
||||||
want interface{}
|
want interface{}
|
||||||
next time.Time
|
next time.Time
|
||||||
}{
|
}{
|
||||||
|
"ezdate with hour": {
|
||||||
|
input: `2000-01-03T15`,
|
||||||
|
want: scheduleEZDate(`2000-01-03T15`),
|
||||||
|
next: someHour,
|
||||||
|
},
|
||||||
"long dur": {
|
"long dur": {
|
||||||
input: `2h1m`,
|
input: `2h1m`,
|
||||||
want: scheduleDuration("2h1m"),
|
want: scheduleDuration("2h1m"),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue