using IWorkDay interface for team
All checks were successful
Tests / Run Go Tests (push) Successful in 42s

This commit is contained in:
2025-09-25 21:52:53 +02:00
parent db6fc10c28
commit e8f1113293
7 changed files with 141 additions and 83 deletions

View File

@@ -4,6 +4,7 @@ import (
"arbeitszeitmessung/helper"
"encoding/json"
"log"
"sort"
"strconv"
"time"
)
@@ -14,6 +15,7 @@ type IWorkDay interface {
TimeWorkReal(User) time.Duration
TimePauseReal(User) (work, pause time.Duration)
TimeOvertimeReal(User) time.Duration
GetAllWorkTimesVirtual(User) (work, pause, overtime time.Duration)
ToString() string
IsWorkDay() bool
IsKurzArbeit() bool
@@ -33,7 +35,7 @@ type WorkDay struct {
kurzArbeit bool
}
func GetDays(user User, tsFrom, tsTo time.Time) []IWorkDay {
func GetDays(user User, tsFrom, tsTo time.Time, orderedForward bool) []IWorkDay {
var allDays map[string]IWorkDay = make(map[string]IWorkDay)
var sortedDays []IWorkDay
for _, day := range GetWorkDays(user, tsFrom, tsTo) {
@@ -60,6 +62,15 @@ func GetDays(user User, tsFrom, tsTo time.Time) []IWorkDay {
for _, day := range allDays {
sortedDays = append(sortedDays, day)
}
if orderedForward {
sort.Slice(sortedDays, func(i, j int) bool {
return sortedDays[i].Date().After(sortedDays[j].Date())
})
} else {
sort.Slice(sortedDays, func(i, j int) bool {
return sortedDays[i].Date().Before(sortedDays[j].Date())
})
}
return sortedDays
}