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
This commit is contained in:
parent
f457925952
commit
36c69bbc2e
2 changed files with 17 additions and 13 deletions
|
@ -148,15 +148,6 @@ target_sources(infinisim PUBLIC
|
||||||
)
|
)
|
||||||
target_link_libraries(infinisim PUBLIC sim-base)
|
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,
|
# add Screens, fonts and icons with a globbing expression,
|
||||||
# to enable easier CI test-runs for PRs adding new Screens/Fonts/Icons
|
# to enable easier CI test-runs for PRs adding new Screens/Fonts/Icons
|
||||||
file(GLOB InfiniTime_SCREENS
|
file(GLOB InfiniTime_SCREENS
|
||||||
|
|
21
main.cpp
21
main.cpp
|
@ -63,8 +63,10 @@
|
||||||
#include <cmath> // std::pow
|
#include <cmath> // std::pow
|
||||||
|
|
||||||
// additional includes for 'saveScreenshot()' function
|
// additional includes for 'saveScreenshot()' function
|
||||||
#include <date/date.h>
|
#include <iomanip> // put_time
|
||||||
|
#include <sstream>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
#include <ctime> // localtime
|
||||||
#if defined(WITH_PNG)
|
#if defined(WITH_PNG)
|
||||||
#include <libpng/png.h>
|
#include <libpng/png.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -97,8 +99,13 @@ extern monitor_t monitor;
|
||||||
void saveScreenshot()
|
void saveScreenshot()
|
||||||
{
|
{
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
// TODO: timestamped png filename
|
auto in_time_t = std::chrono::system_clock::to_time_t(now);
|
||||||
std::string screenshot_filename_base = date::format("InfiniSim_%F_%H%M%S", date::floor<std::chrono::seconds>(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<std::chrono::seconds>(now));
|
||||||
//std::string screenshot_filename_base = "InfiniSim";
|
//std::string screenshot_filename_base = "InfiniSim";
|
||||||
|
|
||||||
const int width = 240;
|
const int width = 240;
|
||||||
|
@ -198,7 +205,13 @@ public:
|
||||||
{
|
{
|
||||||
assert(!in_progress);
|
assert(!in_progress);
|
||||||
auto now = std::chrono::system_clock::now();
|
auto now = std::chrono::system_clock::now();
|
||||||
std::string screenshot_filename_base = date::format("InfiniSim_%F_%H%M%S", date::floor<std::chrono::seconds>(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<std::chrono::seconds>(now));
|
||||||
std::string screenshot_filename = screenshot_filename_base + ".gif";
|
std::string screenshot_filename = screenshot_filename_base + ".gif";
|
||||||
std::cout << "InfiniSim: Screen-capture started: " << screenshot_filename << std::endl;
|
std::cout << "InfiniSim: Screen-capture started: " << screenshot_filename << std::endl;
|
||||||
GifBegin( &writer, screenshot_filename.c_str(), sdl_width, sdl_height, delay_ds, 8, true );
|
GifBegin( &writer, screenshot_filename.c_str(), sdl_width, sdl_height, delay_ds, 8, true );
|
||||||
|
|
Loading…
Reference in a new issue