boostorg / date_time

Boost.org date_time module
http://boost.org/libs/date_time
Boost Software License 1.0
67 stars 95 forks source link

Error handling in boost::posix_time::from_iso_extended_string() #187

Closed elenaepstein66 closed 3 years ago

elenaepstein66 commented 3 years ago

If invalid ISO date is provided as the argument (e.g. "2021-04-21”) the exception thrown is basic_string::at: __n (which is 0) >= this->size() (which is 0)

JeffGarland commented 3 years ago

I have a patch for this case that pre-checks the string size so if it's only a date the ptime will be constructed only from the date string -- so basically defaulting to :00:00:00. I added a test and confirmed that a completely broken string like 2021-1 now provides a date_time exception (derived from std::exception) instead of a string exception -- specifically in that case of 2021-1 it is "Day of month value is out of range 1..31".