🐛 Fix calculation of expected hours
This commit is contained in:
@@ -334,9 +334,41 @@ func TestCloseWeekUsesSettingsEffectiveToday(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("CloseWeek: %v", err)
|
||||
}
|
||||
wantInt(t, cw, "expected_ms", 20*hourMs)
|
||||
// Mon to Wed are 8h each, Thu and Fri count as 20h / 5 = 4h.
|
||||
wantInt(t, cw, "expected_ms", 3*eightH+2*4*hourMs)
|
||||
wantInt(t, cw, "worked_ms", 3*eightH)
|
||||
wantInt(t, cw, "delta_ms", 3*eightH-20*hourMs)
|
||||
wantInt(t, cw, "delta_ms", 3*eightH-(3*eightH+2*4*hourMs))
|
||||
}
|
||||
|
||||
func TestCloseWeekUsesSettingsEffectiveOnEachDay(t *testing.T) {
|
||||
// 32h until 14.05., 36h from Friday 15.05. The week is closed a month later,
|
||||
// when the 36h row is the only one effective today.
|
||||
e := setup(t)
|
||||
e.settings("2026-01-01", 32, 31, "UTC")
|
||||
e.settings("2026-05-15", 36, 31, "UTC")
|
||||
markWeekDays(t, e, weekKey, 5)
|
||||
june := time.Date(2026, 6, 13, 10, 0, 0, 0, time.UTC)
|
||||
|
||||
cw, err := CloseWeek(e.app, e.owner.Id, weekKey, june)
|
||||
if err != nil {
|
||||
t.Fatalf("CloseWeek: %v", err)
|
||||
}
|
||||
// 4 days with 32h / 5 = 6.4h and Friday with 36h / 5 = 7.2h.
|
||||
want := int64(4*6.4*float64(hourMs)) + int64(7.2*float64(hourMs))
|
||||
wantInt(t, cw, "expected_ms", want)
|
||||
// Every day was marked, so the credited time adds up to exactly the expectation.
|
||||
wantInt(t, cw, "worked_ms", want)
|
||||
wantInt(t, cw, "delta_ms", 0)
|
||||
|
||||
// A week that lies before the change keeps 32h.
|
||||
markWeekDays(t, e, "2026-W19", 5)
|
||||
cw, err = CloseWeek(e.app, e.owner.Id, "2026-W19", june)
|
||||
if err != nil {
|
||||
t.Fatalf("CloseWeek: %v", err)
|
||||
}
|
||||
wantInt(t, cw, "expected_ms", 32*hourMs)
|
||||
wantInt(t, cw, "worked_ms", 32*hourMs)
|
||||
wantInt(t, cw, "delta_ms", 0)
|
||||
}
|
||||
|
||||
func TestReopenWeekWithoutClosedWeekFails(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user