Skip to content

Commit 5da0829

Browse files
committed
use __APPLE__ preprocessor macro
1 parent 04d7457 commit 5da0829

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

include/formatters/junit_xml.hpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,18 @@ struct TestSuite {
116116

117117
[[nodiscard]] std::string to_xml() const {
118118
std::string timestamp_str;
119-
if constexpr (requires { std::chrono::current_zone(); }) {
120-
auto localtime = std::chrono::zoned_time(std::chrono::current_zone(), timestamp).get_local_time();
121-
timestamp_str = std::format("{0:%F}T{0:%T}", localtime);
122-
} else {
123-
// Cludge because macOS doesn't have std::chrono::current_zone() or std::chrono::zoned_time()
124-
std::time_t time_t_timestamp = std::chrono::system_clock::to_time_t(timestamp);
125-
std::tm localtime = *std::localtime(&time_t_timestamp);
126-
std::ostringstream oss;
127-
oss << std::put_time(&localtime, "%Y-%m-%dT%H:%M:%S");
128-
timestamp_str = oss.str();
129-
}
119+
#ifdef __APPLE__
120+
// Cludge because macOS doesn't have std::chrono::current_zone() or std::chrono::zoned_time()
121+
std::time_t time_t_timestamp = std::chrono::system_clock::to_time_t(timestamp);
122+
std::tm localtime = *std::localtime(&time_t_timestamp);
123+
std::ostringstream oss;
124+
oss << std::put_time(&localtime, "%Y-%m-%dT%H:%M:%S");
125+
timestamp_str = oss.str();
126+
#else
127+
// Use std::chrono::current_zone() and std::chrono::zoned_time() if available (C++20)
128+
auto localtime = std::chrono::zoned_time(std::chrono::current_zone(), timestamp).get_local_time();
129+
timestamp_str = std::format("{0:%F}T{0:%T}", localtime);
130+
#endif
130131

131132
std::stringstream ss;
132133
ss << " "

0 commit comments

Comments
 (0)