[Boost-bugs] [Boost C++ Libraries] #7715: Fractional seconds are parsed as timezone

Subject: [Boost-bugs] [Boost C++ Libraries] #7715: Fractional seconds are parsed as timezone
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-11-20 08:25:53


#7715: Fractional seconds are parsed as timezone
-------------------------------------------------------------------+--------
 Reporter: knight666@… | Owner: az_sw_dude
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: date_time
  Version: Boost 1.52.0 | Severity: Problem
 Keywords: date_time, timezone, fractional seconds, facet, flags |
-------------------------------------------------------------------+--------
 We're trying to use Boost's excellent date time functionality, but we've
 hit a snag. The formatting we require is "%Y-%m-%dT%H:%M:%S.%F%ZP", which
 results in for example "2012-11-19T23:44:23.122344UTC+1". We use this to
 store dates and time in our database as a string.

 The problem seems to be that the %F and %ZP flags don't work well
 together. The following code generates an exception:

 {{{
 std::string serialized = "2012-11-19T23:44:23.122344UTC+1";
 std::stringstream ss(serialized);

 std::string format = "%Y-%m-%dT%H:%M:%S.%F%ZP";

 boost::local_time::local_time_facet* facet_output = new
 boost::local_time::local_time_facet();
 facet_output->format(format.c_str());
 ss.imbue(std::locale(std::locale::classic(), facet_output));

 boost::local_time::local_time_input_facet* facet_input = new
 boost::local_time::local_time_input_facet();
 facet_input->format(format.c_str());
 ss.imbue(std::locale(ss.getloc(), facet_input));

 boost::local_time::local_date_time
 result(boost::local_time::not_a_date_time);

 ss >> result; // exception
 }}}

 What happens when you trace the stack to the exception is that the
 tokenizer doesn't see the "122344" bit as fractional seconds and instead
 thinks it's the timezone. This results in an invalid timezone and thus an
 exception.

 We can circumvent the problem by removing the %F flag, but that is an
 unacceptable workaround, because we need the precision of the fractional
 seconds. Removing the %F flag solves the problem.

 The problem was found in 1.48.0, but has not yet been fixed in 1.52.0.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/7715>
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:11 UTC