123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package sentio
- import "time"
- type Clock interface {
- Now() time.Time
- After(d time.Duration) <-chan time.Time
- }
- type ClockUTC struct {
- }
- func (t ClockUTC) Now() time.Time {
- return time.Now().In(time.UTC)
- }
- func (t ClockUTC) After(d time.Duration) <-chan time.Time {
- return time.After(d)
- }
- type ClockNY struct {
- location *time.Location
- }
- func NewClockNY() (Clock, error) {
- l, err := time.LoadLocation("America/New_York")
- if err != nil {
- return nil, err
- }
- return ClockNY{
- location: l,
- }, nil
- }
- func (t ClockNY) Now() time.Time {
- return time.Now().In(t.location)
- }
- func (t ClockNY) After(d time.Duration) <-chan time.Time {
- return time.After(d)
- }
- type StubClock struct {
- Clock time.Time
- }
- func (t StubClock) Now() time.Time {
- return t.Clock.In(time.UTC)
- }
- func (t StubClock) After(d time.Duration) <-chan time.Time {
- return time.After(d)
- }
|