From 29b594940f37ac30142fa12e728c1cb20c6dff56 Mon Sep 17 00:00:00 2001 From: Thomas Fussell Date: Sat, 9 Jul 2016 10:37:12 -0400 Subject: [PATCH] cover time --- cmake/generate-tests | 2 +- source/utils/tests/test_datetime.hpp | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/cmake/generate-tests b/cmake/generate-tests index 7edae32f..bfc599bb 100755 --- a/cmake/generate-tests +++ b/cmake/generate-tests @@ -1,2 +1,2 @@ cd ${0%/*} -../third-party/cxxtest/bin/cxxtestgen --runner=ErrorPrinter -o "$1"/tests/runner-autogen.cpp ../tests/*.hpp ../source/*/tests/*.hpp +../third-party/cxxtest/bin/cxxtestgen --runner=ErrorPrinter -o "$1"/tests/runner-autogen.cpp ../source/*/tests/*.hpp diff --git a/source/utils/tests/test_datetime.hpp b/source/utils/tests/test_datetime.hpp index 6f48cb59..5519f391 100644 --- a/source/utils/tests/test_datetime.hpp +++ b/source/utils/tests/test_datetime.hpp @@ -8,7 +8,29 @@ class test_datetime : public CxxTest::TestSuite { public: - test_datetime() + void test_from_string() { + xlnt::time t("10:35:45"); + TS_ASSERT_EQUALS(t.hour, 10); + TS_ASSERT_EQUALS(t.minute, 35); + TS_ASSERT_EQUALS(t.second, 45); + } + + void test_carry() + { + // We want a time that rolls over to the next second, minute, and hour + // Start off with a time 1 microsecond before the next hour + xlnt::datetime dt(2016, 7, 9, 10, 59, 59, 999999); + auto number = dt.to_number(xlnt::calendar::windows_1900); + + // Add 600 nanoseconds to the raw number which represents time as a fraction of a day + // In other words, 6 tenths of a millionth of a sixtieth of a sixtieth of a twenty-fourth of a day + number += (0.6 / 1000000) / 60 / 60 / 24; + auto rollover = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900); + + TS_ASSERT_EQUALS(rollover.hour, 11); + TS_ASSERT_EQUALS(rollover.minute, 00); + TS_ASSERT_EQUALS(rollover.second, 00); + TS_ASSERT_EQUALS(rollover.microsecond, 00); } };