diff --git a/en/en.go b/en/en.go index baf343d4f..6aa88f7ba 100644 --- a/en/en.go +++ b/en/en.go @@ -498,10 +498,9 @@ func (en *en) FmtTimeShort(t time.Time) string { b := make([]byte, 0, 32) - h := t.Hour() - - if h > 12 { - h -= 12 + h := t.Hour() % 12 + if h == 0 { + h = 12 } b = strconv.AppendInt(b, int64(h), 10) @@ -528,10 +527,9 @@ func (en *en) FmtTimeMedium(t time.Time) string { b := make([]byte, 0, 32) - h := t.Hour() - - if h > 12 { - h -= 12 + h := t.Hour() % 12 + if h == 0 { + h = 12 } b = strconv.AppendInt(b, int64(h), 10) @@ -565,10 +563,9 @@ func (en *en) FmtTimeLong(t time.Time) string { b := make([]byte, 0, 32) - h := t.Hour() - - if h > 12 { - h -= 12 + h := t.Hour() % 12 + if h == 0 { + h = 12 } b = strconv.AppendInt(b, int64(h), 10) @@ -607,10 +604,9 @@ func (en *en) FmtTimeFull(t time.Time) string { b := make([]byte, 0, 32) - h := t.Hour() - - if h > 12 { - h -= 12 + h := t.Hour() % 12 + if h == 0 { + h = 12 } b = strconv.AppendInt(b, int64(h), 10) diff --git a/en/en_test.go b/en/en_test.go index 1d3cd3b17..a1d0c6794 100644 --- a/en/en_test.go +++ b/en/en_test.go @@ -687,6 +687,10 @@ func TestFmtTimeFull(t *testing.T) { t: time.Date(2016, 02, 03, 20, 5, 1, 0, fixed), expected: "8:05:01 pm OTHER", }, + { + t: time.Date(2016, 02, 03, 0, 0, 1, 0, loc), + expected: "12:00:01 am Eastern Standard Time", + }, } trans := New() @@ -718,6 +722,10 @@ func TestFmtTimeLong(t *testing.T) { t: time.Date(2016, 02, 03, 20, 5, 1, 0, loc), expected: "8:05:01 pm EST", }, + { + t: time.Date(2016, 02, 03, 0, 0, 1, 0, loc), + expected: "12:00:01 am EST", + }, } trans := New() @@ -744,6 +752,10 @@ func TestFmtTimeMedium(t *testing.T) { t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC), expected: "8:05:01 pm", }, + { + t: time.Date(2016, 02, 03, 0, 0, 1, 0, time.UTC), + expected: "12:00:01 am", + }, } trans := New() @@ -770,6 +782,10 @@ func TestFmtTimeShort(t *testing.T) { t: time.Date(2016, 02, 03, 20, 5, 1, 0, time.UTC), expected: "8:05 pm", }, + { + t: time.Date(2016, 02, 03, 0, 0, 1, 0, time.UTC), + expected: "12:00 am", + }, } trans := New()