fix: allow closing current week when future workdays are not yet closed
CloseWeek was requiring every workday in the ISO week to have a closed_days record, including days in the future. Now only workdays up to and including today are checked; future workdays are skipped. Adds TestCloseWeekMidWeek regression test.
This commit is contained in:
@@ -88,13 +88,18 @@ func (s *WeekService) CloseWeek(ctx context.Context, weekKey string) (*domain.Cl
|
||||
// Compute expected ms for the week (from settings frozen at week start)
|
||||
expectedMs := int64(set.HoursPerWeek * 3_600_000)
|
||||
|
||||
// Verify all workdays are closed; collect worked ms
|
||||
// Verify all workdays up to and including today are closed; collect worked ms.
|
||||
// Future workdays in the week (not yet reached) are skipped.
|
||||
todayKey := time.Now().In(s.tz).Format("2006-01-02")
|
||||
var totalWorkedMs int64
|
||||
for _, dk := range dayKeys {
|
||||
t, _ := time.ParseInLocation("2006-01-02", dk, s.tz)
|
||||
if !set.IsWorkday(int(t.Weekday())) {
|
||||
continue // weekend or non-workday — skip
|
||||
}
|
||||
if dk > todayKey {
|
||||
continue // future workday — skip
|
||||
}
|
||||
cd, err := s.closedDays.GetByDayKey(ctx, dk)
|
||||
if err != nil {
|
||||
if errors.Is(err, sql.ErrNoRows) {
|
||||
|
||||
Reference in New Issue
Block a user