10
10
****/
11
11
12
12
#include " stdafx.h"
13
+
13
14
#include < stdint.h>
14
15
#include < string>
15
16
@@ -81,6 +82,10 @@ SUITE(datetime)
81
82
auto dt = utility::datetime::from_string (str, utility::datetime::ISO_8601);
82
83
utility::string_t str2 = dt.to_string (utility::datetime::ISO_8601);
83
84
VERIFY_ARE_EQUAL (str2, strExpected);
85
+
86
+ auto dt_me = utility::datetime::from_string_maximum_error (str, utility::datetime::ISO_8601);
87
+ utility::string_t str3 = dt_me.to_string (utility::datetime::ISO_8601);
88
+ VERIFY_ARE_EQUAL (str3, strExpected);
84
89
}
85
90
86
91
void TestDateTimeRoundtrip (utility::string_t str) { TestDateTimeRoundtrip (str, str); }
@@ -123,32 +128,18 @@ SUITE(datetime)
123
128
TestDateTimeRoundtrip (_XPLATSTR (" 2013-11-19T14:30:59.5Z" ));
124
129
}
125
130
126
- TEST (parsing_time_roundtrip_year_1900)
127
- {
128
- TestDateTimeRoundtrip (_XPLATSTR (" 1900-01-01T00:00:00Z" ));
129
- }
131
+ TEST (parsing_time_roundtrip_year_1900) { TestDateTimeRoundtrip (_XPLATSTR (" 1900-01-01T00:00:00Z" )); }
130
132
131
- TEST (parsing_time_roundtrip_year_9999)
132
- {
133
- TestDateTimeRoundtrip (_XPLATSTR (" 9999-12-31T23:59:59Z" ));
134
- }
133
+ TEST (parsing_time_roundtrip_year_9999) { TestDateTimeRoundtrip (_XPLATSTR (" 9999-12-31T23:59:59Z" )); }
135
134
136
- TEST (parsing_time_roundtrip_year_2016)
137
- {
138
- TestDateTimeRoundtrip (_XPLATSTR (" 2016-12-31T20:59:59Z" ));
139
- }
135
+ TEST (parsing_time_roundtrip_year_2016) { TestDateTimeRoundtrip (_XPLATSTR (" 2016-12-31T20:59:59Z" )); }
140
136
141
- TEST (parsing_time_roundtrip_year_2020)
142
- {
143
- TestDateTimeRoundtrip (_XPLATSTR (" 2020-12-31T20:59:59Z" ));
144
- }
137
+ TEST (parsing_time_roundtrip_year_2020) { TestDateTimeRoundtrip (_XPLATSTR (" 2020-12-31T20:59:59Z" )); }
145
138
146
- TEST (parsing_time_roundtrip_year_2021)
147
- {
148
- TestDateTimeRoundtrip (_XPLATSTR (" 2021-01-01T20:59:59Z" ));
149
- }
139
+ TEST (parsing_time_roundtrip_year_2021) { TestDateTimeRoundtrip (_XPLATSTR (" 2021-01-01T20:59:59Z" )); }
150
140
151
- TEST (emitting_time_correct_day) {
141
+ TEST (emitting_time_correct_day)
142
+ {
152
143
const auto test = utility::datetime () + UINT64_C (132004507640000000 ); // 2019-04-22T23:52:44 is a Monday
153
144
const auto actual = test.to_string (utility::datetime::RFC_1123);
154
145
const utility::string_t expected (_XPLATSTR (" Mon" ));
@@ -296,13 +287,13 @@ SUITE(datetime)
296
287
_XPLATSTR (" Thu, 01 Jan 1970 00:00:00 G" ),
297
288
_XPLATSTR (" Thu, 01 Jan 1970 00:00:00 GM" ),
298
289
_XPLATSTR (" Fri, 01 Jan 1970 00:00:00 GMT" ), // wrong day
299
- _XPLATSTR (" 01 Jan 1899 00:00:00 GMT" ), // year too small
300
- _XPLATSTR (" 01 Xxx 1971 00:00:00 GMT" ), // month bad
301
- _XPLATSTR (" 00 Jan 1971 00:00:00 GMT" ), // day too small
302
- _XPLATSTR (" 32 Jan 1971 00:00:00 GMT" ), // day too big
303
- _XPLATSTR (" 30 Feb 1971 00:00:00 GMT" ), // day too big for feb
304
- _XPLATSTR (" 30 Feb 1971 00:00:00 GMT" ), // day too big for feb (non-leap year)
305
- _XPLATSTR (" 32 Mar 1971 00:00:00 GMT" ), // other months
290
+ _XPLATSTR (" 01 Jan 1899 00:00:00 GMT" ), // year too small
291
+ _XPLATSTR (" 01 Xxx 1971 00:00:00 GMT" ), // month bad
292
+ _XPLATSTR (" 00 Jan 1971 00:00:00 GMT" ), // day too small
293
+ _XPLATSTR (" 32 Jan 1971 00:00:00 GMT" ), // day too big
294
+ _XPLATSTR (" 30 Feb 1971 00:00:00 GMT" ), // day too big for feb
295
+ _XPLATSTR (" 30 Feb 1971 00:00:00 GMT" ), // day too big for feb (non-leap year)
296
+ _XPLATSTR (" 32 Mar 1971 00:00:00 GMT" ), // other months
306
297
_XPLATSTR (" 31 Apr 1971 00:00:00 GMT" ),
307
298
_XPLATSTR (" 32 May 1971 00:00:00 GMT" ),
308
299
_XPLATSTR (" 31 Jun 1971 00:00:00 GMT" ),
@@ -317,8 +308,8 @@ SUITE(datetime)
317
308
_XPLATSTR (" 01 Jan 1971 00:60:00 GMT" ), // minute too big
318
309
_XPLATSTR (" 01 Jan 1971 00:00:70 GMT" ), // second too big
319
310
_XPLATSTR (" 01 Jan 1971 00:00:61 GMT" ),
320
- _XPLATSTR (" 01 Jan 1899 00:00:00 GMT" ), // underflow
321
- _XPLATSTR (" 01 Jan 1969 00:00:00 CEST" ), // bad tz
311
+ _XPLATSTR (" 01 Jan 1899 00:00:00 GMT" ), // underflow
312
+ _XPLATSTR (" 01 Jan 1969 00:00:00 CEST" ), // bad tz
322
313
_XPLATSTR (" 14 Jan 2019 23:16:21 G0100" ), // bad tzoffsets
323
314
_XPLATSTR (" 01 Jan 1970 00:00:00 +2400" ),
324
315
_XPLATSTR (" 01 Jan 1970 00:00:00 -3000" ),
@@ -332,6 +323,8 @@ SUITE(datetime)
332
323
{
333
324
auto dt = utility::datetime::from_string (str, utility::datetime::RFC_1123);
334
325
VERIFY_ARE_EQUAL (0 , dt.to_interval ());
326
+ auto dt_me = utility::datetime::from_string_maximum_error (str, utility::datetime::RFC_1123);
327
+ VERIFY_ARE_EQUAL (utility::datetime::maximum (), dt_me);
335
328
}
336
329
}
337
330
@@ -484,7 +477,7 @@ SUITE(datetime)
484
477
_XPLATSTR (" 1971-01-01T00:60:00Z" ), // minute too big
485
478
_XPLATSTR (" 1971-01-01T00:00:70Z" ), // second too big
486
479
_XPLATSTR (" 1971-01-01T00:00:61Z" ),
487
- _XPLATSTR (" 1899-01-01T00:00:00Z" ), // underflow
480
+ _XPLATSTR (" 1899-01-01T00:00:00Z" ), // underflow
488
481
_XPLATSTR (" 1900-01-01T00:00:00+00:01" ), // time zone underflow
489
482
// _XPLATSTR("1970-01-01T00:00:00.Z"), // accepted as invalid timezone above
490
483
_XPLATSTR (" 1970-01-01T00:00:00+24:00" ), // bad tzoffsets
@@ -499,23 +492,22 @@ SUITE(datetime)
499
492
{
500
493
auto dt = utility::datetime::from_string (str, utility::datetime::ISO_8601);
501
494
VERIFY_ARE_EQUAL (dt.to_interval (), 0 );
495
+ auto dt_me = utility::datetime::from_string_maximum_error (str, utility::datetime::ISO_8601);
496
+ VERIFY_ARE_EQUAL (dt_me, utility::datetime::maximum ());
502
497
}
503
498
}
504
499
505
- TEST (can_emit_nt_epoch_zero )
500
+ TEST (can_emit_nt_epoch_zero_rfc_1123 )
506
501
{
507
- // ISO 8601
508
- {
509
- auto result = utility::datetime{}.to_string (utility::datetime::RFC_1123);
510
- VERIFY_ARE_EQUAL (_XPLATSTR (" Mon, 01 Jan 1601 00:00:00 GMT" ), result);
511
- }
512
- // ISO 8601
513
- {
514
- auto result = utility::datetime{}.to_string (utility::datetime::ISO_8601);
515
- VERIFY_ARE_EQUAL (_XPLATSTR (" 1601-01-01T00:00:00Z" ), result);
516
- }
502
+ auto result = utility::datetime {}.to_string (utility::datetime::RFC_1123);
503
+ VERIFY_ARE_EQUAL (_XPLATSTR (" Mon, 01 Jan 1601 00:00:00 GMT" ), result);
517
504
}
518
505
506
+ TEST (can_emit_nt_epoch_zero_iso_8601)
507
+ {
508
+ auto result = utility::datetime {}.to_string (utility::datetime::ISO_8601);
509
+ VERIFY_ARE_EQUAL (_XPLATSTR (" 1601-01-01T00:00:00Z" ), result);
510
+ }
519
511
} // SUITE(datetime)
520
512
521
513
} // namespace utils_tests
0 commit comments