7 #include "fwTools/dateAndTime.hpp" 9 #include <fwCore/base.hpp> 11 #include <boost/lexical_cast.hpp> 12 #include <boost/regex.hpp> 21 ::boost::gregorian::date resDate( ::boost::gregorian::from_undelimited_string(
"19000101" ) );
22 if ( dateStr.size() < 8 )
25 "The string length is too short (<8) : " << dateStr <<
26 ". The string is initialized with \"19000101\".");
28 else if ( dateStr.size() > 8 )
30 OSLM_WARN(
"The string length is too long (>8) : " << dateStr <<
".. The string is trunked to 8 characters.");
35 ::boost::regex isNumber(
"[0-9]+");
37 if( ::boost::regex_match(dateStr, isNumber) )
39 resDate = ::boost::gregorian::date( ::boost::gregorian::from_undelimited_string( dateStr ) );
44 "The string not contains 8 numbers : " << dateStr <<
45 ". The string is initialized with \"19000101\".");
53 ::boost::posix_time::time_duration
strToBoostTime(
const std::string& timeStr )
55 using ::boost::posix_time::time_duration;
56 using ::boost::posix_time::hours;
57 using ::boost::posix_time::minutes;
58 using ::boost::posix_time::seconds;
61 if ( timeStr.size() < 6 )
63 OSLM_WARN(
"The string length is too short (<6) : " << timeStr <<
64 ". The string is initialized with \"000000\".");
65 td = hours(0) + minutes(0) + seconds(0);
67 else if ( timeStr.size() > 6 )
69 OSLM_WARN(
"The string length is too short (>6) : " << timeStr <<
". This string is trunked.");
74 ::boost::regex isNumber(
"[0-9]+");
75 if( ::boost::regex_match(timeStr, isNumber) )
77 std::uint16_t h = ::boost::lexical_cast< std::uint16_t > ( timeStr.substr(0, 2) );
78 std::uint16_t m = ::boost::lexical_cast< std::uint16_t > ( timeStr.substr(2, 2) );
79 std::uint16_t s = ::boost::lexical_cast< std::uint16_t > ( timeStr.substr(4, 2) );
80 td = hours(h) + minutes(m) + seconds(s);
84 OSLM_WARN(
"The string not contains 6 numbers : " << timeStr <<
85 ". The string is initialized with \"000000\".");
86 td = hours(0) + minutes(0) + seconds(0);
101 std::string
getDate( const ::boost::posix_time::ptime& dateAndTime )
103 std::string dateAndTimeStr = ::boost::posix_time::to_iso_string(dateAndTime);
104 return dateAndTimeStr.substr(0, 8);
109 std::string
getTime( const ::boost::posix_time::ptime& dateAndTime )
111 std::string dateAndTimeStr = ::boost::posix_time::to_iso_string(dateAndTime);
112 return dateAndTimeStr.substr(9, 6);
119 ::boost::posix_time::ptime now = ::boost::posix_time::second_clock::local_time();
120 std::string nowStr = ::boost::posix_time::to_simple_string(now);
121 return nowStr.substr(0, 21);
#define OSLM_WARN(message)