Opened 7 years ago
Last modified 7 years ago
#11813 new Bugs
Microseconds get cut off in ISO string representation if all zero (posix_time::to_iso_string)
Reported by: | Owned by: | az_sw_dude | |
---|---|---|---|
Milestone: | To Be Determined | Component: | date_time |
Version: | Boost 1.55.0 | Severity: | Problem |
Keywords: | posix_time microseconds to_iso_string | Cc: |
Description
#include <iostream> #include <string> #include <boost/date_time/posix_time/posix_time.hpp> int main() { boost::posix_time::ptime timestamp = boost::posix_time::microsec_clock::local_time(); std::string sTime( boost::posix_time::to_iso_string( timestamp )); std::cout << "Timestamp: " << sTime << std::endl; return 0; }
This outputs for example: Timestamp: 20151121T141522.999982
Now, if microseconds are all zero the output I'd expected was
Timestamp: 20151121T141523.000000
but actually is
Timestamp: 20151121T141523
Now, when trying to cut off the microseconds fraction (for whatever reason) by doing
std::string sFraction = sTime.substr( 16, 21 );
you may end up with the following error:
Something unexpected happened: 'basic_string::substr: __pos (which is 16) > this->size() (which is 15)'
I saw this behavior in Boost 1.55.0, but when I checked the current sources online, I couldn't see any difference, so I think this would occur in the current version, too.
Note:
See TracTickets
for help on using tickets.