Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82563 - in trunk/boost/chrono: detail/inlined/win io
From: vicente.botet_at_[hidden]
Date: 2013-01-20 10:02:05


Author: viboes
Date: 2013-01-20 10:02:04 EST (Sun, 20 Jan 2013)
New Revision: 82563
URL: http://svn.boost.org/trac/boost/changeset/82563

Log:
Chrono: make use of internal_gmtime on windows and make system_clock count relative to 01/01/1970 UTC.
Text files modified:
   trunk/boost/chrono/detail/inlined/win/chrono.hpp | 16 +++++---
   trunk/boost/chrono/io/time_point_io.hpp | 71 +++++++++++++++++++--------------------
   2 files changed, 44 insertions(+), 43 deletions(-)

Modified: trunk/boost/chrono/detail/inlined/win/chrono.hpp
==============================================================================
--- trunk/boost/chrono/detail/inlined/win/chrono.hpp (original)
+++ trunk/boost/chrono/detail/inlined/win/chrono.hpp 2013-01-20 10:02:04 EST (Sun, 20 Jan 2013)
@@ -98,8 +98,12 @@
   #else
     boost::detail::win32::GetSystemTimeAsFileTime( &ft ); // never fails
   #endif
- return system_clock::time_point(system_clock::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
+ )
+ );
   }
 
 #if !defined BOOST_CHRONO_DONT_PROVIDE_HYBRID_ERROR_HANDLING
@@ -130,9 +134,9 @@
       __int64 temp = t.time_since_epoch().count();
 
   # if (!defined( BOOST_MSVC )) || (BOOST_MSVC > 1300) // > VC++ 7.0
- temp -= 116444736000000000LL; // delta from epoch in microseconds
+ //temp -= 116444736000000000LL; // delta from epoch in microseconds
   # else
- temp -= 116444736000000000;
+ //temp -= 116444736000000000LL;
   # endif
 
       temp /= 10000000;
@@ -146,9 +150,9 @@
       temp *= 10000000;
 
   # if (!defined( BOOST_MSVC )) || (BOOST_MSVC > 1300) // > VC++ 7.0
- temp += 116444736000000000LL;
+ //temp += 116444736000000000LL;
   # else
- temp += 116444736000000000;
+ //temp += 116444736000000000LL;
   # endif
 
       return time_point(duration(temp));

Modified: trunk/boost/chrono/io/time_point_io.hpp
==============================================================================
--- trunk/boost/chrono/io/time_point_io.hpp (original)
+++ trunk/boost/chrono/io/time_point_io.hpp 2013-01-20 10:02:04 EST (Sun, 20 Jan 2013)
@@ -34,13 +34,11 @@
 #include <string.h>
 
 #define BOOST_CHRONO_INTERNAL_TIMEGM defined BOOST_WINDOWS && ! defined(__CYGWIN__)
-//#define BOOST_CHRONO_INTERNAL_TIMEGM 1
-
-//#define BOOST_CHRONO_INTERNAL_GMTIME defined BOOST_WINDOWS && ! defined(__CYGWIN__)
-#define BOOST_CHRONO_INTERNAL_GMTIME 0
+#define BOOST_CHRONO_INTERNAL_GMTIME defined BOOST_WINDOWS && ! defined(__CYGWIN__)
 
 #define BOOST_CHRONO_USES_INTERNAL_TIME_GET
 
+
 namespace boost
 {
   namespace chrono
@@ -726,11 +724,13 @@
      return y * 365 + y / 4 - y / 100 + y / 400;
    }
 
+ inline std::tm * internal_gmtime(std::time_t const* t, std::tm *tm)
+ {
+ if (t==0) return 0;
+ if (tm==0) return 0;
 
-
- static
- const unsigned char
- day_of_year_month[2][366] =
+ static const unsigned char
+ day_of_year_month[2][366] =
            {
            { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11
, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12 },
 
@@ -738,27 +738,22 @@
 
            } };
 
- static
- const int32_t days_in_year_before[2][13] =
- {
- { -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 } };
-
- inline std::tm * internal_gmtime(std::time_t const* t, std::tm *tm)
- {
- if (t==0) return 0;
- if (tm==0) return 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;
+ static const int32_t days_in_year_before[2][13] =
+ {
+ { -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 }
+ };
+
+ //tm->tm_year=0;
+ //tm->tm_mon=0;
+ //tm->tm_mday=0;
+ //tm->tm_hour=0;
+ //tm->tm_min=0;
+ //tm->tm_sec=0;
 
      const time_t seconds_in_day = 3600 * 24;
- int32_t days_since_epoch = *t / seconds_in_day;
- int32_t hms = *t - seconds_in_day*days_since_epoch;
+ int32_t days_since_epoch = static_cast<int32_t>(*t / seconds_in_day);
+ int32_t hms = static_cast<int32_t>(*t - seconds_in_day*days_since_epoch);
      if (hms < 0) {
        //std::cout << "days_since_epoch "<< days_since_epoch << std::endl;
        //std::cout << "hms "<< hms << std::endl;
@@ -785,17 +780,17 @@
        tm->tm_mday = doy - days_in_year_before[leap][day_of_year_month[leap][doy] - 1];
 
 
- std::cout << "days_since_epoch "<< days_since_epoch << std::endl;
- std::cout << "hms "<< hms << std::endl;
+ //std::cout << "days_since_epoch "<< days_since_epoch << std::endl;
+ //std::cout << "hms "<< hms << std::endl;
      tm->tm_hour = hms / 3600;
      const int ms = hms % 3600;
      tm->tm_min = ms / 60;
      tm->tm_sec = ms % 60;
 
- std::cout << "t " << *t << std::endl;
- std::cout << "year " << tm->tm_year << std::endl;
- std::cout << "month " << tm->tm_mon << std::endl;
- std::cout << "day " << tm->tm_mday << std::endl;
+ //std::cout << "t " << *t << std::endl;
+ //std::cout << "year " << tm->tm_year << std::endl;
+ //std::cout << "month " << tm->tm_mon << std::endl;
+ //std::cout << "day " << tm->tm_mday << std::endl;
 // std::cout << "hour " << tm->tm_hour << std::endl;
 // std::cout << "min " << tm->tm_min << std::endl;
 // std::cout << "sec " << tm->tm_sec << std::endl;
@@ -837,8 +832,9 @@
 #if defined BOOST_WINDOWS && ! defined(__CYGWIN__)
             std::tm *tmp = 0;
             if ((tmp=localtime(&t)) == 0)
- failed = true;
- tm =*tmp;
+ failed = true;
+ else
+ tm =*tmp;
 #else
             if (localtime_r(&t, &tm) == 0) failed = true;
 #endif
@@ -852,8 +848,9 @@
 #elif defined BOOST_WINDOWS && ! defined(__CYGWIN__)
             std::tm *tmp = 0;
             if((tmp = gmtime(&t)) == 0)
- failed = true;
- tm = *tmp;
+ failed = true;
+ else
+ tm = *tmp;
 #else
             if (gmtime_r(&t, &tm) == 0) failed = true;
 #endif


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