2fas-server/internal/common/clock/clock.go

36 lines
409 B
Go
Raw Normal View History

2022-12-31 10:22:38 +01:00
package clock
import (
"sync"
"time"
)
type Clock interface {
Now() time.Time
}
type clock struct{}
func (clock) Now() time.Time {
return time.Now()
}
func New() Clock {
return &clock{}
}
type mockClock struct {
mu sync.Mutex
now time.Time
}
func (m *mockClock) Now() time.Time {
m.mu.Lock()
defer m.mu.Unlock()
return m.now
}
func Mock() Clock {
return &mockClock{now: time.Unix(0, 0)}
}