diff --git a/include/jwt-cpp/jwt.h b/include/jwt-cpp/jwt.h index a31d913..428163b 100644 --- a/include/jwt-cpp/jwt.h +++ b/include/jwt-cpp/jwt.h @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -2253,11 +2254,18 @@ namespace jwt { typename json_traits::string_type as_string() const { return json_traits::as_string(val); } /** - * Get the contained JSON value as a date + * \brief Get the contained JSON value as a date + * + * If the value is a decimal, it is rounded up to the closest integer + * * \return content as date * \throw std::bad_cast Content was not a date */ - date as_date() const { return std::chrono::system_clock::from_time_t(as_int()); } + date as_date() const { + using std::chrono::system_clock; + if (get_type() == json::type::number) return system_clock::from_time_t(std::round(as_number())); + return system_clock::from_time_t(as_int()); + } /** * Get the contained JSON value as an array