File tree Expand file tree Collapse file tree 3 files changed +10
-8
lines changed
Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -17,7 +17,9 @@ include(${CMAKE_BINARY_DIR}/conan.cmake)
1717conan_cmake_configure(REQUIRES boost/1.76.0
1818 REQUIRES gtest/1.11.0
1919 REQUIRES nlohmann_json/3.9.1
20+ REQUIRES date/3.0.1
2021 OPTIONS boost:header_only=True
22+ OPTIONS date:header_only=True
2123 GENERATORS cmake_find_package)
2224
2325conan_cmake_autodetect(settings)
Original file line number Diff line number Diff line change @@ -15,3 +15,6 @@ find_package(Threads REQUIRED)
1515target_link_libraries (rest PRIVATE Threads::Threads)
1616
1717target_link_libraries (rest PUBLIC controller)
18+
19+ find_package (date REQUIRED)
20+ target_link_libraries (rest PUBLIC date::date)
Original file line number Diff line number Diff line change 11#ifndef DEVELOPER_JOYOFENERGY_CPP_BEAST_METERREADINGCONTROLLER_H
22#define DEVELOPER_JOYOFENERGY_CPP_BEAST_METERREADINGCONTROLLER_H
33
4+ #include < date/date.h>
45#include < service/ElectricityReadingService.h>
56#include < service/MeterReadingService.h>
67
@@ -16,17 +17,13 @@ namespace http = boost::beast::http;
1617
1718namespace detail {
1819auto toRfc3339 (std::chrono::time_point<std::chrono::system_clock> time) {
19- std::stringstream ss;
20- const auto ctime = std::chrono::system_clock::to_time_t (time);
21- ss << std::put_time (std::gmtime (&ctime), " %FT%T" );
22- return ss.str ();
20+ return date::format (" %FT%TZ" , time);
2321}
2422
2523auto fromRfc3339 (const std::string &time) {
26- std::tm tm = {};
27- std::stringstream ss (time);
28- ss >> std::get_time (&tm, " %Y-%m-%dT%H:%M:%S" );
29- auto tp = std::chrono::system_clock::from_time_t (std::mktime (&tm));
24+ std::chrono::time_point<std::chrono::system_clock> tp;
25+ std::istringstream ss (time);
26+ ss >> date::parse (" %FT%TZ" , tp);
3027 return tp;
3128}
3229
You can’t perform that action at this time.
0 commit comments