@@ -17,8 +17,9 @@ import (
1717 "testing"
1818 "time"
1919
20+ "github.com/bep/golocales"
21+
2022 qt "github.com/frankban/quicktest"
21- translators "github.com/gohugoio/localescompressed"
2223)
2324
2425func TestTimeFormatter (t * testing.T ) {
@@ -34,75 +35,75 @@ func TestTimeFormatter(t *testing.T) {
3435 mondayNovemberFirst = mondayNovemberFirst .Add (33 * time .Second )
3536
3637 c .Run ("Norsk nynorsk" , func (c * qt.C ) {
37- f := NewTimeFormatter (translators . GetTranslator ("nn" ))
38+ f := NewTimeFormatter (golocales . New ("nn" ))
3839
3940 c .Assert (f .Format (june06 , "Monday Jan 2 2006" ), qt .Equals , "onsdag juni 6 2018" )
4041 c .Assert (f .Format (june06 , "Mon January 2 2006" ), qt .Equals , "on. juni 6 2018" )
4142 c .Assert (f .Format (june06 , "Mon Mon" ), qt .Equals , "on. on." )
4243 })
4344
4445 c .Run ("Custom layouts Norsk nynorsk" , func (c * qt.C ) {
45- f := NewTimeFormatter (translators . GetTranslator ("nn" ))
46+ f := NewTimeFormatter (golocales . New ("nn" ))
4647
4748 c .Assert (f .Format (june06 , ":date_full" ), qt .Equals , "onsdag 6. juni 2018" )
4849 c .Assert (f .Format (june06 , ":date_long" ), qt .Equals , "6. juni 2018" )
4950 c .Assert (f .Format (june06 , ":date_medium" ), qt .Equals , "6. juni 2018" )
50- c .Assert (f .Format (june06 , ":date_short" ), qt .Equals , "06.06.2018 " )
51+ c .Assert (f .Format (june06 , ":date_short" ), qt .Equals , "06.06.18 " )
5152
52- c .Assert (f .Format (june06 , ":time_full" ), qt .Equals , "kl. 02:09:37 UTC" )
53+ c .Assert (f .Format (june06 , ":time_full" ), qt .Equals , "02:09:37 UTC" )
5354 c .Assert (f .Format (june06 , ":time_long" ), qt .Equals , "02:09:37 UTC" )
5455 c .Assert (f .Format (june06 , ":time_medium" ), qt .Equals , "02:09:37" )
5556 c .Assert (f .Format (june06 , ":time_short" ), qt .Equals , "02:09" )
5657 })
5758
5859 c .Run ("Custom layouts English" , func (c * qt.C ) {
59- f := NewTimeFormatter (translators . GetTranslator ("en" ))
60+ f := NewTimeFormatter (golocales . New ("en" ))
6061
6162 c .Assert (f .Format (june06 , ":date_full" ), qt .Equals , "Wednesday, June 6, 2018" )
6263 c .Assert (f .Format (june06 , ":date_long" ), qt .Equals , "June 6, 2018" )
6364 c .Assert (f .Format (june06 , ":date_medium" ), qt .Equals , "Jun 6, 2018" )
6465 c .Assert (f .Format (june06 , ":date_short" ), qt .Equals , "6/6/18" )
6566
66- c .Assert (f .Format (june06 , ":time_full" ), qt .Equals , "2:09:37 am UTC" )
67- c .Assert (f .Format (june06 , ":time_long" ), qt .Equals , "2:09:37 am UTC" )
68- c .Assert (f .Format (june06 , ":time_medium" ), qt .Equals , "2:09:37 am " )
69- c .Assert (f .Format (june06 , ":time_short" ), qt .Equals , "2:09 am " )
67+ c .Assert (f .Format (june06 , ":time_full" ), qt .Equals , "2:09:37\u202f am UTC" )
68+ c .Assert (f .Format (june06 , ":time_long" ), qt .Equals , "2:09:37\u202f am UTC" )
69+ c .Assert (f .Format (june06 , ":time_medium" ), qt .Equals , "2:09:37\u202f am " )
70+ c .Assert (f .Format (june06 , ":time_short" ), qt .Equals , "2:09\u202f am " )
7071 })
7172
7273 c .Run ("English" , func (c * qt.C ) {
73- f := NewTimeFormatter (translators . GetTranslator ("en" ))
74+ f := NewTimeFormatter (golocales . New ("en" ))
7475
7576 c .Assert (f .Format (june06 , "Monday Jan 2 2006" ), qt .Equals , "Wednesday Jun 6 2018" )
7677 c .Assert (f .Format (june06 , "Mon January 2 2006" ), qt .Equals , "Wed June 6 2018" )
7778 c .Assert (f .Format (june06 , "Mon Mon" ), qt .Equals , "Wed Wed" )
7879 })
7980
8081 c .Run ("Weekdays German" , func (c * qt.C ) {
81- tr := translators . GetTranslator ("de" )
82+ tr := golocales . New ("de" )
8283 f := NewTimeFormatter (tr )
8384
8485 // Issue #9107
8586 for i , weekDayWideGerman := range []string {"Montag" , "Dienstag" , "Mittwoch" , "Donnerstag" , "Freitag" , "Samstag" , "Sonntag" } {
8687 date := mondayNovemberFirst .Add (time .Duration (i * 24 ) * time .Hour )
87- c .Assert (tr .WeekdayWide ( date .Weekday ()) , qt .Equals , weekDayWideGerman )
88+ c .Assert (tr .WeekdaysWide ()[ date .Weekday ()] , qt .Equals , weekDayWideGerman )
8889 c .Assert (f .Format (date , "Monday" ), qt .Equals , weekDayWideGerman )
8990 }
9091
9192 for i , weekDayAbbreviatedGerman := range []string {"Mo." , "Di." , "Mi." , "Do." , "Fr." , "Sa." , "So." } {
9293 date := mondayNovemberFirst .Add (time .Duration (i * 24 ) * time .Hour )
93- c .Assert (tr .WeekdayAbbreviated ( date .Weekday ()) , qt .Equals , weekDayAbbreviatedGerman )
94+ c .Assert (tr .WeekdaysAbbreviated ()[ date .Weekday ()] , qt .Equals , weekDayAbbreviatedGerman )
9495 c .Assert (f .Format (date , "Mon" ), qt .Equals , weekDayAbbreviatedGerman )
9596 }
9697 })
9798
9899 c .Run ("Months German" , func (c * qt.C ) {
99- tr := translators . GetTranslator ("de" )
100+ tr := golocales . New ("de" )
100101 f := NewTimeFormatter (tr )
101102
102103 // Issue #9107
103104 for i , monthWideNorway := range []string {"Januar" , "Februar" , "März" , "April" , "Mai" , "Juni" , "Juli" } {
104105 date := jan06 .Add (time .Duration (i * 24 * 31 ) * time .Hour )
105- c .Assert (tr .MonthWide ( date .Month ()) , qt .Equals , monthWideNorway )
106+ c .Assert (tr .MonthsWide ()[ date .Month ()- 1 ] , qt .Equals , monthWideNorway )
106107 c .Assert (f .Format (date , "January" ), qt .Equals , monthWideNorway )
107108 }
108109 })
@@ -121,7 +122,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
121122 })
122123
123124 b .Run ("Localized" , func (b * testing.B ) {
124- f := NewTimeFormatter (translators . GetTranslator ("nn" ))
125+ f := NewTimeFormatter (golocales . New ("nn" ))
125126 b .ResetTimer ()
126127 for b .Loop () {
127128 got := f .Format (june06 , "Monday Jan 2 2006" )
@@ -132,7 +133,7 @@ func BenchmarkTimeFormatter(b *testing.B) {
132133 })
133134
134135 b .Run ("Localized Custom" , func (b * testing.B ) {
135- f := NewTimeFormatter (translators . GetTranslator ("nn" ))
136+ f := NewTimeFormatter (golocales . New ("nn" ))
136137 b .ResetTimer ()
137138 for b .Loop () {
138139 got := f .Format (june06 , ":date_medium" )
0 commit comments