ts shouldnt yield zero ever, yield now if so
parent
2d8cfa6397
commit
7fc594d5c2
|
|
@ -70,11 +70,6 @@ func TestSchedulerFactory(t *testing.T) {
|
|||
want: scheduleDue(1),
|
||||
next: time.Unix(1, 0),
|
||||
},
|
||||
"zero ts": {
|
||||
input: `0`,
|
||||
want: scheduleDue(0),
|
||||
next: time.Unix(0, 0),
|
||||
},
|
||||
"never": {
|
||||
input: ``,
|
||||
want: scheduleNever{},
|
||||
|
|
@ -108,4 +103,18 @@ func TestSchedulerFactory(t *testing.T) {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
t.Run("zero ts", func(t *testing.T) {
|
||||
got := schedulerFactory("0")
|
||||
if fmt.Sprintf("%T", scheduleDue(0)) != fmt.Sprintf("%T", got) {
|
||||
t.Fatalf("want type %T, got %T", scheduleDue(0), got)
|
||||
}
|
||||
if fmt.Sprint(scheduleDue(0)) != fmt.Sprint(got) {
|
||||
t.Fatalf("want %+v, got %+v", scheduleDue(0), got)
|
||||
}
|
||||
next, _ := got.next(start)
|
||||
if now := time.Now(); next.Sub(now) > time.Second {
|
||||
t.Fatalf("want next %+v, got %+v", now, next)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ import (
|
|||
type TS int64
|
||||
|
||||
func (ts TS) time() time.Time {
|
||||
if ts == 0 {
|
||||
ts = TS(time.Now().Unix())
|
||||
}
|
||||
return time.Unix(int64(ts), 0)
|
||||
}
|
||||
|
||||
|
|
@ -26,8 +29,7 @@ func (ts TS) MarshalYAML() (interface{}, error) {
|
|||
if ts == 0 {
|
||||
ts = TS(time.Now().Unix())
|
||||
}
|
||||
t := time.Unix(int64(ts), 0)
|
||||
return t.Format(time.UnixDate), nil
|
||||
return ts.time().Format(time.UnixDate), nil
|
||||
}
|
||||
|
||||
func (ts *TS) UnmarshalJSON(b []byte) error {
|
||||
|
|
|
|||
Loading…
Reference in New Issue