removed Formatduration and fixed rounding error, working on overtime calculation

This commit is contained in:
2025-07-20 19:34:16 +02:00
parent 68000a0f0a
commit 4201ed7b1c
8 changed files with 230 additions and 179 deletions

View File

@@ -1,6 +1,7 @@
package helper
import (
"fmt"
"time"
)
@@ -14,3 +15,23 @@ func GetMonday(ts time.Time) time.Time {
}
return ts
}
// Converts duration to string
func FormatDuration(d time.Duration) string {
hours := int(d.Abs().Hours())
minutes := int(d.Abs().Minutes()) % 60
sign := ""
if d < 0 {
sign = "-"
}
switch {
case hours > 0 && minutes == 0:
return fmt.Sprintf("%s%dh", sign, hours)
case hours > 0:
return fmt.Sprintf("%s%dh %dmin", sign, hours, minutes)
case minutes > 0:
return fmt.Sprintf("%s%dmin", sign, minutes)
default:
return ""
}
}