Skip to content

Commit e5b7ce4

Browse files
committed
test: types: add test cases for timestamp_type to_string format
Following the previous patch that changed time_point_to_string we should cement the different edge cases for the next time this function changes. Signed-off-by: Benny Halevy <[email protected]>
1 parent 87ee6c3 commit e5b7ce4

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/boost/types_test.cc

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,26 @@ void test_timestamp_like_string_conversions(data_type timestamp_type) {
278278

279279
BOOST_REQUIRE_EQUAL(timestamp_type->to_string(timestamp_type->decompose(tp)), "2015-07-03T00:00:00");
280280

281+
// test fractional milliseconds
282+
tp = db_clock::time_point(db_clock::duration(1435881600123));
283+
BOOST_REQUIRE_EQUAL(timestamp_type->to_string(timestamp_type->decompose(tp)), "2015-07-03T00:00:00.123000");
284+
285+
// test time_stamps around the unix epoch time
286+
tp = db_clock::time_point(db_clock::duration(0));
287+
BOOST_REQUIRE_EQUAL(timestamp_type->to_string(timestamp_type->decompose(tp)), "1970-01-01T00:00:00");
288+
tp = db_clock::time_point(db_clock::duration(456));
289+
BOOST_REQUIRE_EQUAL(timestamp_type->to_string(timestamp_type->decompose(tp)), "1970-01-01T00:00:00.456000");
290+
tp = db_clock::time_point(db_clock::duration(-456));
291+
BOOST_REQUIRE_EQUAL(timestamp_type->to_string(timestamp_type->decompose(tp)), "1969-12-31T23:59:59.544000");
292+
293+
// test time_stamps around year 0
294+
tp = db_clock::time_point(db_clock::duration(-62167219200000));
295+
BOOST_REQUIRE_EQUAL(timestamp_type->to_string(timestamp_type->decompose(tp)), "0-01-01T00:00:00");
296+
tp = db_clock::time_point(db_clock::duration(-62167219199211));
297+
BOOST_REQUIRE_EQUAL(timestamp_type->to_string(timestamp_type->decompose(tp)), "0-01-01T00:00:00.789000");
298+
tp = db_clock::time_point(db_clock::duration(-62167219200789));
299+
BOOST_REQUIRE_EQUAL(timestamp_type->to_string(timestamp_type->decompose(tp)), "-1-12-31T23:59:59.211000");
300+
281301
auto now = time(nullptr);
282302
::tm local_now;
283303
::localtime_r(&now, &local_now);

0 commit comments

Comments
 (0)