forked from go-co-op/gocron
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimeHelper.go
More file actions
38 lines (29 loc) · 947 Bytes
/
Copy pathtimeHelper.go
File metadata and controls
38 lines (29 loc) · 947 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package gocron
import "time"
type timeHelper interface {
Now(*time.Location) time.Time
Unix(int64, int64) time.Time
Sleep(time.Duration)
Date(int, time.Month, int, int, int, int, int, *time.Location) time.Time
NewTicker(time.Duration) *time.Ticker
}
func newTimeHelper() timeHelper {
return &trueTime{}
}
type trueTime struct{}
func (t *trueTime) Now(location *time.Location) time.Time {
n := time.Now().In(location)
return t.Date(n.Year(), n.Month(), n.Day(), n.Hour(), n.Minute(), n.Second(), 0, location)
}
func (t *trueTime) Unix(sec int64, nsec int64) time.Time {
return time.Unix(sec, nsec)
}
func (t *trueTime) Sleep(d time.Duration) {
time.Sleep(d)
}
func (t *trueTime) Date(year int, month time.Month, day, hour, min, sec, nsec int, loc *time.Location) time.Time {
return time.Date(year, month, day, hour, min, sec, nsec, loc)
}
func (t *trueTime) NewTicker(d time.Duration) *time.Ticker {
return time.NewTicker(d)
}