-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
common/htime: Fix time.Format with Go layouts
Fixes #9107
- Loading branch information
Showing
2 changed files
with
44 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,8 +17,8 @@ import ( | |
"testing" | ||
"time" | ||
|
||
translators "github.com/gohugoio/localescompressed" | ||
qt "github.com/frankban/quicktest" | ||
translators "github.com/gohugoio/localescompressed" | ||
) | ||
|
||
func TestTimeFormatter(t *testing.T) { | ||
|
@@ -27,6 +27,12 @@ func TestTimeFormatter(t *testing.T) { | |
june06, _ := time.Parse("2006-Jan-02", "2018-Jun-06") | ||
june06 = june06.Add(7777 * time.Second) | ||
|
||
jan06, _ := time.Parse("2006-Jan-02", "2018-Jan-06") | ||
jan06 = jan06.Add(32 * time.Second) | ||
|
||
mondayNovemberFirst, _ := time.Parse("2006-Jan-02", "2021-11-01") | ||
mondayNovemberFirst = mondayNovemberFirst.Add(33 * time.Second) | ||
|
||
c.Run("Norsk nynorsk", func(c *qt.C) { | ||
f := NewTimeFormatter(translators.GetTranslator("nn")) | ||
|
||
|
@@ -73,6 +79,37 @@ func TestTimeFormatter(t *testing.T) { | |
c.Assert(f.Format(june06, "Mon Mon"), qt.Equals, "Wed Wed") | ||
}) | ||
|
||
c.Run("Weekdays German", func(c *qt.C) { | ||
tr := translators.GetTranslator("de") | ||
f := NewTimeFormatter(tr) | ||
|
||
// Issue #9107 | ||
for i, weekDayWideGerman := range []string{"Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "Samstag", "Sonntag"} { | ||
date := mondayNovemberFirst.Add(time.Duration(i*24) * time.Hour) | ||
c.Assert(tr.WeekdayWide(date.Weekday()), qt.Equals, weekDayWideGerman) | ||
c.Assert(f.Format(date, "Monday"), qt.Equals, weekDayWideGerman) | ||
} | ||
|
||
for i, weekDayAbbreviatedGerman := range []string{"Mo.", "Di.", "Mi.", "Do.", "Fr.", "Sa.", "So."} { | ||
date := mondayNovemberFirst.Add(time.Duration(i*24) * time.Hour) | ||
c.Assert(tr.WeekdayAbbreviated(date.Weekday()), qt.Equals, weekDayAbbreviatedGerman) | ||
c.Assert(f.Format(date, "Mon"), qt.Equals, weekDayAbbreviatedGerman) | ||
} | ||
}) | ||
|
||
c.Run("Months German", func(c *qt.C) { | ||
tr := translators.GetTranslator("de") | ||
f := NewTimeFormatter(tr) | ||
|
||
// Issue #9107 | ||
for i, monthWideNorway := range []string{"Januar", "Februar", "März", "April", "Mai", "Juni", "Juli"} { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bep
Author
Member
|
||
date := jan06.Add(time.Duration(i*24*31) * time.Hour) | ||
c.Assert(tr.MonthWide(date.Month()), qt.Equals, monthWideNorway) | ||
c.Assert(f.Format(date, "January"), qt.Equals, monthWideNorway) | ||
} | ||
|
||
}) | ||
|
||
} | ||
|
||
func BenchmarkTimeFormatter(b *testing.B) { | ||
|
1 comment
on commit ed6fd26
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW: Is there support for abbreviated month names?
("Jan." etc ...)
Why just test the first few months? Especially since the others had issues.