Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r86448 - in branches/release/boost/chrono: detail/inlined/win io
From: vicente.botet_at_[hidden]
Date: 2013-10-26 08:36:11


Author: viboes
Date: 2013-10-26 08:36:11 EDT (Sat, 26 Oct 2013)
New Revision: 86448
URL: http://svn.boost.org/trac/boost/changeset/86448

Log:
Chrono: merge fixes for #9274, #9276.

Text files modified:
   branches/release/boost/chrono/detail/inlined/win/chrono.hpp | 7 ++-
   branches/release/boost/chrono/io/time_point_io.hpp | 69 ++++++++++++++++++++++++++++++++-------
   2 files changed, 61 insertions(+), 15 deletions(-)

Modified: branches/release/boost/chrono/detail/inlined/win/chrono.hpp
==============================================================================
--- branches/release/boost/chrono/detail/inlined/win/chrono.hpp Sat Oct 26 08:32:33 2013 (r86447)
+++ branches/release/boost/chrono/detail/inlined/win/chrono.hpp 2013-10-26 08:36:11 EDT (Sat, 26 Oct 2013) (r86448)
@@ -109,8 +109,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)
+ -116444736000000000LL
+ ));
   }
 #endif
 

Modified: branches/release/boost/chrono/io/time_point_io.hpp
==============================================================================
--- branches/release/boost/chrono/io/time_point_io.hpp Sat Oct 26 08:32:33 2013 (r86447)
+++ branches/release/boost/chrono/io/time_point_io.hpp 2013-10-26 08:36:11 EDT (Sat, 26 Oct 2013) (r86448)
@@ -28,6 +28,7 @@
 #include <boost/chrono/clock_string.hpp>
 #include <boost/chrono/round.hpp>
 #include <boost/chrono/detail/scan_keyword.hpp>
+#include <boost/static_assert.hpp>
 #include <boost/detail/no_exceptions_support.hpp>
 #include <cstring>
 #include <locale>
@@ -46,9 +47,11 @@
 {
   namespace chrono
   {
+ typedef double fractional_seconds;
     namespace detail
     {
 
+
       template <class CharT, class InputIterator = std::istreambuf_iterator<CharT> >
       struct time_get
       {
@@ -758,6 +761,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;
     }
 
@@ -779,7 +783,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;
@@ -801,11 +805,36 @@
      return y * 365 + y / 4 - y / 100 + y / 400;
    }
 
+ // Returns year/month/day triple in civil calendar
+ // Preconditions: z is number of days since 1970-01-01 and is in the range:
+ // [numeric_limits<Int>::min(), numeric_limits<Int>::max()-719468].
+ template <class Int>
+ //constexpr
+ void
+ inline civil_from_days(Int z, Int& y, unsigned& m, unsigned& d) BOOST_NOEXCEPT
+ {
+ BOOST_STATIC_ASSERT_MSG(std::numeric_limits<unsigned>::digits >= 18,
+ "This algorithm has not been ported to a 16 bit unsigned integer");
+ BOOST_STATIC_ASSERT_MSG(std::numeric_limits<Int>::digits >= 20,
+ "This algorithm has not been ported to a 16 bit signed integer");
+ z += 719468;
+ const Int era = (z >= 0 ? z : z - 146096) / 146097;
+ const unsigned doe = static_cast<unsigned>(z - era * 146097); // [0, 146096]
+ const unsigned yoe = (doe - doe/1460 + doe/36524 - doe/146096) / 365; // [0, 399]
+ y = static_cast<Int>(yoe) + era * 400;
+ const unsigned doy = doe - (365*yoe + yoe/4 - yoe/100); // [0, 365]
+ const unsigned mp = (5*doy + 2)/153; // [0, 11]
+ d = doy - (153*mp+2)/5 + 1; // [1, 31]
+ m = mp + (mp < 10 ? 3 : -9); // [1, 12]
+ y += (m <= 2);
+ --m;
+ }
    inline std::tm * internal_gmtime(std::time_t const* t, std::tm *tm)
    {
       if (t==0) return 0;
       if (tm==0) return 0;
 
+#if 0
       static const unsigned char
         day_of_year_month[2][366] =
            {
@@ -820,6 +849,7 @@
        { -1, 30, 58, 89, 119, 150, 180, 211, 242, 272, 303, 333, 364 },
        { -1, 30, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }
      };
+#endif
 
      const time_t seconds_in_day = 3600 * 24;
      int32_t days_since_epoch = static_cast<int32_t>(*t / seconds_in_day);
@@ -829,6 +859,7 @@
        hms = seconds_in_day+hms;
      }
 
+#if 0
      int32_t x = days_since_epoch;
      int32_t y = static_cast<int32_t> (static_cast<long long> (x + 2) * 400
            / 146097);
@@ -843,16 +874,23 @@
        //y -= 32767 + 2;
        y += 70;
        tm->tm_year=y;
- const bool leap = is_leap(y);
+ const int32_t leap = is_leap(y);
        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] ;
+#else
+ int32_t y;
+ unsigned m, d;
+ civil_from_days(days_since_epoch, y, m, d);
+ tm->tm_year=y-1900; tm->tm_mon=m; tm->tm_mday=d;
+#endif
 
      tm->tm_hour = hms / 3600;
      const int ms = hms % 3600;
      tm->tm_min = ms / 60;
      tm->tm_sec = ms % 60;
 
+ tm->tm_isdst = -1;
+ (void)mktime(tm);
      return tm;
    }
 
@@ -907,6 +945,9 @@
               tm = *tmp;
 #else
             if (gmtime_r(&t, &tm) == 0) failed = true;
+ tm.tm_isdst = -1;
+ (void)mktime(&tm);
+
 #endif
 
           }
@@ -922,7 +963,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";
@@ -932,6 +973,7 @@
                 //if (! os.good()) {
                 //throw "exception";
                 //}
+ os.precision(9);
                 os << d.count();
                 //if (! os.good()) {
                 //throw "exception";
@@ -1058,12 +1100,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)
           {
@@ -1079,9 +1117,13 @@
             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();
+ std::ios::fmtflags flgs = is.flags();
+ is.setf(std::ios::fixed, std::ios::floatfield);
+ is.precision(9);
             is >> sec;
+ is.flags(flgs);
             if (is.fail())
             {
               err |= std::ios_base::failbit;
@@ -1099,13 +1141,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