@@ -12,6 +12,14 @@ func TestParse(t *testing.T) {
1212 assert .Empty (t , Parse ("" ).ToString ())
1313 })
1414
15+ t .Run ("invalid time" , func (t * testing.T ) {
16+ assert .True (t , Parse ("0" ).HasError ())
17+ assert .True (t , Parse ("xxx" ).HasError ())
18+
19+ assert .Empty (t , Parse ("0" ).ToString ())
20+ assert .Empty (t , Parse ("xxx" ).ToString ())
21+ })
22+
1523 t .Run ("invalid timezone" , func (t * testing.T ) {
1624 assert .True (t , Parse ("2020-08-05" , "" ).HasError ())
1725 assert .True (t , Parse ("2020-08-05" , "0" ).HasError ())
@@ -22,14 +30,6 @@ func TestParse(t *testing.T) {
2230 assert .Empty (t , Parse ("2020-08-05" , "xxx" ).ToString ())
2331 })
2432
25- t .Run ("invalid time" , func (t * testing.T ) {
26- assert .True (t , Parse ("0" ).HasError ())
27- assert .True (t , Parse ("xxx" ).HasError ())
28-
29- assert .Empty (t , Parse ("0" ).ToString ())
30- assert .Empty (t , Parse ("xxx" ).ToString ())
31- })
32-
3333 t .Run ("without timezone" , func (t * testing.T ) {
3434 assert .Equal (t , Now ().Timestamp (), Parse ("now" ).Timestamp ())
3535 assert .Equal (t , Yesterday ().Timestamp (), Parse ("yesterday" ).Timestamp ())
@@ -80,6 +80,14 @@ func TestParseByFormat(t *testing.T) {
8080 assert .Empty (t , ParseByFormat ("" , DateFormat ).ToString ())
8181 })
8282
83+ t .Run ("invalid time" , func (t * testing.T ) {
84+ assert .True (t , ParseByFormat ("0" , DateFormat ).HasError ())
85+ assert .True (t , ParseByFormat ("xxx" , DateFormat , PRC ).HasError ())
86+
87+ assert .Empty (t , ParseByFormat ("0" , DateFormat ).ToString ())
88+ assert .Empty (t , ParseByFormat ("xxx" , DateFormat , PRC ).ToString ())
89+ })
90+
8391 t .Run ("empty format" , func (t * testing.T ) {
8492 assert .True (t , ParseByFormat ("2020-08-05" , "" ).HasError ())
8593 assert .Empty (t , ParseByFormat ("2020-08-05" , "" ).ToString ())
@@ -106,14 +114,6 @@ func TestParseByFormat(t *testing.T) {
106114 assert .Empty (t , ParseByFormat ("2020-08-05" , TimestampNanoFormat ).ToString ())
107115 })
108116
109- t .Run ("invalid time" , func (t * testing.T ) {
110- assert .True (t , ParseByFormat ("0" , DateFormat ).HasError ())
111- assert .True (t , ParseByFormat ("xxx" , DateFormat , PRC ).HasError ())
112-
113- assert .Empty (t , ParseByFormat ("0" , DateFormat ).ToString ())
114- assert .Empty (t , ParseByFormat ("xxx" , DateFormat , PRC ).ToString ())
115- })
116-
117117 t .Run ("without timezone" , func (t * testing.T ) {
118118 assert .Equal (t , "2020-08-05 00:00:00 +0000 UTC" , ParseByFormat ("2020-08-05" , DateFormat ).ToString ())
119119 assert .Equal (t , "0000-01-01 13:14:15 +0000 UTC" , ParseByFormat ("13:14:15" , TimeFormat ).ToString ())
@@ -149,6 +149,14 @@ func TestParseByLayout(t *testing.T) {
149149 assert .Empty (t , ParseByLayout ("" , DateLayout ).ToString ())
150150 })
151151
152+ t .Run ("invalid time" , func (t * testing.T ) {
153+ assert .True (t , ParseByLayout ("0" , DateFormat ).HasError ())
154+ assert .True (t , ParseByLayout ("xxx" , DateFormat , PRC ).HasError ())
155+
156+ assert .Empty (t , ParseByLayout ("0" , DateFormat ).ToString ())
157+ assert .Empty (t , ParseByLayout ("xxx" , DateFormat , PRC ).ToString ())
158+ })
159+
152160 t .Run ("empty layout" , func (t * testing.T ) {
153161 assert .True (t , ParseByLayout ("2020-08-05" , "" ).HasError ())
154162 assert .Empty (t , ParseByLayout ("2020-08-05" , "" ).ToString ())
@@ -174,14 +182,6 @@ func TestParseByLayout(t *testing.T) {
174182 assert .Empty (t , ParseByLayout ("2020-08-05" , TimestampNanoLayout ).ToString ())
175183 })
176184
177- t .Run ("invalid time" , func (t * testing.T ) {
178- assert .True (t , ParseByLayout ("0" , DateFormat ).HasError ())
179- assert .True (t , ParseByLayout ("xxx" , DateFormat , PRC ).HasError ())
180-
181- assert .Empty (t , ParseByLayout ("0" , DateFormat ).ToString ())
182- assert .Empty (t , ParseByLayout ("xxx" , DateFormat , PRC ).ToString ())
183- })
184-
185185 t .Run ("without timezone" , func (t * testing.T ) {
186186 assert .Equal (t , "2020-08-05 00:00:00 +0000 UTC" , ParseByLayout ("2020-08-05" , DateLayout ).ToString ())
187187 assert .Equal (t , "0000-01-01 13:14:15 +0000 UTC" , ParseByLayout ("13:14:15" , TimeLayout ).ToString ())
@@ -209,6 +209,14 @@ func TestParseWithLayouts(t *testing.T) {
209209 assert .Empty (t , ParseWithLayouts ("" , []string {DateTimeLayout }).ToString ())
210210 })
211211
212+ t .Run ("invalid time" , func (t * testing.T ) {
213+ assert .True (t , ParseWithLayouts ("0" , []string {DateTimeLayout }).HasError ())
214+ assert .True (t , ParseWithLayouts ("xxx" , []string {DateTimeLayout }).HasError ())
215+
216+ assert .Empty (t , ParseWithLayouts ("0" , []string {DateTimeLayout }).ToString ())
217+ assert .Empty (t , ParseWithLayouts ("xxx" , []string {DateTimeLayout }).ToString ())
218+ })
219+
212220 t .Run ("empty layouts" , func (t * testing.T ) {
213221 assert .Equal (t , "2020-08-05 13:14:15 +0000 UTC" , ParseWithLayouts ("2020-08-05 13:14:15" , []string {}).ToString ())
214222 assert .Equal (t , "2006-01-02 15:04:05" , ParseWithLayouts ("2020-08-05 13:14:15" , []string {}).CurrentLayout ())
@@ -222,14 +230,6 @@ func TestParseWithLayouts(t *testing.T) {
222230 assert .Empty (t , ParseWithLayouts ("2020-08-05 13:14:15" , []string {DateLayout }, "xxx" ).ToString ())
223231 })
224232
225- t .Run ("invalid time" , func (t * testing.T ) {
226- assert .True (t , ParseWithLayouts ("0" , []string {DateTimeLayout }).HasError ())
227- assert .True (t , ParseWithLayouts ("xxx" , []string {DateTimeLayout }).HasError ())
228-
229- assert .Empty (t , ParseWithLayouts ("0" , []string {DateTimeLayout }).ToString ())
230- assert .Empty (t , ParseWithLayouts ("xxx" , []string {DateTimeLayout }).ToString ())
231- })
232-
233233 t .Run ("without timezone" , func (t * testing.T ) {
234234 c := ParseWithLayouts ("2020|08|05 13|14|15" , []string {"2006|01|02 15|04|05" , "2006|1|2 3|4|5" })
235235 assert .Equal (t , "2020-08-05 13:14:15 +0000 UTC" , c .ToString ())
@@ -249,6 +249,14 @@ func TestParseWithFormats(t *testing.T) {
249249 assert .Empty (t , ParseWithFormats ("" , []string {DateTimeFormat }).ToString ())
250250 })
251251
252+ t .Run ("invalid time" , func (t * testing.T ) {
253+ assert .True (t , ParseWithFormats ("0" , []string {DateTimeLayout }).HasError ())
254+ assert .True (t , ParseWithFormats ("xxx" , []string {DateTimeLayout }).HasError ())
255+
256+ assert .Empty (t , ParseWithFormats ("0" , []string {DateTimeLayout }).ToString ())
257+ assert .Empty (t , ParseWithFormats ("xxx" , []string {DateTimeLayout }).ToString ())
258+ })
259+
252260 t .Run ("empty layouts" , func (t * testing.T ) {
253261 assert .Equal (t , "2020-08-05 13:14:15 +0000 UTC" , ParseWithFormats ("2020-08-05 13:14:15" , []string {}).ToString ())
254262 assert .Equal (t , "2006-01-02 15:04:05" , ParseWithFormats ("2020-08-05 13:14:15" , []string {}).CurrentLayout ())
@@ -262,14 +270,6 @@ func TestParseWithFormats(t *testing.T) {
262270 assert .Empty (t , ParseWithFormats ("2020-08-05 13:14:15" , []string {DateFormat }, "xxx" ).ToString ())
263271 })
264272
265- t .Run ("invalid time" , func (t * testing.T ) {
266- assert .True (t , ParseWithFormats ("0" , []string {DateTimeLayout }).HasError ())
267- assert .True (t , ParseWithFormats ("xxx" , []string {DateTimeLayout }).HasError ())
268-
269- assert .Empty (t , ParseWithFormats ("0" , []string {DateTimeLayout }).ToString ())
270- assert .Empty (t , ParseWithFormats ("xxx" , []string {DateTimeLayout }).ToString ())
271- })
272-
273273 t .Run ("without timezone" , func (t * testing.T ) {
274274 c := ParseWithFormats ("2020|08|05 13|14|15" , []string {"Y|m|d H|i|s" , "y|m|d h|i|s" })
275275 assert .Equal (t , "2020-08-05 13:14:15 +0000 UTC" , c .ToString ())
0 commit comments