Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84284 - in trunk: boost/date_time/posix_time libs/date_time/test/posix_time
From: marshall_at_[hidden]
Date: 2013-05-14 17:22:02


Author: marshall
Date: 2013-05-14 17:22:01 EDT (Tue, 14 May 2013)
New Revision: 84284
URL: http://svn.boost.org/trac/boost/changeset/84284

Log:
Added missing call 'to_time_t' (and tests)
Text files modified:
   trunk/boost/date_time/posix_time/conversion.hpp | 7 +++++++
   trunk/libs/date_time/test/posix_time/testtime.cpp | 7 ++++++-
   2 files changed, 13 insertions(+), 1 deletions(-)

Modified: trunk/boost/date_time/posix_time/conversion.hpp
==============================================================================
--- trunk/boost/date_time/posix_time/conversion.hpp (original)
+++ trunk/boost/date_time/posix_time/conversion.hpp 2013-05-14 17:22:01 EDT (Tue, 14 May 2013)
@@ -30,6 +30,13 @@
     return start + seconds(static_cast<long>(t));
   }
 
+ //! Function that converts a ptime into a time_t
+ std::time_t to_time_t(ptime pt) {
+ time_duration dur = pt - ptime(gregorian::date(1970,1,1));
+ return std::time_t(dur.total_seconds ());
+ }
+
+
   //! Convert a time to a tm structure truncating any fractional seconds
   inline
   std::tm to_tm(const boost::posix_time::ptime& t) {

Modified: trunk/libs/date_time/test/posix_time/testtime.cpp
==============================================================================
--- trunk/libs/date_time/test/posix_time/testtime.cpp (original)
+++ trunk/libs/date_time/test/posix_time/testtime.cpp 2013-05-14 17:22:01 EDT (Tue, 14 May 2013)
@@ -258,26 +258,31 @@
   //time_t conversions:
   t18 = from_time_t(0); //1970-1-1 0:0:0
   check("time_t conversion of 0", t18 == ptime(date(1970,1,1)));
+ check("time_t conversion from 0", to_time_t(t18) == 0);
   
   std::time_t tt(500000000);
   t18 = from_time_t(tt); //1985-11-5 0:53:20
   check("time_t conversion of 500000000",
         t18 == ptime(date(1985,11,5), time_duration(0,53,20)));
+ check("time_t conversion from 500000000", to_time_t(t18) == tt);
   
   std::time_t tt1(1060483634);
   t18 = from_time_t(tt1); //2003-08-10 2:47:14
   check("time_t conversion of 1060483634",
         t18 == ptime(date(2003,8,10), time_duration(2,47,14)));
+ check("time_t conversion from 1060483634", to_time_t(t18) == tt1);
   
   std::time_t tt2(1760483634);
   t18 = from_time_t(tt2); //2025-10-14 23:13:54
   check("time_t conversion of 1760483634",
         t18 == ptime(date(2025,10,14), time_duration(23,13,54)));
-
+ check("time_t conversion from 1760483634", to_time_t(t18) == tt2);
+
   std::time_t tt3(1960483634);
   t18 = from_time_t(tt3); //2032-2-15 18:47:14
   check("time_t conversion of 1960483634",
         t18 == ptime(date(2032,2,15), time_duration(18,47,14)));
+ check("time_t conversion from 1960483634", to_time_t(t18) == tt3);
 
   special_values_tests();
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk