I’am using boost date time to calculate the unix time for a particular date.
In most cases the returned value is correct but sometimes the calculated number of
second is not correct.
This is an example :
boost::posix_time::ptime t(boost::gregorian::date(1900, 1, 1));
boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
boost::posix_time::time_duration dur;
dur = t - epoch;
int tstamp = dur.total_seconds();
if (t < epoch) tstamp = -tstamp ;
The expected value is -2208902400 but I get -2085978496.
Do you have a workaround for this issue ?
For some reason boost has the year 2038 bug.
The work around is to avoid dates from before your grandparents were born 🙂
update: the boost bug tracker has a bug for this. It’s 3 years old.