refactor: introduce clock to make tests reproducible

This commit is contained in:
2026-05-13 20:24:56 +00:00
parent 7e6c47a50e
commit ca5f5f95e2
9 changed files with 140 additions and 84 deletions

View File

@@ -8,6 +8,7 @@ import (
"time"
"github.com/google/uuid"
"github.com/wotra/wotra/internal/clock"
"github.com/wotra/wotra/internal/domain"
"github.com/wotra/wotra/internal/store"
)
@@ -31,6 +32,7 @@ type EntryService struct {
settings *store.SettingsStore
syncStore *store.SyncStore
tz *time.Location
clock clock.Clock
}
func NewEntryService(
@@ -39,6 +41,7 @@ func NewEntryService(
settings *store.SettingsStore,
syncStore *store.SyncStore,
tz *time.Location,
clk clock.Clock,
) *EntryService {
return &EntryService{
entries: entries,
@@ -46,11 +49,12 @@ func NewEntryService(
settings: settings,
syncStore: syncStore,
tz: tz,
clock: clk,
}
}
func (s *EntryService) nowMs() int64 {
return time.Now().UnixMilli()
return s.clock.Now().UnixMilli()
}
func (s *EntryService) dayKeyForMs(ms int64) string {