replace boost date_time with chrono

This commit is contained in:
Martin Brodbeck 2022-09-26 10:14:57 +02:00
parent c44d8b352a
commit 85574ff08a
3 changed files with 13 additions and 9 deletions

3
.vscode/launch.json vendored
View File

@ -21,7 +21,8 @@
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
],
"visualizerFile": "/home/brodbemn/.config/Code - OSS/User/workspaceStorage/d64ec049841ecb3d43e402bb3c167cb5/tonka3000.qtvsctools/qt.natvis.xml"
}
]
}

View File

@ -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}/..)

View File

@ -1,12 +1,12 @@
#include "database.h"
#include <chrono>
#include <filesystem>
#include <fmt/chrono.h>
#include <iostream>
#include <stdexcept>
#include <vector>
#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);
}