Files
arbeitszeitmessung/Backend/models/compoundDay.go
tom_trgr 855cd6f34f
Some checks failed
Tests / Run Go Tests (push) Failing after 44s
working compound days + working public holidays
2025-12-24 01:38:16 +01:00

106 lines
2.6 KiB
Go

package models
import (
"log/slog"
"time"
)
type CompoundDay struct {
Day time.Time
DayParts []IWorkDay
}
func NewCompondDay(date time.Time, dayParts ...IWorkDay) *CompoundDay {
return &CompoundDay{Day: date, DayParts: dayParts}
}
func (c *CompoundDay) AddDayPart(dayPart IWorkDay) {
c.DayParts = append(c.DayParts, dayPart)
}
func (c *CompoundDay) GetWorkDay() WorkDay {
workday, ok := c.DayParts[0].(*WorkDay)
if ok {
return *workday
}
return WorkDay{}
}
// IsEmpty implements [IWorkDay].
func (c *CompoundDay) IsEmpty() bool {
return len(c.DayParts) > 0
}
// Date implements [IWorkDay].
func (c *CompoundDay) Date() time.Time {
return c.Day
}
// GetDayProgress implements [IWorkDay].
func (c *CompoundDay) GetDayProgress(u User) int8 {
var dayProcess int8
for _, day := range c.DayParts {
dayProcess += day.GetDayProgress(u)
}
return dayProcess
}
// GetOvertime implements [IWorkDay].
func (c *CompoundDay) GetOvertime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
var overtime time.Duration
for _, day := range c.DayParts {
overtime += day.GetOvertime(u, base, includeKurzarbeit)
}
return overtime
}
// GetPausetime implements [IWorkDay].
func (c *CompoundDay) GetPausetime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
var pausetime time.Duration
for _, day := range c.DayParts {
pausetime += day.GetPausetime(u, base, includeKurzarbeit)
}
return pausetime
}
// GetTimes implements [IWorkDay].
func (c *CompoundDay) GetTimes(u User, base WorktimeBase, includeKurzarbeit bool) (work time.Duration, pause time.Duration, overtime time.Duration) {
return c.GetWorktime(u, base, includeKurzarbeit), c.GetPausetime(u, base, includeKurzarbeit), c.GetOvertime(u, base, includeKurzarbeit)
}
// GetWorktime implements [IWorkDay].
func (c *CompoundDay) GetWorktime(u User, base WorktimeBase, includeKurzarbeit bool) time.Duration {
var worktime time.Duration
for _, day := range c.DayParts {
worktime += day.GetWorktime(u, base, includeKurzarbeit)
slog.Info("Calc worktime for day", "day", day, "worktime", worktime.String())
}
return worktime
}
// IsKurzArbeit implements [IWorkDay].
func (c *CompoundDay) IsKurzArbeit() bool {
return false
}
// IsWorkDay implements [IWorkDay].
func (c *CompoundDay) IsWorkDay() bool {
return true
}
// RequiresAction implements [IWorkDay].
func (c *CompoundDay) RequiresAction() bool {
return false
}
// ToString implements [IWorkDay].
func (c *CompoundDay) ToString() string {
return "Compound Day"
}
// Type implements [IWorkDay].
func (c *CompoundDay) Type() DayType {
return DayTypeCompound
}