Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84967 - in trunk: boost/chrono/io libs/chrono/test
From: vicente.botet_at_[hidden]
Date: 2013-07-07 07:37:28


Author: viboes
Date: 2013-07-07 07:37:27 EDT (Sun, 07 Jul 2013)
New Revision: 84967
URL: http://svn.boost.org/trac/boost/changeset/84967

Log:
Chrono: Complete #7868.

Added:
   trunk/libs/chrono/test/test_7868.cpp (contents, props changed)
Text files modified:
   trunk/boost/chrono/io/time_point_io.hpp | 6 +-
   trunk/libs/chrono/test/Jamfile.v2 | 3 +
   trunk/libs/chrono/test/test_7868.cpp | 69 ++++++++++++++++++++++++++++++++++++++++
   3 files changed, 74 insertions(+), 4 deletions(-)

Modified: trunk/boost/chrono/io/time_point_io.hpp
==============================================================================
--- trunk/boost/chrono/io/time_point_io.hpp Sun Jul 7 06:43:20 2013 (r84966)
+++ trunk/boost/chrono/io/time_point_io.hpp 2013-07-07 07:37:27 EDT (Sun, 07 Jul 2013) (r84967)
@@ -255,9 +255,9 @@
 // b = that_.get(b, e, iob, err, tm, fm, fm + sizeof(fm)/sizeof(fm[0]));
 // }
 // break;
-// case 'S':
-// that_.get_second(tm->tm_sec, b, e, err, ct);
-// break;
+ case 'S':
+ get_second(tm->tm_sec, b, e, err, ct);
+ break;
 // case 'T':
 // {
 // const char_type fm[] = {'%', 'H', ':', '%', 'M', ':', '%', 'S'};

Modified: trunk/libs/chrono/test/Jamfile.v2
==============================================================================
--- trunk/libs/chrono/test/Jamfile.v2 Sun Jul 7 06:43:20 2013 (r84966)
+++ trunk/libs/chrono/test/Jamfile.v2 2013-07-07 07:37:27 EDT (Sun, 07 Jul 2013) (r84967)
@@ -507,6 +507,7 @@
         [ chrono-v1-v2-run-header io/duration_output.cpp ]
         [ chrono-v1-v2-run-header io/time_point_input.cpp ]
         [ chrono-v1-v2-run-header io/time_point_output.cpp ]
+ [ chrono-run test_7868.cpp ]
         ;
 
     test-suite "win32"
@@ -517,6 +518,6 @@
     explicit ts_ ;
     test-suite ts_
         :
- #[ chrono-run test_xx.cpp ]
+ #[ chrono-run test_7868.cpp ]
         ;
 

Added: trunk/libs/chrono/test/test_7868.cpp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ trunk/libs/chrono/test/test_7868.cpp 2013-07-07 07:37:27 EDT (Sun, 07 Jul 2013) (r84967)
@@ -0,0 +1,69 @@
+#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>
+#include <boost/detail/lightweight_test.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;
+ BOOST_TEST_EQ(atnow.time_since_epoch().count(), atnow2.time_since_epoch().count());
+
+ // 1 sec wrong:
+ std::cout << "diff:" << boost::chrono::duration_cast<microseconds>(atnow2 - atnow).count() <<std::endl;
+ BOOST_TEST_EQ(boost::chrono::duration_cast<microseconds>(atnow2 - atnow).count(), 0);
+ 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 formatted1;
+ formatted1 << time_fmt(boost::chrono::timezone::utc, "%Y-%m-%d %H:%M:%S");
+ formatted1 << atnow ;
+ std::stringstream formatted2;
+ formatted2 << time_fmt(boost::chrono::timezone::utc, "%Y-%m-%d %H:%M:%S");
+ formatted2 << atnow2 ;
+ BOOST_TEST_EQ(formatted1.str(), formatted2.str());
+
+
+ }
+
+ {
+ std::cout << "FORMATTED" << std::endl;
+ 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;
+ //BOOST_TEST_EQ(atnow, atnow2); // fails because the pattern doesn't contains nanoseconds
+ //BOOST_TEST_EQ(atnow.time_since_epoch().count(), atnow2.time_since_epoch().count()); // fails because the pattern doesn't contains nanoseconds
+ BOOST_TEST_EQ(boost::chrono::duration_cast<seconds>(atnow2 - atnow).count(), 0);
+
+ }
+ return boost::report_errors();
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk