Antares Xpansion
Investment simulations for Antares studies
Loading...
Searching...
No Matches
Clock.h
1
2#pragma once
3
4#include <ctime>
5#include <string>
6
7class Clock
8{
9public:
10 Clock() = default;
11 virtual ~Clock() = default;
12
13 virtual std::time_t getTime()
14 {
15 std::time_t beginTime = std::time(nullptr);
16 return beginTime;
17 }
18};
19
20inline void localtime_platform(const std::time_t& time_p, struct tm& local_time)
21{
22#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
23 localtime_s(&local_time, &time_p);
24#else // defined(__unix__) || (__APPLE__)
25 localtime_r(&time_p, &local_time);
26#endif
27}
28
29namespace clock_utils
30{
31inline std::string timeToStr(const std::time_t& time_p)
32{
33 struct tm local_time;
34 localtime_platform(time_p, local_time);
35 // localtime_r(&time_p, &local_time); // Compliant
36 const char* FORMAT = "%d-%m-%Y %H:%M:%S";
37 char buffer_l[100];
38 strftime(buffer_l, sizeof(buffer_l), FORMAT, &local_time);
39 std::string strTime_l(buffer_l);
40
41 return strTime_l;
42}
43} // namespace clock_utils
Definition Clock.h:8