Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
update time parsing
  • Loading branch information
ccbrown committed Sep 1, 2018
commit 707603f504881537e70aa030a3ac5fb00b113d69
57 changes: 51 additions & 6 deletions server/localization.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,36 @@ func (l *Locale) ForumHost() string {
return "www.pathofexile.com"
}

var esMonthReplacer = strings.NewReplacer(
"ene", "Jan",
"feb", "Feb",
"mar", "Mar",
"abr", "Apr",
"may", "May",
"jun", "Jun",
"jul", "Jul",
"ago", "Aug",
"sep", "Sep",
"oct", "Oct",
"nov", "Nov",
"dic", "Dec",
)

var brMonthReplacer = strings.NewReplacer(
"de jan de", "Jan",
"de fev de", "Feb",
"de mar de", "Mar",
"de abr de", "Apr",
"de mai de", "May",
"de jun de", "Jun",
"de jul de", "Jul",
"de ago de", "Aug",
"de set de", "Sep",
"de out de", "Oct",
"de nov de", "Nov",
"de dez de", "Dec",
)

var thMonthReplacer = strings.NewReplacer(
"ม.ค.", "Jan",
"ก.พ.", "Feb",
Expand Down Expand Up @@ -70,20 +100,35 @@ var frMonthReplacer = strings.NewReplacer(
"déc.", "Dec",
)

var ruMonthReplacer = strings.NewReplacer(
"янв.", "Jan",
"февр.", "Feb",
"марта", "Mar",
"апр.", "Apr",
"мая", "May",
"июня", "Jun",
"июля", "Jul",
"авг.", "Aug",
"сент.", "Sep",
"окт.", "Oct",
"нояб.", "Nov",
"дек.", "Dec",
)

// TODO: add translations
var Locales = []*Locale{
{
IncludeReddit: true,
Image: "static/images/locales/gb.png",
ParseTime: func(s string, tz *time.Location) (time.Time, error) {
return time.ParseInLocation("Jan _2, 2006 3:04:05 PM", s, tz)
return time.ParseInLocation("Jan _2, 2006, 3:04:05 PM", s, tz)
},
},
{
Subdomain: "br",
Image: "static/images/locales/br.png",
ParseTime: func(s string, tz *time.Location) (time.Time, error) {
return time.ParseInLocation("2/1/2006 15:04:05", s, tz)
return time.ParseInLocation("2 Jan 2006 15:04:05", brMonthReplacer.Replace(s), tz)
},
Translations: map[string]string{
"Activity": "Atividade",
Expand All @@ -97,7 +142,7 @@ var Locales = []*Locale{
Subdomain: "ru",
Image: "static/images/locales/ru.png",
ParseTime: func(s string, tz *time.Location) (time.Time, error) {
return time.ParseInLocation("2.1.2006 15:04:05", s, tz)
return time.ParseInLocation("2 Jan 2006 г., 15:04:05", ruMonthReplacer.Replace(s), tz)
},
Translations: map[string]string{
"Activity": "Активность",
Expand All @@ -111,14 +156,14 @@ var Locales = []*Locale{
Subdomain: "th",
Image: "static/images/locales/th.png",
ParseTime: func(s string, tz *time.Location) (time.Time, error) {
return time.ParseInLocation("_2 Jan 2006, 15:04:05", thMonthReplacer.Replace(s), tz)
return time.ParseInLocation("_2 Jan 2006 15:04:05", thMonthReplacer.Replace(s), tz)
},
},
{
Subdomain: "de",
Image: "static/images/locales/de.png",
ParseTime: func(s string, tz *time.Location) (time.Time, error) {
return time.ParseInLocation("2.1.2006 15:04:05", s, tz)
return time.ParseInLocation("2.1.2006, 15:04:05", s, tz)
},
Translations: map[string]string{
"Activity": "Aktivität",
Expand Down Expand Up @@ -146,7 +191,7 @@ var Locales = []*Locale{
Subdomain: "es",
Image: "static/images/locales/es.png",
ParseTime: func(s string, tz *time.Location) (time.Time, error) {
return time.ParseInLocation("2/1/2006 15:04:05", s, tz)
return time.ParseInLocation("2 Jan. 2006 15:04:05", esMonthReplacer.Replace(s), tz)
},
Translations: map[string]string{
"Activity": "Actividad",
Expand Down
32 changes: 32 additions & 0 deletions server/localization_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package server

import (
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func TestLocale_ParseTime(t *testing.T) {
for subdomain, s := range map[string]string{
"": "Aug 29, 2018, 5:51:19 PM",
"br": "31 de ago de 2018 00:50:19",
"ru": "1 сент. 2018 г., 2:09:52",
"th": "31 ส.ค. 2018 00:50:25",
"de": "31.08.2018, 00:50:20",
"fr": "31 août 2018 00:50:22",
"es": "31 ago. 2018 0:50:23",
} {
t.Run(subdomain, func(t *testing.T) {
var locale *Locale
for _, l := range Locales {
if l.Subdomain == subdomain {
locale = l
break
}
}
_, err := locale.ParseTime(s, time.FixedZone("UTC-5", -5*60*60))
assert.NoError(t, err)
})
}
}