@@ -96,32 +96,33 @@ func TestParseTime(t *testing.T) {
96
96
output testTime
97
97
norm string
98
98
l int
99
- err bool
99
+ state TimeState
100
100
}{
101
101
{input : "00:00:00" , norm : "00:00:00.000000" , output : testTime {}},
102
- {input : "00:00:00foo" , norm : "00:00:00.000000" , output : testTime {}, err : true },
102
+ {input : "-00:00:00" , norm : "-00:00:00.000000" , output : testTime {negative : true }},
103
+ {input : "00:00:00foo" , norm : "00:00:00.000000" , output : testTime {}, state : TimePartial },
103
104
{input : "11:12:13" , norm : "11:12:13.000000" , output : testTime {11 , 12 , 13 , 0 , false }},
104
- {input : "11:12:13foo" , norm : "11:12:13.000000" , output : testTime {11 , 12 , 13 , 0 , false }, err : true },
105
+ {input : "11:12:13foo" , norm : "11:12:13.000000" , output : testTime {11 , 12 , 13 , 0 , false }, state : TimePartial },
105
106
{input : "11:12:13.1" , norm : "11:12:13.100000" , output : testTime {11 , 12 , 13 , 100000000 , false }, l : 1 },
106
- {input : "11:12:13.foo" , norm : "11:12:13.000000" , output : testTime {11 , 12 , 13 , 0 , false }, err : true },
107
- {input : "11:12:13.1foo" , norm : "11:12:13.100000" , output : testTime {11 , 12 , 13 , 100000000 , false }, l : 1 , err : true },
107
+ {input : "11:12:13.foo" , norm : "11:12:13.000000" , output : testTime {11 , 12 , 13 , 0 , false }, state : TimePartial },
108
+ {input : "11:12:13.1foo" , norm : "11:12:13.100000" , output : testTime {11 , 12 , 13 , 100000000 , false }, l : 1 , state : TimePartial },
108
109
{input : "11:12:13.123456" , norm : "11:12:13.123456" , output : testTime {11 , 12 , 13 , 123456000 , false }, l : 6 },
109
110
{input : "11:12:13.000001" , norm : "11:12:13.000001" , output : testTime {11 , 12 , 13 , 1000 , false }, l : 6 },
110
111
{input : "11:12:13.000000" , norm : "11:12:13.000000" , output : testTime {11 , 12 , 13 , 0 , false }, l : 6 },
111
- {input : "11:12:13.123456foo" , norm : "11:12:13.123456" , output : testTime {11 , 12 , 13 , 123456000 , false }, l : 6 , err : true },
112
+ {input : "11:12:13.123456foo" , norm : "11:12:13.123456" , output : testTime {11 , 12 , 13 , 123456000 , false }, l : 6 , state : TimePartial },
112
113
{input : "3 11:12:13" , norm : "83:12:13.000000" , output : testTime {3 * 24 + 11 , 12 , 13 , 0 , false }},
113
- {input : "3 11:12:13foo" , norm : "83:12:13.000000" , output : testTime {3 * 24 + 11 , 12 , 13 , 0 , false }, err : true },
114
+ {input : "3 11:12:13foo" , norm : "83:12:13.000000" , output : testTime {3 * 24 + 11 , 12 , 13 , 0 , false }, state : TimePartial },
114
115
{input : "3 41:12:13" , norm : "113:12:13.000000" , output : testTime {3 * 24 + 41 , 12 , 13 , 0 , false }},
115
- {input : "3 41:12:13foo" , norm : "113:12:13.000000" , output : testTime {3 * 24 + 41 , 12 , 13 , 0 , false }, err : true },
116
- {input : "34 23:12:13" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, err : true },
117
- {input : "35 11:12:13" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, err : true },
116
+ {input : "3 41:12:13foo" , norm : "113:12:13.000000" , output : testTime {3 * 24 + 41 , 12 , 13 , 0 , false }, state : TimePartial },
117
+ {input : "34 23:12:13" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, state : TimePartial },
118
+ {input : "35 11:12:13" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, state : TimePartial },
118
119
{input : "11:12" , norm : "11:12:00.000000" , output : testTime {11 , 12 , 0 , 0 , false }},
119
120
{input : "5 11:12" , norm : "131:12:00.000000" , output : testTime {5 * 24 + 11 , 12 , 0 , 0 , false }},
120
121
{input : "-2 11:12" , norm : "-59:12:00.000000" , output : testTime {2 * 24 + 11 , 12 , 0 , 0 , true }},
121
- {input : "--2 11:12" , norm : "00:00:00.000000" , err : true },
122
- {input : "nonsense" , norm : "00:00:00.000000" , err : true },
122
+ {input : "--2 11:12" , norm : "00:00:00.000000" , state : TimeInvalid },
123
+ {input : "nonsense" , norm : "00:00:00.000000" , state : TimeInvalid },
123
124
{input : "2 11" , norm : "59:00:00.000000" , output : testTime {2 * 24 + 11 , 0 , 0 , 0 , false }},
124
- {input : "2 -11" , norm : "00:00:02.000000" , output : testTime {0 , 0 , 2 , 0 , false }, err : true },
125
+ {input : "2 -11" , norm : "00:00:02.000000" , output : testTime {0 , 0 , 2 , 0 , false }, state : TimePartial },
125
126
{input : "13" , norm : "00:00:13.000000" , output : testTime {0 , 0 , 13 , 0 , false }},
126
127
{input : "111213" , norm : "11:12:13.000000" , output : testTime {11 , 12 , 13 , 0 , false }},
127
128
{input : "111213.123456" , norm : "11:12:13.123456" , output : testTime {11 , 12 , 13 , 123456000 , false }, l : 6 },
@@ -130,19 +131,21 @@ func TestParseTime(t *testing.T) {
130
131
{input : "25:12:13" , norm : "25:12:13.000000" , output : testTime {25 , 12 , 13 , 0 , false }},
131
132
{input : "32:35" , norm : "32:35:00.000000" , output : testTime {32 , 35 , 0 , 0 , false }},
132
133
{input : "101:34:58" , norm : "101:34:58.000000" , output : testTime {101 , 34 , 58 , 0 , false }},
134
+ {input : "101:64:58" , norm : "00:00:00.000000" , state : TimeInvalid },
135
+ {input : "101:34:68" , norm : "00:00:00.000000" , state : TimeInvalid },
133
136
{input : "1" , norm : "00:00:01.000000" , output : testTime {0 , 0 , 1 , 0 , false }},
134
137
{input : "11" , norm : "00:00:11.000000" , output : testTime {0 , 0 , 11 , 0 , false }},
135
138
{input : "111" , norm : "00:01:11.000000" , output : testTime {0 , 1 , 11 , 0 , false }},
136
139
{input : "1111" , norm : "00:11:11.000000" , output : testTime {0 , 11 , 11 , 0 , false }},
137
140
{input : "11111" , norm : "01:11:11.000000" , output : testTime {1 , 11 , 11 , 0 , false }},
138
141
{input : "111111" , norm : "11:11:11.000000" , output : testTime {11 , 11 , 11 , 0 , false }},
139
- {input : "1foo" , norm : "00:00:01.000000" , output : testTime {0 , 0 , 1 , 0 , false }, err : true },
140
- {input : "11foo" , norm : "00:00:11.000000" , output : testTime {0 , 0 , 11 , 0 , false }, err : true },
141
- {input : "111foo" , norm : "00:01:11.000000" , output : testTime {0 , 1 , 11 , 0 , false }, err : true },
142
- {input : "1111foo" , norm : "00:11:11.000000" , output : testTime {0 , 11 , 11 , 0 , false }, err : true },
143
- {input : "11111foo" , norm : "01:11:11.000000" , output : testTime {1 , 11 , 11 , 0 , false }, err : true },
144
- {input : "111111foo" , norm : "11:11:11.000000" , output : testTime {11 , 11 , 11 , 0 , false }, err : true },
145
- {input : "1111111foo" , norm : "111:11:11.000000" , output : testTime {111 , 11 , 11 , 0 , false }, err : true },
142
+ {input : "1foo" , norm : "00:00:01.000000" , output : testTime {0 , 0 , 1 , 0 , false }, state : TimePartial },
143
+ {input : "11foo" , norm : "00:00:11.000000" , output : testTime {0 , 0 , 11 , 0 , false }, state : TimePartial },
144
+ {input : "111foo" , norm : "00:01:11.000000" , output : testTime {0 , 1 , 11 , 0 , false }, state : TimePartial },
145
+ {input : "1111foo" , norm : "00:11:11.000000" , output : testTime {0 , 11 , 11 , 0 , false }, state : TimePartial },
146
+ {input : "11111foo" , norm : "01:11:11.000000" , output : testTime {1 , 11 , 11 , 0 , false }, state : TimePartial },
147
+ {input : "111111foo" , norm : "11:11:11.000000" , output : testTime {11 , 11 , 11 , 0 , false }, state : TimePartial },
148
+ {input : "1111111foo" , norm : "111:11:11.000000" , output : testTime {111 , 11 , 11 , 0 , false }, state : TimePartial },
146
149
{input : "-1" , norm : "-00:00:01.000000" , output : testTime {0 , 0 , 1 , 0 , true }},
147
150
{input : "-11" , norm : "-00:00:11.000000" , output : testTime {0 , 0 , 11 , 0 , true }},
148
151
{input : "-111" , norm : "-00:01:11.000000" , output : testTime {0 , 1 , 11 , 0 , true }},
@@ -172,44 +175,31 @@ func TestParseTime(t *testing.T) {
172
175
{input : "11111.1" , norm : "01:11:11.100000" , output : testTime {1 , 11 , 11 , 100000000 , false }, l : 1 },
173
176
{input : "111111.1" , norm : "11:11:11.100000" , output : testTime {11 , 11 , 11 , 100000000 , false }, l : 1 },
174
177
{input : "1111111.1" , norm : "111:11:11.100000" , output : testTime {111 , 11 , 11 , 100000000 , false }, l : 1 },
175
- {input : "20000101" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, err : true },
176
- {input : "-20000101" , norm : "-838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , true }, err : true },
177
- {input : "999995959" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, err : true },
178
- {input : "-999995959" , norm : "-838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , true }, err : true },
179
- {input : "4294965959" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, err : true },
180
- {input : "-4294965959" , norm : "-838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , true }, err : true },
181
- {input : "4294975959" , norm : "00:00:00.000000" , err : true },
182
- {input : "-4294975959" , norm : "00:00:00.000000" , err : true },
183
- {input : "\t 34 foo\t " , norm : "00:00:34.000000" , output : testTime {0 , 0 , 34 , 0 , false }, err : true },
184
- {input : "\t 34 1foo\t " , norm : "817:00:00.000000" , output : testTime {817 , 0 , 0 , 0 , false }, err : true },
185
- {input : "\t 34 23foo\t " , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, err : true },
186
- {input : "\t 35 foo\t " , norm : "00:00:35.000000" , output : testTime {0 , 0 , 35 , 0 , false }, err : true },
187
- {input : "\t 35 1foo\t " , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, err : true },
188
- {input : " 255 foo" , norm : "00:02:55.000000" , output : testTime {0 , 2 , 55 , 0 , false }, err : true },
189
- {input : "255" , norm : "00:02:55.000000" , output : testTime {0 , 2 , 55 , 0 , false }},
178
+ {input : "20000101" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, state : TimePartial },
179
+ {input : "-20000101" , norm : "-838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , true }, state : TimePartial },
180
+ {input : "999995959" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, state : TimePartial },
181
+ {input : "-999995959" , norm : "-838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , true }, state : TimePartial },
182
+ {input : "4294965959" , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, state : TimePartial },
183
+ {input : "-4294965959" , norm : "-838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , true }, state : TimePartial },
184
+ {input : "4294975959" , norm : "00:00:00.000000" , state : TimeInvalid },
185
+ {input : "-4294975959" , norm : "00:00:00.000000" , state : TimeInvalid },
186
+ {input : "\t 34 foo\t " , norm : "00:00:34.000000" , output : testTime {0 , 0 , 34 , 0 , false }, state : TimePartial },
187
+ {input : "\t 34 1foo\t " , norm : "817:00:00.000000" , output : testTime {817 , 0 , 0 , 0 , false }, state : TimePartial },
188
+ {input : "\t 34 23foo\t " , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, state : TimePartial },
189
+ {input : "\t 35 foo\t " , norm : "00:00:35.000000" , output : testTime {0 , 0 , 35 , 0 , false }, state : TimePartial },
190
+ {input : "\t 35 1foo\t " , norm : "838:59:59.000000" , output : testTime {838 , 59 , 59 , 0 , false }, state : TimePartial },
190
191
}
191
192
192
193
for _ , test := range tests {
193
194
t .Run (test .input , func (t * testing.T ) {
194
- got , l , ok := ParseTime (test .input , - 1 )
195
- if test .err {
196
- assert .Equal (t , test .output .hour , got .Hour ())
197
- assert .Equal (t , test .output .minute , got .Minute ())
198
- assert .Equal (t , test .output .second , got .Second ())
199
- assert .Equal (t , test .output .nanosecond , got .Nanosecond ())
200
- assert .Equal (t , test .norm , string (got .AppendFormat (nil , 6 )))
201
- assert .Equal (t , test .l , l )
202
- assert .Falsef (t , ok , "did not fail to parse %s" , test .input )
203
- return
204
- }
205
-
206
- require .True (t , ok )
195
+ got , l , state := ParseTime (test .input , - 1 )
196
+ assert .Equal (t , test .state , state )
207
197
assert .Equal (t , test .output .hour , got .Hour ())
208
198
assert .Equal (t , test .output .minute , got .Minute ())
209
199
assert .Equal (t , test .output .second , got .Second ())
210
200
assert .Equal (t , test .output .nanosecond , got .Nanosecond ())
211
- assert .Equal (t , test .l , l )
212
201
assert .Equal (t , test .norm , string (got .AppendFormat (nil , 6 )))
202
+ assert .Equal (t , test .l , l )
213
203
})
214
204
}
215
205
}
0 commit comments