Boost logo

Boost Users :

From: Matt Schuckmann (matthew_schuckmann_at_[hidden])
Date: 2004-07-22 09:45:15


Has anybody ever implimented a to_time_t function/method for the ptime class
to create a time_t from a ptime. I tried doing it similar to the way
from_time_t does it but I'm not getting the right answer.

It's nice that you can convert from a time_t for use with legacy code but
sometimes you need to go back the other way.

Herer is my to_time_t function that does not appear to be working
inline
std::time_t to_time_t(ptime t)
{
   if( t == neg_infin )
      return 0;
   else if( t == pos_infin )
      return LONG_MAX;
   ptime start(gregorian::date(1970,1,1),time_duration(0,0,0));
   return (t-start).total_seconds();
}

Thanks,


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