diff options
author | lloyd <[email protected]> | 2009-12-01 15:36:30 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-12-01 15:36:30 +0000 |
commit | 29e9b23500d101f01988a33e8f1a6aaab39d5f7d (patch) | |
tree | 28fdc5244d6b618b09a4b0d80fd1708a56401e77 /src/utils | |
parent | 9ffe4441271ff41fd33fc3965c191e62bce36453 (diff) |
Most files including <botan/time.h> actually just needed <chrono>
Clean up implementation of calendar_value() a bit
Diffstat (limited to 'src/utils')
-rw-r--r-- | src/utils/time.cpp | 25 | ||||
-rw-r--r-- | src/utils/time.h | 4 |
2 files changed, 17 insertions, 12 deletions
diff --git a/src/utils/time.cpp b/src/utils/time.cpp index 1c64c820e..97804813d 100644 --- a/src/utils/time.cpp +++ b/src/utils/time.cpp @@ -43,25 +43,26 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz) return res; } -} - -/* -* Convert a time_t to a struct tm -*/ -calendar_point calendar_value( - const std::chrono::system_clock::time_point& time_point) +std::tm do_gmtime(time_t time_val) { - time_t time_val = std::chrono::system_clock::to_time_t(time_point); - // Race condition: std::gmtime is not assured thread safe, // and C++ does not include gmtime_r. Use a mutex here? std::tm* tm_p = std::gmtime(&time_val); if (tm_p == 0) - throw Encoding_Error("time_t_to_tm could not convert"); + throw Encoding_Error("calendar_value could not convert with gmtime"); + return *tm_p; + } - std::tm tm = *tm_p; - // Race is over here +} + +/* +* Convert a time_point to a calendar_point +*/ +calendar_point calendar_value( + const std::chrono::system_clock::time_point& time_point) + { + std::tm tm = do_gmtime(std::chrono::system_clock::to_time_t(time_point)); return calendar_point(tm.tm_year + 1900, tm.tm_mon + 1, diff --git a/src/utils/time.h b/src/utils/time.h index 28b777efe..bd1c8fb06 100644 --- a/src/utils/time.h +++ b/src/utils/time.h @@ -29,6 +29,10 @@ struct BOTAN_DLL calendar_point year(y), month(mon), day(d), hour(h), minutes(min), seconds(sec) {} }; +/* +* @param time_point a time point from the system clock +* @returns calendar_point object representing this time point +*/ BOTAN_DLL calendar_point calendar_value( const std::chrono::system_clock::time_point& time_point); |