fix: keep closed week snapshot in sync when days change
When a day is closed, re-closed, or reopened, DayService now recomputes worked_ms and delta_ms on the closed week containing that day (if the week is already closed). This prevents stale delta values after editing entries and re-closing a day. - DayService.recomputeWeek: sums worked_ms from all closed_days in the week, updates closed_weeks row preserving expected_ms - NewDayService now takes ClosedWeekStore - WeekKeyForDayKey exported helper (used by DayService) - TestWeekSnapshotUpdatesWhenDayReopened regression test
This commit is contained in:
@@ -45,6 +45,16 @@ func NewWeekService(
|
||||
// WeekDayKeysExported is exported for testing.
|
||||
var WeekDayKeysExported = weekDayKeys
|
||||
|
||||
// WeekKeyForDayKey returns the ISO week key (YYYY-Www) for a given YYYY-MM-DD day key.
|
||||
func WeekKeyForDayKey(dayKey string, tz *time.Location) (string, error) {
|
||||
t, err := time.ParseInLocation("2006-01-02", dayKey, tz)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("invalid day_key %q: %w", dayKey, err)
|
||||
}
|
||||
year, week := t.ISOWeek()
|
||||
return fmt.Sprintf("%d-W%02d", year, week), nil
|
||||
}
|
||||
|
||||
// weekDayKeys returns the YYYY-MM-DD keys for Mon-Sun of the ISO week encoded as weekKey.
|
||||
// weekKey format: "YYYY-Www" (e.g. "2024-W03").
|
||||
func weekDayKeys(weekKey string, tz *time.Location) ([]string, error) {
|
||||
|
||||
Reference in New Issue
Block a user