-
Notifications
You must be signed in to change notification settings - Fork 6
/
formatting_test.go
67 lines (57 loc) · 1.51 KB
/
formatting_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
60
61
62
63
64
65
66
67
package gostradamus
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestParseToTime(t *testing.T) {
actualResult, err := parseToTime("2019-01-01 12:12:12", "YYYY-MM-DD HH:mm:ss", UTC)
assert.NoError(t, err)
assert.Equal(t, time.Date(2019, 1, 1, 12, 12, 12, 0, time.UTC), actualResult)
}
func TestParseToTime_Error(t *testing.T) {
actualResult, err := parseToTime("2019-01-01 12:12:12", "YYYY-MM-DD testHH:mm:ss", UTC)
assert.Error(t, err)
assert.Equal(t, time.Time{}, actualResult)
}
func TestParseToTimeOrdinal(t *testing.T) {
actualResult, err := parseToTime("Tuesday 5th April 2011", "dddd Do MMMM YYYY", UTC)
assert.NoError(t, err)
assert.Equal(t, time.Date(2011, 4, 5, 0, 0, 0, 0, time.UTC), actualResult)
}
func TestFormatFromTime(t *testing.T) {
actualResult := formatFromTime(
time.Date(2011, 4, 5, 15, 7, 8, 9, time.UTC),
"YYYY YY MMMM MMM MM M DDDD DD D dddd ddd HH hh h A a mm m ss s S ZZZ zz Z",
)
assert.Equal(
t,
"2011 11 April Apr 04 4 095 05 5 Tuesday Tue 15 03 3 PM pm 07 7 08 8 000000 UTC Z Z",
actualResult,
)
location, err := time.LoadLocation("Japan")
if err != nil {
panic(err)
}
date := time.Date(2011, 4, 5, 15, 7, 8, 9, location)
actualResult = formatFromTime(
date,
"ZZZ zz Z",
)
assert.Equal(
t,
"JST +09:00 +0900",
actualResult,
)
}
func TestOrdinal(t *testing.T) {
actualResult := formatFromTime(
time.Date(2011, 4, 5, 15, 7, 8, 9, time.UTC),
"dddd Do MMMM YYYY",
)
assert.Equal(
t,
"Tuesday 5th April 2011",
actualResult,
)
}