seperated pdf-generate endpoint + added new helper in Time

This commit is contained in:
2025-10-28 22:59:33 +01:00
parent 4bc5594dc5
commit cf5238f024
6 changed files with 104 additions and 7 deletions

View File

@@ -55,3 +55,16 @@ func FormatDurationFill(d time.Duration, fill bool) string {
func IsSameDate(a, b time.Time) bool {
return a.Truncate(24 * time.Hour).Equal(b.Truncate(24 * time.Hour))
}
func GetWorkingDays(startDate, endDate time.Time) int {
if endDate.Before(startDate) {
return 0
}
var count int = 0
for d := startDate.Truncate(24 * time.Hour); !d.After(endDate); d = d.Add(24 * time.Hour) {
if !IsWeekend(d) {
count++
}
}
return count
}

View File

@@ -1,6 +1,7 @@
package helper
import (
"fmt"
"testing"
"time"
)
@@ -35,3 +36,25 @@ func TestFormatDuration(t *testing.T) {
})
}
}
func TestGetWorkingDays(t *testing.T) {
testCases := []struct {
start string
end string
days int
}{
{"2025-10-01", "2025-10-02", 2},
{"2025-10-02", "2025-10-01", 0},
{"2025-10-01", "2025-10-31", 23},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("WorkingDayTest: %d days", tc.days), func(t *testing.T) {
startDate, _ := time.Parse(time.DateOnly, tc.start)
endDate, _ := time.Parse(time.DateOnly, tc.end)
if GetWorkingDays(startDate, endDate) != tc.days {
t.Error("Calculated workdays do not match target")
}
})
}
}