package models import ( "arbeitszeitmessung/helper" "log" "time" ) type IWorkDay interface { Date() time.Time ToString() string IsWorkDay() bool IsKurzArbeit() bool GetDayProgress(User) int8 RequiresAction() bool GetWorktime(User, WorktimeBase, bool) time.Duration GetPausetime(User, WorktimeBase, bool) time.Duration GetTimes(User, WorktimeBase, bool) (work, pause, overtime time.Duration) GetOvertime(User, WorktimeBase, bool) time.Duration } func GetDays(user User, tsFrom, tsTo time.Time, orderedForward bool) []IWorkDay { var allDays map[string]IWorkDay = make(map[string]IWorkDay) for _, day := range GetWorkDays(user, tsFrom, tsTo) { allDays[day.Date().Format(time.DateOnly)] = &day } absences, err := GetAbsencesByCardUID(user.CardUID, tsFrom, tsTo) if err != nil { log.Println("Error gettings absences for all Days!", err) return nil } for _, day := range absences { if helper.IsWeekend(day.Date()) { continue } // Absence should be integrated in workday switch { case day.AbwesenheitTyp.WorkTime < 0: if workDay, ok := allDays[day.Date().Format(time.DateOnly)].(*WorkDay); ok { workDay.kurzArbeit = true workDay.kurzArbeitAbsence = day } case day.AbwesenheitTyp.WorkTime < 100: if workDay, ok := allDays[day.Date().Format(time.DateOnly)].(*WorkDay); ok { workDay.worktimeAbsece = day } default: allDays[day.Date().Format(time.DateOnly)] = &day } } sortedDays := sortDays(allDays, orderedForward) return sortedDays }