| 102 | }; |
| 103 | |
| 104 | inline std::tm *localtime_thread_safe(const std::time_t *time, std::tm *buf) { |
| 105 | #if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || defined(_MSC_VER) |
| 106 | if (localtime_s(buf, time)) |
| 107 | return nullptr; |
| 108 | return buf; |
| 109 | #else |
| 110 | static std::mutex mtx; |
| 111 | std::lock_guard<std::mutex> lock(mtx); |
| 112 | std::tm *tm_ptr = std::localtime(time); |
| 113 | if (tm_ptr != nullptr) { |
| 114 | *buf = *tm_ptr; |
| 115 | } |
| 116 | return tm_ptr; |
| 117 | #endif |
| 118 | } |
| 119 | |
| 120 | // This is for casting times on the system clock into datetime.datetime instances |
| 121 | template <typename Duration> |