forked from theplant/cldr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
calendar_test.go
59 lines (51 loc) · 1.8 KB
/
calendar_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package cldr_test
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"golang.org/x/text/language"
"github.com/razor-1/cldr/resources"
)
const dateTimeString = "Jan 2, 2006 at 3:04:05pm"
func TestFormatDateTime(t *testing.T) {
datetime, _ := time.Parse(dateTimeString, dateTimeString)
ta := assert.New(t)
en, err := resources.GetLocale(language.Make("en"))
ta.NoError(err)
tests := []struct {
inTime time.Time
err error
fmtFunc func(time.Time) (string, error)
format string
}{
{fmtFunc: en.Calendar.FmtDateFull, format: "Monday, January 2, 2006"},
{fmtFunc: en.Calendar.FmtDateLong, format: "January 2, 2006"},
{fmtFunc: en.Calendar.FmtDateMedium, format: "Jan 2, 2006"},
{fmtFunc: en.Calendar.FmtDateShort, format: "1/2/06"},
{fmtFunc: en.Calendar.FmtTimeFull, format: "3:04:05 PM GMT+00:00"},
{fmtFunc: en.Calendar.FmtTimeLong, format: "3:04:05 PM GMT+00:00"},
{fmtFunc: en.Calendar.FmtTimeMedium, format: "3:04:05 PM"},
{fmtFunc: en.Calendar.FmtTimeShort, format: "3:04 PM"},
{fmtFunc: en.Calendar.FmtDateTimeFull, format: "Monday, January 2, 2006 at 3:04:05 PM GMT+00:00"},
{fmtFunc: en.Calendar.FmtDateTimeLong, format: "January 2, 2006 at 3:04:05 PM GMT+00:00"},
{fmtFunc: en.Calendar.FmtDateTimeMedium, format: "Jan 2, 2006, 3:04:05 PM"},
{fmtFunc: en.Calendar.FmtDateTimeShort, format: "1/2/06, 3:04 PM"},
}
for _, test := range tests {
t.Run("", func(t *testing.T) {
var tm time.Time
if test.inTime.IsZero() {
// all tests use datetime. default to it but still allow an easy override for future tests
tm = datetime
} else {
tm = test.inTime
}
out, err := test.fmtFunc(tm)
ta.Equal(test.err, err)
ta.Equal(test.format, out)
})
}
r, err := en.Calendar.Format(datetime, "MMMM d yy")
ta.NoError(err)
ta.Equal("January 2 06", r)
}