diff options
author | Jack Lloyd <[email protected]> | 2017-12-04 16:58:19 -0500 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2017-12-04 16:58:19 -0500 |
commit | f82ee841f719926e91eb4a5533c964821f08488d (patch) | |
tree | 21c5924b896caa716e9a690a6cc2463bbede82ea /src/tests/test_utils.cpp | |
parent | e5f39dd483a08accc8a12e8b322a48037c5b3bf4 (diff) |
Simplify date conversion by avoiding OS utilities
We have to rely on non-portable OS calls to convert UTC times,
and they are not available on many systems (including Solaris and MinGW).
But instead there is a simple algorithm due to Howard Hinnant that
does the same job. Woo.
Diffstat (limited to 'src/tests/test_utils.cpp')
-rw-r--r-- | src/tests/test_utils.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/tests/test_utils.cpp b/src/tests/test_utils.cpp index b8df9c270..3c4accab2 100644 --- a/src/tests/test_utils.cpp +++ b/src/tests/test_utils.cpp @@ -274,26 +274,26 @@ class Date_Format_Tests final : public Text_Based_Test if(type == "valid" || type == "valid.not_std" || type == "valid.64_bit_time_t") { Botan::calendar_point c(d[0], d[1], d[2], d[3], d[4], d[5]); - result.test_is_eq(date_str + " year", c.year, d[0]); - result.test_is_eq(date_str + " month", c.month, d[1]); - result.test_is_eq(date_str + " day", c.day, d[2]); - result.test_is_eq(date_str + " hour", c.hour, d[3]); - result.test_is_eq(date_str + " minute", c.minutes, d[4]); - result.test_is_eq(date_str + " second", c.seconds, d[5]); - - if(type == "valid.not_std" || (type == "valid.64_bit_time_t" && c.year > 2037 && sizeof(std::time_t) == 4)) + result.test_is_eq(date_str + " year", c.get_year(), d[0]); + result.test_is_eq(date_str + " month", c.get_month(), d[1]); + result.test_is_eq(date_str + " day", c.get_day(), d[2]); + result.test_is_eq(date_str + " hour", c.get_hour(), d[3]); + result.test_is_eq(date_str + " minute", c.get_minutes(), d[4]); + result.test_is_eq(date_str + " second", c.get_seconds(), d[5]); + + if(type == "valid.not_std" || (type == "valid.64_bit_time_t" && c.get_year() > 2037 && sizeof(std::time_t) == 4)) { result.test_throws("valid but out of std::timepoint range", [c]() { c.to_std_timepoint(); }); } else { Botan::calendar_point c2 = Botan::calendar_value(c.to_std_timepoint()); - result.test_is_eq(date_str + " year", c2.year, d[0]); - result.test_is_eq(date_str + " month", c2.month, d[1]); - result.test_is_eq(date_str + " day", c2.day, d[2]); - result.test_is_eq(date_str + " hour", c2.hour, d[3]); - result.test_is_eq(date_str + " minute", c2.minutes, d[4]); - result.test_is_eq(date_str + " second", c2.seconds, d[5]); + result.test_is_eq(date_str + " year", c2.get_year(), d[0]); + result.test_is_eq(date_str + " month", c2.get_month(), d[1]); + result.test_is_eq(date_str + " day", c2.get_day(), d[2]); + result.test_is_eq(date_str + " hour", c2.get_hour(), d[3]); + result.test_is_eq(date_str + " minute", c2.get_minutes(), d[4]); + result.test_is_eq(date_str + " second", c2.get_seconds(), d[5]); } } else if(type == "invalid") |