Re: [Boost-bugs] [Boost C++ Libraries] #3109: time_duration::total_seconds() - overflow

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3109: time_duration::total_seconds() - overflow
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-01-19 20:38:15


#3109: time_duration::total_seconds() - overflow
-------------------------------+--------------------------------------------
 Reporter: ioni@… | Owner: az_sw_dude
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: date_time
  Version: Boost 1.41.0 | Severity: Problem
 Keywords: year 2038 problem |
-------------------------------+--------------------------------------------
Changes (by rehor@…):

  * version: Boost 1.39.0 => Boost 1.41.0

Comment:

 platform: MSVC 8, Windows XP
 Boost 1.41

 time_duration::total_seconds should be returning 64bit int instead of
 32bit int. All underlying code is correct, only the return type of
 time_duration::total_seconds() is only a 32bit int, which is not wide
 enough for time durations lasting several decades or a century. When
 changed to 64bit int, total_seconds() works as expected. The problem
 possibly applies to other total_* methods as well.

 {{{
 time_duration d =
     ptime(boost::gregorian::date(2010,1,1))
   - ptime(boost::gregorian::date(1899,12,30));

 unsigned long long s = d.total_seconds(); // returns a negative int
 }}}

 Proposed fix: time_duration.hpp
 {{{
     //! Returns total number of seconds truncating any fractional seconds
     tick_type total_seconds() const //changed type from sec_type to
 tick_type
     {
       return static_cast<tick_type>(ticks() / ticks_per_second());
     }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/3109#comment:1>
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:02 UTC