Skip to content

Commit fd29103

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

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/dsf/headers/Dynamics.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
#include <filesystem>
3030
#include <functional>
3131
#include <iomanip>
32+
#ifdef __APPLE__
33+
#include <sstream>
34+
#endif
3235

3336
#include <tbb/tbb.h>
3437

@@ -97,9 +100,17 @@ namespace dsf {
97100
/// @brief Get the current simulation time as formatted string (YYYY-MM-DD HH:MM:SS)
98101
/// @return std::string, The current simulation time as formatted string
99102
inline auto strDateTime() const {
103+
#ifdef __APPLE__
104+
std::time_t const t = time();
105+
std::ostringstream oss;
106+
oss << std::put_time(std::localtime(&t), "%Y-%m-%d %H:%M:%S");
107+
return oss.str();
108+
#else
100109
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()))));
110+
"{:%Y-%m-%d %H:%M:%S}",
111+
std::chrono::floor<std::chrono::seconds>(std::chrono::current_zone()->to_local(
112+
std::chrono::system_clock::from_time_t(time()))));
113+
#endif
103114
}
104115
};
105116

test/Test_dynamics.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,20 @@ 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+
std::ostringstream oss;
232+
oss << std::put_time(std::localtime(&t), "%Y-%m-%d %H:%M:%S");
233+
CHECK_EQ(dynamics.strDateTime(), oss.str());
234+
}
235+
#else
228236
CHECK_EQ(dynamics.strDateTime(),
229237
std::format("{:%Y-%m-%d %H:%M:%S}",
230238
std::chrono::floor<std::chrono::seconds>(
231239
std::chrono::current_zone()->to_local(
232240
std::chrono::system_clock::from_time_t(0)))));
241+
#endif
233242
auto const epochStart{
234243
std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())};
235244
dynamics.setInitTime(epochStart);
@@ -244,13 +253,22 @@ TEST_CASE("FirstOrderDynamics") {
244253
CHECK(dynamics.nAgents() < n);
245254
CHECK_EQ(dynamics.time_step(), 40);
246255
CHECK_EQ(dynamics.time() - epochStart, 40);
256+
#ifdef __APPLE__
257+
{
258+
std::time_t const t = dynamics.time();
259+
std::ostringstream oss;
260+
oss << std::put_time(std::localtime(&t), "%Y-%m-%d %H:%M:%S");
261+
CHECK_EQ(dynamics.strDateTime(), oss.str());
262+
}
263+
#else
247264
CHECK_EQ(
248265
dynamics.strDateTime(),
249266
std::format(
250267
"{:%Y-%m-%d %H:%M:%S}",
251268
std::chrono::floor<std::chrono::seconds>(
252269
std::chrono::current_zone()->to_local(
253270
std::chrono::system_clock::from_time_t(dynamics.time())))));
271+
#endif
254272
}
255273
}
256274
}

0 commit comments

Comments
 (0)