Skip to content

Commit 83bfab8

Browse files
committed
Fix macos which in 2025 still does not support C++20
1 parent dbdc081 commit 83bfab8

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/dsf/headers/Dynamics.hpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,15 @@ namespace dsf {
9797
/// @brief Get the current simulation time as formatted string (YYYY-MM-DD HH:MM:SS)
9898
/// @return std::string, The current simulation time as formatted string
9999
inline auto strDateTime() const {
100+
#ifdef __APPLE__
101+
auto const t = time();
102+
return std::format("{:%Y-%m-%d %H:%M:%S}", *std::localtime(&t));
103+
#else
100104
return std::format(
101-
"{:%Y-%m-%d %H:%M:%S}", std::chrono::floor<std::chrono::seconds>(std::chrono::current_zone()->to_local(
102-
std::chrono::system_clock::from_time_t(time()))));
105+
"{:%Y-%m-%d %H:%M:%S}",
106+
std::chrono::floor<std::chrono::seconds>(std::chrono::current_zone()->to_local(
107+
std::chrono::system_clock::from_time_t(time()))));
108+
#endif
103109
}
104110
};
105111

test/Test_dynamics.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,19 @@ TEST_CASE("FirstOrderDynamics") {
225225
graph.importMatrix("./data/matrix.dat", false);
226226
// graph.adjustNodeCapacities();
227227
FirstOrderDynamics dynamics{graph, false, 69, 0., dsf::PathWeight::LENGTH};
228+
#ifdef __APPLE__
229+
{
230+
std::time_t const t{0};
231+
CHECK_EQ(dynamics.strDateTime(),
232+
std::format("{:%Y-%m-%d %H:%M:%S}", *std::localtime(&t)));
233+
}
234+
#else
228235
CHECK_EQ(dynamics.strDateTime(),
229236
std::format("{:%Y-%m-%d %H:%M:%S}",
230237
std::chrono::floor<std::chrono::seconds>(
231238
std::chrono::current_zone()->to_local(
232239
std::chrono::system_clock::from_time_t(0)))));
240+
#endif
233241
auto const epochStart{
234242
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())};
235243
dynamics.setInitTime(epochStart);
@@ -244,13 +252,21 @@ TEST_CASE("FirstOrderDynamics") {
244252
CHECK(dynamics.nAgents() < n);
245253
CHECK_EQ(dynamics.time_step(), 40);
246254
CHECK_EQ(dynamics.time() - epochStart, 40);
255+
#ifdef __APPLE__
256+
{
257+
auto const t = dynamics.time();
258+
CHECK_EQ(dynamics.strDateTime(),
259+
std::format("{:%Y-%m-%d %H:%M:%S}", *std::localtime(&t)));
260+
}
261+
#else
247262
CHECK_EQ(
248263
dynamics.strDateTime(),
249264
std::format(
250265
"{:%Y-%m-%d %H:%M:%S}",
251266
std::chrono::floor<std::chrono::seconds>(
252267
std::chrono::current_zone()->to_local(
253268
std::chrono::system_clock::from_time_t(dynamics.time())))));
269+
#endif
254270
}
255271
}
256272
}

0 commit comments

Comments
 (0)