fix: time calc errors with only one booking per day + working empty kurzarbeit fixed #74
This commit is contained in:
@@ -46,11 +46,10 @@ func (d *WorkDay) GetWorktimeAbsence() Absence {
|
||||
|
||||
// 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() && len(d.Bookings) > 0 {
|
||||
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)
|
||||
work, _ := correctWorkPause(getWorkPause(d))
|
||||
if (d.worktimeAbsece != Absence{}) {
|
||||
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
|
||||
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)
|
||||
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)
|
||||
}
|
||||
|
||||
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) {
|
||||
var lastBooking Booking
|
||||
for _, b := range bookings {
|
||||
|
||||
Reference in New Issue
Block a user