File tree Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Expand file tree Collapse file tree 1 file changed +10
-2
lines changed Original file line number Diff line number Diff line change 23
23
24
24
#include < algorithm>
25
25
#include < chrono>
26
+ #include < cmath>
26
27
#include < codecvt>
27
28
#include < functional>
28
29
#include < iterator>
@@ -2253,11 +2254,18 @@ namespace jwt {
2253
2254
typename json_traits::string_type as_string () const { return json_traits::as_string (val); }
2254
2255
2255
2256
/* *
2256
- * Get the contained JSON value as a date
2257
+ * \brief Get the contained JSON value as a date
2258
+ *
2259
+ * If the value is a decimal, it is rounded up to the closest integer
2260
+ *
2257
2261
* \return content as date
2258
2262
* \throw std::bad_cast Content was not a date
2259
2263
*/
2260
- date as_date () const { return std::chrono::system_clock::from_time_t (as_int ()); }
2264
+ date as_date () const {
2265
+ using std::chrono::system_clock;
2266
+ if (get_type () == json::type::number) return system_clock::from_time_t (std::round (as_number ()));
2267
+ return system_clock::from_time_t (as_int ());
2268
+ }
2261
2269
2262
2270
/* *
2263
2271
* Get the contained JSON value as an array
You can’t perform that action at this time.
0 commit comments