Skip to content

Commit 536fe98

Browse files
authored
Fix localtime
Fix localtime fix #282
1 parent ccb4715 commit 536fe98

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

source/matplot/core/axis_type.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,13 @@
33
//
44

55
#include <cmath>
6+
#if defined(__unix__)
7+
#include <time.h>
8+
#elif defined(_WIN32)
9+
#include <time.h>
10+
#else
611
#include <ctime>
12+
#endif
713
#include <matplot/core/axes_type.h>
814
#include <matplot/core/axis_type.h>
915
#include <matplot/core/figure_type.h>
@@ -257,7 +263,13 @@ namespace matplot {
257263
char buff[20] = {0};
258264
time_t now = (time_t)tick_values_[i];
259265
struct tm buf;
266+
#if defined(__unix__)
267+
localtime_r(&now, &buf);
268+
#elif defined(_WIN32)
260269
localtime_s(&buf, &now);
270+
#else
271+
buf = *std::localtime(&now);
272+
#endif
261273
strftime(buff, 20, tick_label_format_.c_str(), &buf);
262274
r += "\"" + escape(std::string(buff)) + "\" ";
263275
} else {

0 commit comments

Comments
 (0)