#pragma once #include #include #include class test_datetime : public test_suite { public: void test_from_string() { xlnt::time t("10:35:45"); assert_equals(t.hour, 10); assert_equals(t.minute, 35); assert_equals(t.second, 45); } void test_to_string() { xlnt::datetime dt(2016, 7, 16, 9, 11, 32, 999999); assert_equals(dt.to_string(), "2016/7/16 9:11:32:999999"); } 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); assert_equals(rollover.hour, 11); assert_equals(rollover.minute, 00); assert_equals(rollover.second, 00); assert_equals(rollover.microsecond, 00); } void test_leap_year_bug() { xlnt::datetime dt(1900, 2, 29, 0, 0, 0, 0); auto number = dt.to_number(xlnt::calendar::windows_1900); assert_equals(static_cast(number), 60); auto converted = xlnt::datetime::from_number(number, xlnt::calendar::windows_1900); assert_equals(dt, converted); } void test_early_date() { xlnt::date d(1900, 1, 29); auto number = d.to_number(xlnt::calendar::windows_1900); assert_equals(number, 29); auto converted = xlnt::date::from_number(number, xlnt::calendar::windows_1900); assert_equals(d, converted); } void test_mac_calendar() { xlnt::date d(2016, 7, 16); auto number_1900 = d.to_number(xlnt::calendar::windows_1900); auto number_1904 = d.to_number(xlnt::calendar::mac_1904); assert_equals(number_1900, 42567); assert_equals(number_1904, 41105); auto converted_1900 = xlnt::date::from_number(number_1900, xlnt::calendar::windows_1900); auto converted_1904 = xlnt::date::from_number(number_1904, xlnt::calendar::mac_1904); assert_equals(converted_1900, d); assert_equals(converted_1904, d); } void test_operators() { xlnt::date d1(2016, 7, 16); xlnt::date d2(2016, 7, 16); xlnt::date d3(2016, 7, 15); assert_equals(d1, d2); assert_differs(d1, d3); } };