Subject: [Boost-bugs] [Boost C++ Libraries] #11813: Microseconds get cut off in ISO string representation if all zero (posix_time::to_iso_string)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2015-11-21 14:33:17
#11813: Microseconds get cut off in ISO string representation if all zero
(posix_time::to_iso_string)
-------------------------------------+-------------------------------------
Reporter: Marcel Glacki <boost- | Type: Bugs
trac@â¦> | Milestone: To Be Determined
Status: new | Version: Boost 1.55.0
Component: None | Keywords: posix_time microseconds
Severity: Problem | to_iso_string
-------------------------------------+-------------------------------------
{{{
#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[[BR]]
''Timestamp: 20151121T141523.000000''[[BR]]
but actually is[[BR]]
''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.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/11813> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:19 UTC