[Boost-bugs] [Boost C++ Libraries] #7868: chrono_io parses time incorrectly (1.53 and 1.52)

Subject: [Boost-bugs] [Boost C++ Libraries] #7868: chrono_io parses time incorrectly (1.53 and 1.52)
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-01-08 13:48:30


#7868: chrono_io parses time incorrectly (1.53 and 1.52)
-------------------------------------------------+--------------------------
 Reporter: Johan Lundberg <lundberj@…> | Owner: viboes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: chrono
  Version: Boost 1.52.0 | Severity: Regression
 Keywords: |
-------------------------------------------------+--------------------------
 streaming the result of
   boost::chrono::system_clock::now()
 into a stringstream, and back to a
   boost::chrono::system_clock::time_point
 gives wrong results.


 With boost 1.52 the error is exactly one second (when using the default
 formats)

 With boost 1.53 beta (of today) the parsed times are semi-random around
 1974.

 With user-defined formats the error behaves a little differently:

 In my example (attached) the time is correct up to the seconds, which are
 always parsed as 01 both with boost 1.52 and 1.53.

       cheers, Johan Lundberg

 -------------
 Full example:

 {{{

 #define BOOST_CHRONO_VERSION 2
 #define BOOST_CHRONO_PROVIDES_DATE_IO_FOR_SYSTEM_CLOCK_TIME_POINT 1

 #include <sstream>
 #include <iostream>
 #include <boost/chrono/chrono_io.hpp>
 #include <boost/chrono/floor.hpp>
 #include <boost/chrono/round.hpp>
 #include <boost/chrono/ceil.hpp>

 int main()
 {
   using namespace boost;
   using namespace boost::chrono;
   boost::chrono::system_clock::time_point atnow=
 boost::chrono::system_clock::now();
   {
       std::stringstream strm;
       std::stringstream strm2;
       // does not change anything:
 strm<<time_fmt(boost::chrono::timezone::utc);
       // does not change anything:
 strm2<<time_fmt(boost::chrono::timezone::utc);
       boost::chrono::system_clock::time_point atnow2;
       strm<<atnow<<std::endl;
       std::cout << "A:" << strm.str()<< std::endl;
       strm>>atnow2;
       strm2<<atnow2<<std::endl;
       std::cout << "B:" << strm2.str()<< std::endl;

       // 1 sec wrong:
       std::cout << "diff:" <<
 boost::chrono::duration_cast<microseconds>(atnow2 - atnow).count()
 <<std::endl;
       std::stringstream formatted;
       formatted << time_fmt(boost::chrono::timezone::utc, "%Y-%m-%d
 %H:%M:%S");
       formatted << "actual:"<< atnow <<std::endl;;
       formatted << "parsed:"<< atnow2 <<std::endl;;
       std::cout << formatted.str();
   }

   {
       std::stringstream strm;
       std::stringstream strm2;
       boost::chrono::system_clock::time_point atnow2;
       // the final second mark is always parsed as 01
       strm<<time_fmt(boost::chrono::timezone::utc, "%Y-%m-%d %H:%M:%S");
       strm2<<time_fmt(boost::chrono::timezone::utc, "%Y-%m-%d %H:%M:%S");
       strm<<atnow<<std::endl;
       std::cout << "actual:" << strm.str()<< std::endl;
       strm>>atnow2;
       strm2<<atnow2<<std::endl;
       // the final second mark is always parsed as 01
       std::cout << "parsed:" << strm2.str()<< std::endl;
   }
 }
 }}}


 --------------------------------------------
 Details:

 Compiled boost with gcc4.7.2 on Linux. I tried compiling boost both with
 and without cxxflags=-std=gnu++11, same result.

 I also tried compiling my example with and without -std=c++11

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