| 23 | |
| 24 | namespace visage::time { |
| 25 | std::string formatTime(const Time& time, const char* format_string) { |
| 26 | static constexpr int kMaxLength = 100; |
| 27 | |
| 28 | auto t = std::chrono::system_clock::to_time_t(time); |
| 29 | tm time_info {}; |
| 30 | #if VISAGE_WINDOWS |
| 31 | localtime_s(&time_info, &t); |
| 32 | #else |
| 33 | localtime_r(&t, &time_info); |
| 34 | #endif |
| 35 | |
| 36 | char buffer[kMaxLength]; |
| 37 | if (std::strftime(buffer, kMaxLength, format_string, &time_info) == 0) |
| 38 | return ""; |
| 39 | |
| 40 | return buffer; |
| 41 | } |
| 42 | } |