aboutsummaryrefslogtreecommitdiffstats
path: root/src/utils/time.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/utils/time.cpp')
-rw-r--r--src/utils/time.cpp27
1 files changed, 16 insertions, 11 deletions
diff --git a/src/utils/time.cpp b/src/utils/time.cpp
index 856b1c7be..1c64c820e 100644
--- a/src/utils/time.cpp
+++ b/src/utils/time.cpp
@@ -45,25 +45,30 @@ u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
}
-/**
-* Get the system clock
-*/
-u64bit system_time()
- {
- return static_cast<u64bit>(std::time(0));
- }
-
/*
* Convert a time_t to a struct tm
*/
-std::tm time_t_to_tm(u64bit timer)
+calendar_point calendar_value(
+ const std::chrono::system_clock::time_point& time_point)
{
- std::time_t time_val = static_cast<std::time_t>(timer);
+ 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");
- return (*tm_p);
+
+ std::tm tm = *tm_p;
+ // Race is over here
+
+ return calendar_point(tm.tm_year + 1900,
+ tm.tm_mon + 1,
+ tm.tm_mday,
+ tm.tm_hour,
+ tm.tm_min,
+ tm.tm_sec);
}
u64bit get_nanoseconds_clock()