Boost logo

Boost Users :

Subject: [Boost-users] boost::posix_time::from_time_t bug ???
From: £ukasz Majewski (lukasz.majewski.ggroups_at_[hidden])
Date: 2009-05-01 08:29:48


Hello,

   i think that i've found bug in date time library or maybe i made
something wrog.

SAMPLE CODE:

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

using namespace boost::posix_time;

int main( int argc, char** argv )
{
        time_t t = time( 0 );

        std::cout << "time_t: " << ctime( &t ) << std::endl;

        struct tm* t2 = localtime( &t );
        std::cout << "struct tm: " << asctime( t2 ) << std::endl;

        ptime t3 = from_time_t( t );

        std::cout << "ptime from time_t: " << to_simple_string( t3 ) <<
std::endl;

        ptime t4 = ptime_from_tm( *t2 );

        std::cout << "ptime from tm: " << to_simple_string( t4 ) <<
std::endl;

        return 0;
}

OUTPUT:

time_t: Fri May 1 14:22:01 2009
struct tm: Fri May 1 14:22:01 2009
ptime from time_t: 2009-May-01 12:22:01 // incorrect result
ptime from tm: 2009-May-01 14:22:01



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net