From a93b93a3cd1b190203df0cc9031921a6f8407e0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Sun, 18 May 2025 14:26:24 +0200 Subject: [PATCH] v0.0.576 --- goextVersion.go | 4 ++-- timeext/duration.go | 33 +++++++++++++++++++++++++++++++-- 2 files changed, 33 insertions(+), 4 deletions(-) diff --git a/goextVersion.go b/goextVersion.go index 8294bb9..5580c8b 100644 --- a/goextVersion.go +++ b/goextVersion.go @@ -1,5 +1,5 @@ package goext -const GoextVersion = "0.0.575" +const GoextVersion = "0.0.576" -const GoextVersionTimestamp = "2025-05-11T19:17:05+0200" +const GoextVersionTimestamp = "2025-05-18T14:26:24+0200" diff --git a/timeext/duration.go b/timeext/duration.go index 2c13629..3a5ee65 100644 --- a/timeext/duration.go +++ b/timeext/duration.go @@ -43,8 +43,8 @@ func FormatNaturalDurationEnglish(iv time.Duration) string { } } - if min := int64(iv.Minutes()); min < 180 { - return fmt.Sprintf("%d minutes ago", min) + if mins := int64(iv.Minutes()); mins < 180 { + return fmt.Sprintf("%d minutes ago", mins) } if hours := int64(iv.Hours()); hours < 72 { @@ -66,3 +66,32 @@ func FormatNaturalDurationEnglish(iv time.Duration) string { years := int64(iv.Hours() / 24.0 / 7.0 / 365) return fmt.Sprintf("%d years ago", years) } + +func FormatDurationGerman(iv time.Duration) string { + if sec := int64(iv.Seconds()); sec < 180 { + return fmt.Sprintf("%d s", sec) + } + + if mins := int64(iv.Minutes()); mins < 180 { + return fmt.Sprintf("%d min", mins) + } + + if hours := int64(iv.Hours()); hours < 72 { + return fmt.Sprintf("%d h", hours) + } + + if days := int64(iv.Hours() / 24.0); days < 21 { + return fmt.Sprintf("%d Tage", days) + } + + if weeks := int64(iv.Hours() / 24.0 / 7.0); weeks < 12 { + return fmt.Sprintf("%d Wochen", weeks) + } + + if months := int64(iv.Hours() / 24.0 / 7.0 / 30); months < 36 { + return fmt.Sprintf("%d Monate", months) + } + + years := int64(iv.Hours() / 24.0 / 7.0 / 365) + return fmt.Sprintf("%d Jahre", years) +}