From 36c69bbc2e7cf3625cb2816fddaa1f4a85a85a3a Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Sun, 26 Feb 2023 22:44:15 +0100 Subject: [PATCH] main: use ctime put_time to replace date/date.h include Implementation referenced from: https://stackoverflow.com/questions/17223096/outputting-date-and-time-in-c-using-stdchrono Fixes: https://github.com/InfiniTimeOrg/InfiniSim/issues/88 --- CMakeLists.txt | 9 --------- main.cpp | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a296b5a..cf00821 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -148,15 +148,6 @@ target_sources(infinisim PUBLIC ) target_link_libraries(infinisim PUBLIC sim-base) -# add dates library -if(EXISTS "${InfiniTime_DIR}/src/libs/date/includes") - target_include_directories(infinisim SYSTEM PRIVATE "${InfiniTime_DIR}/src/libs/date/includes") -elseif(EXISTS "${InfiniTime_DIR}/src/libs/date/include") - target_include_directories(infinisim SYSTEM PRIVATE "${InfiniTime_DIR}/src/libs/date/include") -else() - message(FATAL_ERROR "can't find date includes/include directory, is the submodule checked out?") -endif() - # add Screens, fonts and icons with a globbing expression, # to enable easier CI test-runs for PRs adding new Screens/Fonts/Icons file(GLOB InfiniTime_SCREENS diff --git a/main.cpp b/main.cpp index 7f19459..f4d1fe1 100644 --- a/main.cpp +++ b/main.cpp @@ -63,8 +63,10 @@ #include // std::pow // additional includes for 'saveScreenshot()' function -#include +#include // put_time +#include #include +#include // localtime #if defined(WITH_PNG) #include #endif @@ -97,8 +99,13 @@ extern monitor_t monitor; void saveScreenshot() { auto now = std::chrono::system_clock::now(); - // TODO: timestamped png filename - std::string screenshot_filename_base = date::format("InfiniSim_%F_%H%M%S", date::floor(now)); + auto in_time_t = std::chrono::system_clock::to_time_t(now); + // timestamped png filename + std::stringstream ss; + ss << "InfiniSim_" << std::put_time(std::localtime(&in_time_t), "%F_%H%M%S"); + std::string screenshot_filename_base = ss.str(); + // TODO: use std::format once we have C++20 and new enough GCC 13 + //std::string screenshot_filename_base = std::format("InfiniSim_%F_%H%M%S", std::chrono::floor(now)); //std::string screenshot_filename_base = "InfiniSim"; const int width = 240; @@ -198,7 +205,13 @@ public: { assert(!in_progress); auto now = std::chrono::system_clock::now(); - std::string screenshot_filename_base = date::format("InfiniSim_%F_%H%M%S", date::floor(now)); + auto in_time_t = std::chrono::system_clock::to_time_t(now); + // timestamped png filename + std::stringstream ss; + ss << "InfiniSim_" << std::put_time(std::localtime(&in_time_t), "%F_%H%M%S"); + std::string screenshot_filename_base = ss.str(); + // TODO: use std::format once we have C++20 and new enough GCC 13 + //std::string screenshot_filename_base = std::format("InfiniSim_%F_%H%M%S", std::chrono::floor(now)); std::string screenshot_filename = screenshot_filename_base + ".gif"; std::cout << "InfiniSim: Screen-capture started: " << screenshot_filename << std::endl; GifBegin( &writer, screenshot_filename.c_str(), sdl_width, sdl_height, delay_ds, 8, true );