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 public:
9 Clock() = default;
10 virtual ~Clock() = default;
11
12 virtual std::time_t getTime() {
13 std::time_t beginTime = std::time(nullptr);
14 return beginTime;
15 }
16};
17
18inline void localtime_platform(const std::time_t &time_p,
19 struct tm &local_time) {
20#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
21 localtime_s(&local_time, &time_p);
22#else // defined(__unix__) || (__APPLE__)
23 localtime_r(&time_p, &local_time);
24#endif
25}
26namespace clock_utils {
27inline std::string timeToStr(const std::time_t &time_p) {
28 struct tm local_time;
29 localtime_platform(time_p, local_time);
30 // localtime_r(&time_p, &local_time); // Compliant
31 const char *FORMAT = "%d-%m-%Y %H:%M:%S";
32 char buffer_l[100];
33 strftime(buffer_l, sizeof(buffer_l), FORMAT, &local_time);
34 std::string strTime_l(buffer_l);
35
36 return strTime_l;
37}
38}
Definition Clock.h:7