-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiso8601_replacer_test.go
216 lines (173 loc) · 8.85 KB
/
iso8601_replacer_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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
package main
import (
"testing"
"time"
)
type iso8601TestDefinition struct {
Input string
Expected string
}
const format = "Mon 2006 Jan 02 03:04pm MST"
func (definition iso8601TestDefinition) execute(t *testing.T) {
location, _ := time.LoadLocation("America/Denver")
replacer := NewIso8601Replacer()
result := replacer.ReplaceDates(definition.Input, format, location)
if result != definition.Expected {
t.Error(
"For", "\""+definition.Input+"\"",
"expected", "\""+definition.Expected+"\"",
"got", "\""+result+"\"",
)
}
}
// TestUtcDates should work
func TestUtcDates(t *testing.T) {
testDefinitions := []iso8601TestDefinition{
{"2019-03-17T01:02", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17T01:02Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17T01:02:03Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17T01:02:03.4Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17T01:02:03.04Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17T01:02:03.004Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17 01:02:03Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17 01:02:03.4Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17 01:02:03.04Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17 01:02:03.004Z", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17 01:02:03", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17 01:02:03.4", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17 01:02:03.04", "Sat 2019 Mar 16 07:02pm MDT"},
{"2019-03-17 01:02:03.004", "Sat 2019 Mar 16 07:02pm MDT"},
}
for _, definition := range testDefinitions {
definition.execute(t)
}
}
func TestUtcPlusOffset(t *testing.T) {
testDefinitions := []iso8601TestDefinition{
{"2019-03-17T01:02:03Z+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17T01:02:03Z+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03Z+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03Z+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17 01:02:03Z+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03Z+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.4Z+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17T01:02:03.4Z+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.4Z+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.4Z+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17 01:02:03.4Z+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.4Z+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.04Z+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17T01:02:03.04Z+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.04Z+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.04Z+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17 01:02:03.04Z+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.04Z+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.004Z+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17T01:02:03.004Z+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.004Z+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.004Z+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17 01:02:03.004Z+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.004Z+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17T01:02:03+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17 01:02:03+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.4+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17T01:02:03.4+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.4+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.4+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17 01:02:03.4+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.4+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.04+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17T01:02:03.04+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.04+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.04+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17 01:02:03.04+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.04+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.004+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17T01:02:03.004+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17T01:02:03.004+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.004+05", "Sat 2019 Mar 16 02:02pm MDT"},
{"2019-03-17 01:02:03.004+0530", "Sat 2019 Mar 16 01:32pm MDT"},
{"2019-03-17 01:02:03.004+05:30", "Sat 2019 Mar 16 01:32pm MDT"},
}
for _, definition := range testDefinitions {
definition.execute(t)
}
}
func TestUtcMinusOffset(t *testing.T) {
testDefinitions := []iso8601TestDefinition{
{"2019-03-17T01:02:03Z-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17T01:02:03Z-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03Z-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03Z-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17 01:02:03Z-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03Z-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.4Z-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17T01:02:03.4Z-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.4Z-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.4Z-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17 01:02:03.4Z-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.4Z-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.04Z-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17T01:02:03.04Z-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.04Z-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.04Z-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17 01:02:03.04Z-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.04Z-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.004Z-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17T01:02:03.004Z-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.004Z-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.004Z-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17 01:02:03.004Z-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.004Z-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17T01:02:03-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17 01:02:03-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.4-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17T01:02:03.4-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.4-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.4-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17 01:02:03.4-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.4-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.04-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17T01:02:03.04-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.04-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.04-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17 01:02:03.04-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.04-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.004-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17T01:02:03.004-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17T01:02:03.004-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.004-05", "Sun 2019 Mar 17 12:02am MDT"},
{"2019-03-17 01:02:03.004-05:30", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-17 01:02:03.004-0530", "Sun 2019 Mar 17 12:32am MDT"},
{"2019-03-29T15:59:57.368427-06:00", "Fri 2019 Mar 29 03:59pm MDT"},
{"2019-07-16T18:00:00.000000001-06:00", "Tue 2019 Jul 16 06:00pm MDT"},
}
for _, definition := range testDefinitions {
definition.execute(t)
}
}
func TestMultipleDates(t *testing.T) {
testDefinitions := []iso8601TestDefinition{
{"Date 1: 2019-03-17T01:02:03Z-05 and Date 2: 2019-03-17T01:02:03Z-05.", "Date 1: Sun 2019 Mar 17 12:02am MDT and Date 2: Sun 2019 Mar 17 12:02am MDT."},
}
for _, definition := range testDefinitions {
definition.execute(t)
}
}
func TestNonRecognized(t *testing.T) {
testDefinitions := []iso8601TestDefinition{
{"This is a test string with no valid dates", "This is a test string with no valid dates"},
{"This is a test string with an invalid date 2019-03-17 01.", "This is a test string with an invalid date 2019-03-17 01."},
}
for _, definition := range testDefinitions {
definition.execute(t)
}
}