Re: [Boost-bugs] [Boost C++ Libraries] #4543: ptime: year 2038 problem

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #4543: ptime: year 2038 problem
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2012-03-07 22:04:53


#4543: ptime: year 2038 problem
---------------------------------------------+------------------------------
  Reporter: Roland Bock <rbock@…> | Owner: az_sw_dude
      Type: Bugs | Status: new
 Milestone: Boost 1.44.0 | Component: date_time
   Version: Boost 1.44.0 | Severity: Problem
Resolution: | Keywords:
---------------------------------------------+------------------------------

Comment (by pjohnmeyer@…):

 I am curious what the path forward is on this bug, which still exists in
 1.48. I have implemented my own version of "from_time_t" that we use on
 our project that extends the useful life of the function significantly.

 The most confusing part of this problem, in my mind, is that you can
 achieve valid and invalid times by performing essentially the same set of
 operations. See below:

 {{{
   std::time_t theT = std::time_t(LONG_MAX) + std::time_t(100000);
   auto tm1 = boost::posix_time::from_time_t(theT);
   auto tm2 = boost::posix_time::from_time_t(LONG_MAX) +
 boost::posix_time::seconds(100000);
   auto tm3 = myproject::from_time_t(theT);
 }}}

 `tm1` is 1901-Dec-15 00:32:31, because the `from_time_t` cast to `long`
 (which is 32-bits on my platform, MSVC) causes the positive value
 `LONG_MAX + 100000` to be interpreted as a negative value.

 `tm2` and `tm3` both evaluate, correctly, to 2038-Jan-20 07:00:47. `tm2`
 at a glance does nothing mathematically different; it simply adds in the
 additional 100000 seconds after `from_time_t` is called.

 Here is the implementation of `myproject::from_time_t`. Yes it has magic
 numbers that I calculated by working backwards from the inner workings of
 the `posix_time` code, and it doesn't address the full range of possible
 values of a 64-bit `time_t`. It does, however, extend the max value to
 9,012,505,233,654 seconds since the epoch. The impacts this has elsewhere,
 however, I have not yet examined -- I know that, for example, converting
 extremely high values to a gregorian date will cause a bad year exception.

 {{{
   boost::posix_time::ptime myproject::from_time_t(std::time_t time)
   {
     return boost::posix_time::ptime(
       static_cast<boost::posix_time::ptime::time_rep_type>(
         210866803200000000ll + (time * 1000000) )
   }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4543#comment:2>
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:09 UTC