Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86376 - in trunk/boost/chrono: detail/inlined/win io
From: vicente.botet_at_[hidden]
Date: 2013-10-20 14:27:56


Author: viboes
Date: 2013-10-20 14:27:56 EDT (Sun, 20 Oct 2013)
New Revision: 86376
URL: http://svn.boost.org/trac/boost/changeset/86376

Log:
Chrono: fix two important issues with Boost.Chrono IO v2 on windows
* now() returned 1 day later.
* make use of system_clock::duration instead of microseconds in time_point_io input rounding

Text files modified:
   trunk/boost/chrono/detail/inlined/win/chrono.hpp | 10 +++++++---
   trunk/boost/chrono/io/time_point_io.hpp | 25 ++++++++++++-------------
   2 files changed, 19 insertions(+), 16 deletions(-)

Modified: trunk/boost/chrono/detail/inlined/win/chrono.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/win/chrono.hpp Sun Oct 20 14:10:12 2013 (r86375)
+++ trunk/boost/chrono/detail/inlined/win/chrono.hpp 2013-10-20 14:27:56 EDT (Sun, 20 Oct 2013) (r86376)
@@ -94,7 +94,8 @@
     return system_clock::time_point(
       system_clock::duration(
         ((static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime)
- -116444736000000000LL
+ //- 116444736000000000LL
+ - (134775LL*864000000000LL)
       )
     );
   }
@@ -109,8 +110,11 @@
     {
         ec.clear();
     }
- return time_point(duration(
- (static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime));
+ return system_clock::time_point(
+ system_clock::duration(
+ ((static_cast<__int64>( ft.dwHighDateTime ) << 32) | ft.dwLowDateTime)
+ - (134775LL*864000000000LL)
+ ));
   }
 #endif
 

Modified: trunk/boost/chrono/io/time_point_io.hpp
==============================================================================
--- trunk/boost/chrono/io/time_point_io.hpp Sun Oct 20 14:10:12 2013 (r86375)
+++ trunk/boost/chrono/io/time_point_io.hpp 2013-10-20 14:27:56 EDT (Sun, 20 Oct 2013) (r86376)
@@ -46,9 +46,11 @@
 {
   namespace chrono
   {
+ typedef double fractional_seconds;
     namespace detail
     {
 
+
       template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
       struct time_get
       {
@@ -760,6 +762,7 @@
         { 0,31,59,90,120,151,181,212,243,273,304,334},
         { 0,31,60,91,121,152,182,213,244,274,305,335}
       };
+
       return days[is_leap(year)][month-1] + day - 1;
     }
 
@@ -781,7 +784,7 @@
       month++;
       int day = t->tm_mday;
       int day_of_year = days_from_1jan(year,month,day);
- int days_since_epoch = days_from_1970(year) + day_of_year;
+ int days_since_epoch = days_from_1970(year) + day_of_year ;
 
       time_t seconds_in_day = 3600 * 24;
       time_t result = seconds_in_day * days_since_epoch + 3600 * t->tm_hour + 60 * t->tm_min + t->tm_sec;
@@ -846,10 +849,9 @@
        //y -= 32767 + 2;
        y += 70;
        tm->tm_year=y;
- const bool leap = is_leap(y);
+ const bool leap = (is_leap(y)==1);
        tm->tm_mon = day_of_year_month[leap][doy]-1;
- tm->tm_mday = doy - days_in_year_before[leap][day_of_year_month[leap][doy] - 1];
-
+ tm->tm_mday = doy - days_in_year_before[leap][tm->tm_mon] ;
 
      tm->tm_hour = hms / 3600;
      const int ms = hms % 3600;
@@ -925,7 +927,7 @@
               failed = tpf.put(os, os, os.fill(), &tm, pb, pe).failed();
               if (!failed)
               {
- duration<double> d = tp - system_clock::from_time_t(t) + seconds(tm.tm_sec);
+ duration<fractional_seconds> d = tp - system_clock::from_time_t(t) + seconds(tm.tm_sec);
                 if (d.count() < 10) os << CharT('0');
                 //if (! os.good()) {
                 // throw "exception";
@@ -1061,12 +1063,8 @@
           const std::time_get<CharT>& tg = std::use_facet<std::time_get<CharT> >(loc);
           const std::ctype<CharT>& ct = std::use_facet<std::ctype<CharT> >(loc);
           tm tm; // {0}
- tm.tm_year=0;
- tm.tm_mon=0;
- tm.tm_mday=0;
- tm.tm_hour=0;
- tm.tm_min=0;
- tm.tm_sec=0;
+ std::memset(&tm, 0, sizeof(std::tm));
+
           typedef std::istreambuf_iterator<CharT, Traits> It;
           if (pb == pe)
           {
@@ -1082,7 +1080,7 @@
             tg.get(is, 0, is, err, &tm, pb, pe);
 #endif
             if (err & std::ios_base::failbit) goto exit;
- double sec;
+ fractional_seconds sec;
             CharT c = CharT();
             is >> sec;
             if (is.fail())
@@ -1102,13 +1100,14 @@
 
             if (err & std::ios_base::failbit) goto exit;
             time_t t;
+
 #if BOOST_CHRONO_INTERNAL_TIMEGM
             t = detail::internal_timegm(&tm);
 #else
             t = timegm(&tm);
 #endif
             tp = time_point_cast<Duration>(
- system_clock::from_time_t(t) - min + round<microseconds> (duration<double> (sec))
+ system_clock::from_time_t(t) - min + round<system_clock::duration> (duration<fractional_seconds> (sec))
                 );
           }
           else


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