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

@@ -87,6 +87,13 @@ func (a *Absence) RequiresAction() bool {
return false
}
func (a *Absence) GetAllWorkTimesVirtual(u User) (work, pause, overtime time.Duration) {
if a.AbwesenheitTyp.WorkTime > 1 {
return u.ArbeitszeitProTag(), 0, 0
}
return 0, 0, 0
}
func (a *Absence) Insert() error {
qStr, err := DB.Prepare(`INSERT INTO abwesenheit (card_uid, abwesenheit_typ, datum_from, datum_to) VALUES ($1, $2, $3, $4) RETURNING counter_id;`)
if err != nil {

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
}

View File

@@ -4,7 +4,6 @@ import (
"database/sql"
"errors"
"log"
"sort"
"time"
)
@@ -46,10 +45,7 @@ func NewWorkWeek(user User, tsMonday time.Time, populate bool) WorkWeek {
}
func (w *WorkWeek) PopulateWithDays(worktime time.Duration, overtime time.Duration) {
w.Days = GetDays(w.User, w.WeekStart, w.WeekStart.Add(6*24*time.Hour))
sort.Slice(w.Days, func(i, j int) bool {
return w.Days[i].Date().Before(w.Days[j].Date())
})
w.Days = GetDays(w.User, w.WeekStart, w.WeekStart.Add(6*24*time.Hour), false)
for _, day := range w.Days {
w.Worktime += day.TimeWorkVirtual(w.User)