From 9a14888e35620b575f2a5d99471759da439b84ce Mon Sep 17 00:00:00 2001 From: jakopako Date: Sun, 1 Dec 2024 23:13:37 +0100 Subject: [PATCH] support additional date format --- date/date.go | 2 +- date/date_test.go | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/date/date.go b/date/date.go index 4b37e38..69070b0 100644 --- a/date/date.go +++ b/date/date.go @@ -62,7 +62,7 @@ func GetDateFormat(date string, parts CoveredDateParts) (string, string) { return defaultFormat, defaultLanguage } - separators := []rune{' ', ',', '.', '-', ':', '@'} + separators := []rune{' ', ',', '.', '-', ':', '@', '/'} tokens := []string{} sepTokens := []string{} diff --git a/date/date_test.go b/date/date_test.go index 1f9c872..efae140 100644 --- a/date/date_test.go +++ b/date/date_test.go @@ -510,3 +510,35 @@ func TestGetDateFormat17(t *testing.T) { } } } + +func TestGetDateFormat18(t *testing.T) { + dateFormats := []formatTestStruct{ + { + input: "Mi. 04/12/2024", + coveredParts: CoveredDateParts{Day: true, Month: true, Year: true}, + formatString: "Mon. 2/1/2006", + language: "de_DE", + }, + { + input: "Sa. 07/12/2024", + coveredParts: CoveredDateParts{Day: true, Month: true, Year: true}, + formatString: "Mon. 2/1/2006", + language: "de_DE", + }, + { + input: "Sa. 18/01/2024", + coveredParts: CoveredDateParts{Day: true, Month: true, Year: true}, + formatString: "Mon. 2/1/2006", + language: "de_DE", + }, + } + for _, df := range dateFormats { + f, l := GetDateFormat(df.input, df.coveredParts) + if f != df.formatString { + log.Fatalf("expected %s but got %s", df.formatString, f) + } + if l != df.language { + log.Fatalf("expected date language %s but got %s", df.language, l) + } + } +}