Example #1
0
		boost::posix_time::time_duration Service::GetTimeOfDay( const boost::posix_time::time_duration& value )
		{
			return
				value >= DAY_DURATION ?
				time_duration(value.hours() % 24, value.minutes(), value.seconds()) :
				value
			;
		}
Example #2
0
 //! Convert a time_duration to a tm structure truncating any fractional seconds and zeroing fields for date components 
 inline
 std::tm to_tm(const boost::posix_time::time_duration& td) {
   std::tm timetm = {};
   timetm.tm_hour = date_time::absolute_value(td.hours());
   timetm.tm_min = date_time::absolute_value(td.minutes());
   timetm.tm_sec = date_time::absolute_value(td.seconds());
   timetm.tm_isdst = -1; // -1 used when dst info is unknown
   return timetm;
 }
Example #3
0
    std::string durationToStr(const boost::posix_time::time_duration &duration)
    {
        std::stringstream ss;

        ss << std::setfill('0') << std::setw(2) << duration.hours() << ":"
           << std::setfill('0') << std::setw(2) << duration.minutes() << ":"
           << std::setfill('0') << std::setw(2) << duration.seconds();
        return ss.str();
    }
Example #4
0
 //! Convert a time_duration to a tm structure truncating any fractional seconds and zeroing fields for date components
 inline
 std::tm to_tm(const boost::posix_time::time_duration& td) {
   std::tm timetm;
   std::memset(&timetm, 0, sizeof(timetm));
   timetm.tm_hour = static_cast<int>(date_time::absolute_value(td.hours()));
   timetm.tm_min = static_cast<int>(date_time::absolute_value(td.minutes()));
   timetm.tm_sec = static_cast<int>(date_time::absolute_value(td.seconds()));
   timetm.tm_isdst = -1; // -1 used when dst info is unknown
   return timetm;
 }
		std::string SchedulesBasedService::EncodeSchedule( const boost::posix_time::time_duration& value )
		{
			if(value.is_not_a_date_time())
			{
				return string();
			}

			std::stringstream os;

			os << std::setw( 2 ) << std::setfill ( '0' )
				<< (value.hours() / 24) << ":"
				<< std::setw( 2 ) << std::setfill ( '0' )
				<< (value.hours() % 24) << ":"
				<< std::setw( 2 ) << std::setfill ( '0' )
				<< value.minutes()
				;

			return os.str ();
		}
Example #6
0
string current_time_string()  {

  stringstream sstream;
  
  boost::posix_time::ptime now = boost::posix_time::
    microsec_clock::local_time();

    const boost::posix_time::time_duration td = now.time_of_day();
    const long hours        = td.hours();
    const long minutes      = td.minutes();
    const long seconds      = td.seconds();
    const long milliseconds = td.total_milliseconds() -
                              ((hours * 3600 + minutes * 60 + seconds) *
			       1000);
    char buf[40];
    sprintf(buf, "%02ld:%02ld:%02ld.%03ld", 
        hours, minutes, seconds, milliseconds);

    return string(buf);
}