forked from emmaly/go-pkg-rss
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
timeparser_test.go
94 lines (83 loc) · 2.41 KB
/
timeparser_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package feeder
import (
"testing"
"time"
)
func Test_InvalidDate(t *testing.T) {
date, err := parseTime("invalid")
if !date.IsZero() {
t.Errorf("Invalid date should parse to zero")
}
if err == nil {
t.Errorf("error should not be nil")
}
}
func Test_ParseLayout0(t *testing.T) {
date, err := parseTime("2014-03-07T05:38:00-05:00")
expected := time.Date(2014, time.March, 7, 5, 38, 0, 0, time.FixedZone("-0500", -18000))
assertEqualTime(t, expected, date)
if err != nil {
t.Errorf("err should be nil")
}
}
func Test_ParseLayout1(t *testing.T) {
date, err := parseTime("Fri, 07 Mar 2014 17:42:51 GMT")
expected := time.Date(2014, time.March, 7, 17, 42, 51, 0, time.UTC)
assertEqualTime(t, expected, date)
if err != nil {
t.Errorf("err should be nil")
}
}
func Test_ParseLayout2(t *testing.T) {
date, err := parseTime("2014-02-05T23:33:34Z")
expected := time.Date(2014, time.February, 5, 23, 33, 34, 0, time.UTC)
assertEqualTime(t, expected, date)
if err != nil {
t.Errorf("err should be nil")
}
}
func Test_ParseLayout3(t *testing.T) {
date, err := parseTime("Mon, 03 Mar 2014 02:12:25 +0000")
expected := time.Date(2014, time.March, 3, 2, 12, 25, 0, time.UTC)
assertEqualTime(t, expected, date)
if err != nil {
t.Errorf("err should be nil")
}
}
func Test_ParseLayout4(t *testing.T) {
date, err := parseTime("Fri, 21, Mar 2014 10:41")
expected := time.Date(2014, time.March, 21, 10, 41, 0, 0, time.UTC)
assertEqualTime(t, expected, date)
if err != nil {
t.Errorf("err should be nil")
}
}
func Test_ParseLayout4_1(t *testing.T) {
date, err := parseTime("Fri, 17, Jan 2014 11:1")
expected := time.Date(2014, time.January, 17, 11, 1, 0, 0, time.UTC)
assertEqualTime(t, expected, date)
if err != nil {
t.Errorf("err should be nil")
}
}
func Test_ParseLayout4_2(t *testing.T) {
date, err := parseTime("Thu, 9, Jan 2014 10:19")
expected := time.Date(2014, time.January, 9, 10, 19, 0, 0, time.UTC)
assertEqualTime(t, expected, date)
if err != nil {
t.Errorf("err should be nil")
}
}
func Test_ParseLayout5(t *testing.T) {
date, err := parseTime("22 Jul 2013 14:55:01 EST")
expected := time.Date(2013, time.July, 22, 14, 55, 1, 0, time.FixedZone("EST", -18000))
assertEqualTime(t, expected, date)
if err != nil {
t.Errorf("err should be nil")
}
}
func assertEqualTime(t *testing.T, expected, actual time.Time) {
if !expected.Equal(actual) {
t.Errorf("expected %v but was %v", expected, actual)
}
}