Boost logo

Boost :

Subject: [boost] [date_time] Trouble with operator+ and microsec(BIG_NUMBER)
From: Christoph Mathys (eraserix_at_[hidden])
Date: 2009-02-19 10:28:41


Hello

I'm using date_time on a 32b Ubuntu machine (1.36, gcc 4.2.4). The
following code shows the problem (at least on my machine):
(compiled with -O2 -Wall, without warnings)

#include <iostream>
#include <boost/date_time/posix_time/posix_time.hpp>
#include <boost/date_time/gregorian/gregorian_types.hpp>

using namespace std;
namespace bpt = boost::posix_time;

int main(int, char**)
{
        const int64_t timeInNs = 1235051546649264674LL;
        const bpt::ptime EPOCH(boost::gregorian::date(1970, 1, 1));
        bpt::ptime offset = EPOCH + bpt::microsec(timeInNs / 1000);

        cout << offset << std::endl;
        return 0;
}

I expect this program to print a date after 1.Jan 1970. However, I get
the following output:
1969-Dec-21 19:28:13.710725

If I change timeInNs to 1235051546649264LL (I removed the last 3
digits), the date is after 1.1.1970.

Whats wrong?

Christoph


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk