Boost logo

Boost Users :

Subject: Re: [Boost-users] [posix_time] from_time_t bug
From: Igor R (boost.lists_at_[hidden])
Date: 2012-02-24 07:57:19

> I am running into a problem with boost::posix_time::from_time_t() on a PC
> with, windows xp, visual studio 2010.  When I input a number larger than the
> decimal equivalent of 0x7FFFFFFF (maximum posssible int32) into the function
> it returns a ptime with a date of 1902 or something close to.  I assume the
> UNIX equivalent of time_t is a int32 and that is why I am having this
> problem, but I know a time_t is the equivalent to __int64 in windows xp.
> Is there is a MACRO define I am missing or is this a bug that needs to be
> fixed with this function so that it can accept the windows equivalent of
> time_t?
> Shouldn't this function accept and convert larger intigers thank int32 to a
> ptime or do I have to write my own?

The function looks like this:

conversion.hpp, line 27:
  ptime from_time_t(std::time_t t)
    ptime start(gregorian::date(1970,1,1));
    return start + seconds(static_cast<long>(t));

As you see, it deliberately truncates time_t to long (which has sizeof
== 4, when compiling in 32bit), because seconds() constructor accepts
The most simple patch would be the following:
    --return start + seconds(static_cast<long>(t));
    ++return start + milliseconds(t * 1000);

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at