fixed #61, #62 refactored getTime variants
Some checks failed
Tests / Run Go Tests (push) Failing after 1m20s

This commit is contained in:
2025-12-12 12:26:40 +01:00
parent 1ccc19b85c
commit 76b23133d0
10 changed files with 196 additions and 207 deletions

View File

@@ -30,15 +30,19 @@ const (
WorktimeBaseDay WorktimeBase = "day"
)
func (d *WorkDay) GetWorktimeAbsence() Absence {
return d.worktimeAbsece
}
// Gets the time as is in the db (with corrected pause times)
func (d *WorkDay) GetWorktime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
if includeKurzarbeit && d.IsKurzArbeit() {
if includeKurzarbeit && d.IsKurzArbeit() && len(d.Bookings) > 0 {
return d.kurzArbeitAbsence.GetWorktime(u, base, true)
}
work, pause := calcWorkPause(d.Bookings)
work, pause = correctWorkPause(work, pause)
if (d.worktimeAbsece != Absence{}) {
work += d.worktimeAbsece.GetWorktimeReal(u, base)
work += d.worktimeAbsece.GetWorktime(u, base, false)
}
return work.Round(time.Minute)
}
@@ -124,12 +128,12 @@ func (d *WorkDay) Date() time.Time {
func (d *WorkDay) GenerateKurzArbeitBookings(u User) (time.Time, time.Time) {
var timeFrom, timeTo time.Time
if d.workTime >= u.ArbeitszeitProTag() {
if d.GetWorktime(u, WorktimeBaseDay, false) >= u.ArbeitszeitProTag() {
return timeFrom, timeTo
}
timeFrom = d.Bookings[len(d.Bookings)-1].Timestamp.Add(time.Minute)
timeTo = timeFrom.Add(u.ArbeitszeitProTag() - d.workTime)
timeTo = timeFrom.Add(u.ArbeitszeitProTag() - d.GetWorktime(u, WorktimeBaseDay, false))
slog.Debug("Added duration as Kurzarbeit", "date", d.Date().String(), "duration", timeTo.Sub(timeFrom).String())
return timeFrom, timeTo