1
2
3
4
5
6 #include <cmajor/rt/Time.hpp>
7 #include <chrono>
8 #include <thread>
9 #include <ctime>
10
11 int64_t RtNow()
12 {
13 return std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::steady_clock::now().time_since_epoch()).count();
14 }
15
16 void RtSleep(int64_t nanoseconds)
17 {
18 std::chrono::nanoseconds duration{ nanoseconds };
19 std::this_thread::sleep_for(duration);
20 }
21
22 void RtGetCurrentDate(int16_t* year, int8_t* month, int8_t* day)
23 {
24 std::time_t currentTime;
25 std::time(¤tTime);
26 struct tm* localTime = nullptr;
27 localTime = std::localtime(¤tTime);
28 *year = 1900 + localTime->tm_year;
29 *month = 1 + localTime->tm_mon;
30 *day = localTime->tm_mday;
31 }
32
33 void RtGetCurrentDateTime(int16_t* year, int8_t* month, int8_t* day, int32_t* secs)
34 {
35 std::time_t currentTime;
36 std::time(¤tTime);
37 struct tm* localTime = nullptr;
38 localTime = std::localtime(¤tTime);
39 *year = 1900 + localTime->tm_year;
40 *month = 1 + localTime->tm_mon;
41 *day = localTime->tm_mday;
42 *secs = localTime->tm_hour * 3600 + localTime->tm_min * 60 + localTime->tm_sec;
43 }
44
45 int64_t RtGetCurrentTime()
46 {
47 std::time_t currentTime;
48 std::time(¤tTime);
49 return currentTime;
50 }