Skip to content

Commit abd58a2

Browse files
committed
Fix for utiltime to compile with msvc.
1 parent 0a8b7b4 commit abd58a2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/utiltime.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,20 +79,32 @@ void MilliSleep(int64_t n)
7979
std::string FormatISO8601DateTime(int64_t nTime) {
8080
struct tm ts;
8181
time_t time_val = nTime;
82+
#ifdef _MSC_VER
83+
gmtime_s(&ts, &time_val);
84+
#else
8285
gmtime_r(&time_val, &ts);
86+
#endif
8387
return strprintf("%04i-%02i-%02iT%02i:%02i:%02iZ", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday, ts.tm_hour, ts.tm_min, ts.tm_sec);
8488
}
8589

8690
std::string FormatISO8601Date(int64_t nTime) {
8791
struct tm ts;
8892
time_t time_val = nTime;
93+
#ifdef _MSC_VER
94+
gmtime_s(&ts, &time_val);
95+
#else
8996
gmtime_r(&time_val, &ts);
97+
#endif
9098
return strprintf("%04i-%02i-%02i", ts.tm_year + 1900, ts.tm_mon + 1, ts.tm_mday);
9199
}
92100

93101
std::string FormatISO8601Time(int64_t nTime) {
94102
struct tm ts;
95103
time_t time_val = nTime;
104+
#ifdef _MSC_VER
105+
gmtime_s(&ts, &time_val);
106+
#else
96107
gmtime_r(&time_val, &ts);
108+
#endif
97109
return strprintf("%02i:%02i:%02iZ", ts.tm_hour, ts.tm_min, ts.tm_sec);
98110
}

0 commit comments

Comments
 (0)