From 74bce88cc0ce875dc4a1adbd1a5c438534c087cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=20Tr=C3=B6ger?= Date: Tue, 2 Dec 2025 16:53:43 +0100 Subject: [PATCH] fixed #60 --- Backend/helper/time.go | 7 +++++ Backend/helper/time_test.go | 32 ++++++++++++++++++++--- Backend/templates/teamComponents.templ | 2 +- Backend/templates/teamComponents_templ.go | 6 ++--- Backend/templates/timePage.templ | 2 +- Backend/templates/timePage_templ.go | 6 ++--- 6 files changed, 43 insertions(+), 12 deletions(-) diff --git a/Backend/helper/time.go b/Backend/helper/time.go index 30198fc..fcd739d 100644 --- a/Backend/helper/time.go +++ b/Backend/helper/time.go @@ -68,3 +68,10 @@ func GetWorkingDays(startDate, endDate time.Time) int { } return count } + +func FormatGermanDayOfWeek(t time.Time) string { + return days[t.Weekday()][:2] +} + +var days = [...]string{ + "Sonntag", "Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag"} diff --git a/Backend/helper/time_test.go b/Backend/helper/time_test.go index 8e56834..96ae5a9 100644 --- a/Backend/helper/time_test.go +++ b/Backend/helper/time_test.go @@ -18,7 +18,7 @@ func TestGetMonday(t *testing.T) { } func TestFormatDuration(t *testing.T) { - durations := []struct { + testCases := []struct { name string duration time.Duration }{ @@ -28,9 +28,9 @@ func TestFormatDuration(t *testing.T) { {"-1h 30min", time.Duration(-90 * time.Minute)}, {"", 0}, } - for _, d := range durations { - t.Run(d.name, func(t *testing.T) { - if FormatDuration(d.duration) != d.name { + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + if FormatDuration(tc.duration) != tc.name { t.Error("Format missmatch in Formatduration.") } }) @@ -58,3 +58,27 @@ func TestGetWorkingDays(t *testing.T) { }) } } + +func TestFormatGermanDayOfWeek(t *testing.T) { + testCases := []struct { + date string + result string + }{ + {"2025-12-01", "Mo"}, + {"2025-12-02", "Di"}, + {"2025-12-03", "Mi"}, + {"2025-12-04", "Do"}, + {"2025-12-05", "Fr"}, + {"2025-12-06", "Sa"}, + {"2025-12-07", "So"}, + } + + for _, tc := range testCases { + t.Run(fmt.Sprintf("FormatWeekDayTest: %s date", tc.date), func(t *testing.T) { + date, _ := time.Parse(time.DateOnly, tc.date) + if FormatGermanDayOfWeek(date) != tc.result { + t.Error("Formatted workday did not match!") + } + }) + } +} diff --git a/Backend/templates/teamComponents.templ b/Backend/templates/teamComponents.templ index d1dd820..086bd8d 100644 --- a/Backend/templates/teamComponents.templ +++ b/Backend/templates/teamComponents.templ @@ -32,7 +32,7 @@ templ defaultWeekDayComponent(u models.User, day models.IWorkDay) {
@timeGaugeComponent(day.GetDayProgress(u), false)
-

{ day.Date().Format("02.01.2006") }

+

{ day.Date().Format("02.01.2006") }

if day.IsWorkDay() { {{ workDay, _ := day.(*models.WorkDay) diff --git a/Backend/templates/teamComponents_templ.go b/Backend/templates/teamComponents_templ.go index 1c0e46b..6314bce 100644 --- a/Backend/templates/teamComponents_templ.go +++ b/Backend/templates/teamComponents_templ.go @@ -151,9 +151,9 @@ func defaultWeekDayComponent(u models.User, day models.IWorkDay) templ.Component return templ_7745c5c3_Err } var templ_7745c5c3_Var7 string - templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(day.Date().Format("Mon")) + templ_7745c5c3_Var7, templ_7745c5c3_Err = templ.JoinStringErrs(helper.FormatGermanDayOfWeek(day.Date())) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 35, Col: 92} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 35, Col: 108} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var7)) if templ_7745c5c3_Err != nil { @@ -166,7 +166,7 @@ func defaultWeekDayComponent(u models.User, day models.IWorkDay) templ.Component var templ_7745c5c3_Var8 string templ_7745c5c3_Var8, templ_7745c5c3_Err = templ.JoinStringErrs(day.Date().Format("02.01.2006")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 35, Col: 136} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/teamComponents.templ`, Line: 35, Col: 152} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var8)) if templ_7745c5c3_Err != nil { diff --git a/Backend/templates/timePage.templ b/Backend/templates/timePage.templ index 1643cc8..88cd3ec 100644 --- a/Backend/templates/timePage.templ +++ b/Backend/templates/timePage.templ @@ -98,7 +98,7 @@ templ defaultDayComponent(day models.IWorkDay) { @timeGaugeComponent(day.GetDayProgress(user), day.Date().Equal(time.Now().Truncate(24*time.Hour)))

- { day.Date().Format("02.01.2006") } + { day.Date().Format("02.01.2006") }

if day.IsWorkDay() { {{ diff --git a/Backend/templates/timePage_templ.go b/Backend/templates/timePage_templ.go index 0ac75a5..209fa28 100644 --- a/Backend/templates/timePage_templ.go +++ b/Backend/templates/timePage_templ.go @@ -269,9 +269,9 @@ func defaultDayComponent(day models.IWorkDay) templ.Component { return templ_7745c5c3_Err } var templ_7745c5c3_Var12 string - templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(day.Date().Format("Mon")) + templ_7745c5c3_Var12, templ_7745c5c3_Err = templ.JoinStringErrs(helper.FormatGermanDayOfWeek(day.Date())) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timePage.templ`, Line: 101, Col: 82} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timePage.templ`, Line: 101, Col: 98} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var12)) if templ_7745c5c3_Err != nil { @@ -284,7 +284,7 @@ func defaultDayComponent(day models.IWorkDay) templ.Component { var templ_7745c5c3_Var13 string templ_7745c5c3_Var13, templ_7745c5c3_Err = templ.JoinStringErrs(day.Date().Format("02.01.2006")) if templ_7745c5c3_Err != nil { - return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timePage.templ`, Line: 101, Col: 126} + return templ.Error{Err: templ_7745c5c3_Err, FileName: `templates/timePage.templ`, Line: 101, Col: 142} } _, templ_7745c5c3_Err = templ_7745c5c3_Buffer.WriteString(templ.EscapeString(templ_7745c5c3_Var13)) if templ_7745c5c3_Err != nil {