refactor(eventsub): conditionally use Howard's date lib (#6048)
Co-authored-by: Nerixyz <nerixdev@outlook.de>
This commit is contained in:
@@ -48,8 +48,12 @@ add_library(${PROJECT_NAME} STATIC ${SOURCE_FILES})
|
||||
# Generate source groups for use in IDEs
|
||||
# source_group(TREE ${CMAKE_SOURCE_DIR} FILES ${SOURCE_FILES})
|
||||
|
||||
target_include_directories(${PROJECT_NAME} PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/../include")
|
||||
|
||||
target_include_directories(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../include"
|
||||
PRIVATE
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/../lib/date/include"
|
||||
)
|
||||
|
||||
target_link_libraries(${PROJECT_NAME}
|
||||
PUBLIC
|
||||
|
||||
@@ -1,16 +1,22 @@
|
||||
#include "twitch-eventsub-ws/chrono.hpp"
|
||||
|
||||
#include "twitch-eventsub-ws/date.h"
|
||||
#include "twitch-eventsub-ws/detail/errors.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#if __cpp_lib_chrono >= 201907L
|
||||
# include <chrono>
|
||||
using namespace std::chrono;
|
||||
#else
|
||||
# include <date/date.h>
|
||||
using namespace date;
|
||||
#endif
|
||||
|
||||
namespace chatterino::eventsub::lib {
|
||||
|
||||
boost::json::result_for<std::chrono::system_clock::time_point,
|
||||
boost::json::value>::type
|
||||
tag_invoke(
|
||||
boost::json::try_value_to_tag<std::chrono::system_clock::time_point>,
|
||||
const boost::json::value &jvRoot, const AsISO8601 &)
|
||||
tag_invoke(boost::json::try_value_to_tag<
|
||||
std::chrono::system_clock::time_point> /*tag*/,
|
||||
const boost::json::value &jvRoot, const AsISO8601 & /*tag*/)
|
||||
{
|
||||
const auto raw = boost::json::try_value_to<std::string>(jvRoot);
|
||||
if (raw.has_error())
|
||||
@@ -18,10 +24,18 @@ boost::json::result_for<std::chrono::system_clock::time_point,
|
||||
return raw.error();
|
||||
}
|
||||
|
||||
std::chrono::system_clock::time_point tp;
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>
|
||||
tp;
|
||||
std::istringstream in{*raw};
|
||||
in >> date::parse("%FT%H:%M:%12SZ", tp);
|
||||
in >> parse("%FT%H:%M:%12SZ", tp);
|
||||
|
||||
return tp;
|
||||
if (!in.good())
|
||||
{
|
||||
EVENTSUB_BAIL_HERE(error::Kind::BadTimeFormat);
|
||||
}
|
||||
|
||||
return std::chrono::time_point_cast<std::chrono::system_clock::duration>(
|
||||
tp);
|
||||
}
|
||||
|
||||
} // namespace chatterino::eventsub::lib
|
||||
|
||||
@@ -27,6 +27,8 @@ std::string ApplicationErrorCategory::message(int ev) const
|
||||
return "No message handler found"s;
|
||||
case Kind::UnknownVariant:
|
||||
return "Unknown variant value"s;
|
||||
case Kind::BadTimeFormat:
|
||||
return "Bad time format"s;
|
||||
}
|
||||
|
||||
assert(false);
|
||||
|
||||
Reference in New Issue
Block a user