This commit is contained in:
59
Backend/models/iworkday.go
Normal file
59
Backend/models/iworkday.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"arbeitszeitmessung/helper"
|
||||
"log"
|
||||
"time"
|
||||
)
|
||||
|
||||
type IWorkDay interface {
|
||||
Date() time.Time
|
||||
ToString() string
|
||||
IsWorkDay() bool
|
||||
IsKurzArbeit() bool
|
||||
GetDayProgress(User) int8
|
||||
RequiresAction() bool
|
||||
GetWorktimeReal(User, WorktimeBase) time.Duration
|
||||
GetPausetimeReal(User, WorktimeBase) time.Duration
|
||||
GetOvertimeReal(User, WorktimeBase) time.Duration
|
||||
GetWorktimeVirtual(User, WorktimeBase) time.Duration
|
||||
GetPausetimeVirtual(User, WorktimeBase) time.Duration
|
||||
GetOvertimeVirtual(User, WorktimeBase) time.Duration
|
||||
GetTimesReal(User, WorktimeBase) (work, pause, overtime time.Duration)
|
||||
GetTimesVirtual(User, WorktimeBase) (work, pause, overtime 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
|
||||
}
|
||||
Reference in New Issue
Block a user