From 85574ff08add4562ee7cee9e0719e4672f33f0fe Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Mon, 26 Sep 2022 10:14:57 +0200 Subject: [PATCH] replace boost date_time with chrono --- .vscode/launch.json | 3 ++- src/core/CMakeLists.txt | 6 +++--- src/core/database.cpp | 13 ++++++++----- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 17dfcc6..fb0e8c6 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -21,7 +21,8 @@ "text": "-enable-pretty-printing", "ignoreFailures": true } - ] + ], + "visualizerFile": "/home/brodbemn/.config/Code - OSS/User/workspaceStorage/d64ec049841ecb3d43e402bb3c167cb5/tonka3000.qtvsctools/qt.natvis.xml" } ] } \ No newline at end of file diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index dac5c00..90b6fbc 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -1,6 +1,6 @@ set(Boost_USE_STATIC_LIBS ON) -find_package(Boost 1.62 COMPONENTS date_time REQUIRED) +find_package(Boost 1.62 REQUIRED) find_package(SQLite3 REQUIRED) # Because csv-parser needs threads: @@ -36,10 +36,10 @@ set(CORE_SOURCES add_library(core STATIC ${CORE_SOURCES}) target_include_directories(core PRIVATE ${PROJECT_SOURCE_DIR}/subprojects/csv-parser/single_include) if (WIN32) - target_link_libraries(core PRIVATE Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARY} Threads::Threads fmt::fmt) + target_link_libraries(core PRIVATE sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARY} Threads::Threads fmt::fmt) target_link_libraries(core PRIVATE bcrypt) else() - target_link_libraries(core PRIVATE Boost::boost Boost::date_time sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARIES} Threads::Threads fmt::fmt) + target_link_libraries(core PRIVATE sqlite3 nlohmann_json::nlohmann_json ${XLNT_LIBRARIES} Threads::Threads fmt::fmt) endif() target_include_directories(core PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/src/core/database.cpp b/src/core/database.cpp index f9ba43e..7a5095d 100644 --- a/src/core/database.cpp +++ b/src/core/database.cpp @@ -1,12 +1,12 @@ #include "database.h" +#include #include +#include #include #include #include -#include "boost/date_time/posix_time/posix_time.hpp" - Database::Database(const std::string &dbname) { dbname_ = dbname; @@ -45,8 +45,11 @@ void Database::newDb() fs::path sourcePath = dbname_; fs::path destPath = sourcePath.parent_path() / sourcePath.stem(); - destPath += std::string("_") += - boost::posix_time::to_iso_string(boost::posix_time::second_clock::local_time()) += ".db"; + + auto chronoTime = std::chrono::system_clock::now(); + std::string timeString = fmt::format("{0:%F}T{0:%T}", chronoTime); + + destPath += std::string("_") += timeString += ".db"; fs::copy_file(sourcePath, destPath, fs::copy_options::overwrite_existing); @@ -63,7 +66,7 @@ void Database::exec(const std::string &sql) const int errCode = sqlite3_exec(db_, sql.c_str(), nullptr, nullptr, &errMsg); if (errCode) { std::string errMsgString(errMsg); // Make a C++ string of the errMsg, so that we can call - // sqlite3_free() before throwing the exception + // sqlite3_free() before throwing the exception sqlite3_free(errMsg); throw std::runtime_error("Error in SQL execution: " + errMsgString); }