fix: time calc errors with only one booking per day + working empty kurzarbeit fixed #74

This commit is contained in:
2026-02-06 17:52:57 +01:00
parent 6b0b8906a9
commit 38322a64cf
2 changed files with 15 additions and 5 deletions

View File

@@ -46,11 +46,10 @@ func (d *WorkDay) GetWorktimeAbsence() Absence {
// Gets the time as is in the db (with corrected pause times) // Gets the time as is in the db (with corrected pause times)
func (d *WorkDay) GetWorktime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration { func (d *WorkDay) GetWorktime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
if includeKurzarbeit && d.IsKurzArbeit() && len(d.Bookings) > 0 { if includeKurzarbeit && d.IsKurzArbeit() { //&& len(d.Bookings) > 0
return d.kurzArbeitAbsence.GetWorktime(u, base, true) return d.kurzArbeitAbsence.GetWorktime(u, base, true)
} }
work, pause := calcWorkPause(d.Bookings) work, _ := correctWorkPause(getWorkPause(d))
work, pause = correctWorkPause(work, pause)
if (d.worktimeAbsece != Absence{}) { if (d.worktimeAbsece != Absence{}) {
work += d.worktimeAbsece.GetWorktime(u, base, false) work += d.worktimeAbsece.GetWorktime(u, base, false)
} }
@@ -59,7 +58,7 @@ func (d *WorkDay) GetWorktime(u User, base WorktimeBase, includeKurzarbeit bool)
// Gets the corrected pause times based on db entries // Gets the corrected pause times based on db entries
func (d *WorkDay) GetPausetime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration { func (d *WorkDay) GetPausetime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
work, pause := calcWorkPause(d.Bookings) work, pause := getWorkPause(d)
work, pause = correctWorkPause(work, pause) work, pause = correctWorkPause(work, pause)
return pause.Round(time.Minute) return pause.Round(time.Minute)
} }
@@ -81,6 +80,15 @@ func (d *WorkDay) GetTimes(u User, base WorktimeBase, includeKurzarbeit bool) (w
return d.GetWorktime(u, base, includeKurzarbeit), d.GetPausetime(u, base, includeKurzarbeit), d.GetOvertime(u, base, includeKurzarbeit) return d.GetWorktime(u, base, includeKurzarbeit), d.GetPausetime(u, base, includeKurzarbeit), d.GetOvertime(u, base, includeKurzarbeit)
} }
func getWorkPause(d *WorkDay) (work, pause time.Duration) {
//if today calc, else take from db
if helper.IsSameDate(d.Date(), time.Now()) {
return calcWorkPause(d.Bookings)
} else {
return d.workTime, d.pauseTime
}
}
func calcWorkPause(bookings []Booking) (work, pause time.Duration) { func calcWorkPause(bookings []Booking) (work, pause time.Duration) {
var lastBooking Booking var lastBooking Booking
for _, b := range bookings { for _, b := range bookings {

View File

@@ -170,10 +170,12 @@ templ workDayWeekComponent(workDay *models.WorkDay) {
<div class="flex flex-row gap-2 items-center"> <div class="flex flex-row gap-2 items-center">
<span class="icon-[material-symbols-light--schedule-outline] flex-shrink-0"></span> <span class="icon-[material-symbols-light--schedule-outline] flex-shrink-0"></span>
switch { switch {
case !workDay.TimeFrom.Equal(workDay.TimeTo): case !workDay.IsEmpty():
<span>{ workDay.TimeFrom.Format("15:04") }</span> <span>{ workDay.TimeFrom.Format("15:04") }</span>
<span>-</span> <span>-</span>
<span>{ workDay.TimeTo.Format("15:04") }</span> <span>{ workDay.TimeTo.Format("15:04") }</span>
case workDay.IsKurzArbeit():
<span>Kurzarbeit</span>
default: default:
<p>Keine Anwesenheit</p> <p>Keine Anwesenheit</p>
} }