/*!\ingroup time_format */ inline std::string to_iso_string(time_duration td) { std::ostringstream ss; if(td.is_special()) { /* simply using 'ss << td.get_rep()' won't work on compilers * that don't support locales. This way does. */ // switch copied from date_names_put.hpp switch(td.get_rep().as_special()) { case not_a_date_time: //ss << "not-a-number"; ss << "not-a-date-time"; break; case pos_infin: ss << "+infinity"; break; case neg_infin: ss << "-infinity"; break; default: ss << ""; } } else { if(td.is_negative()) { ss << '-'; } ss << std::setw(2) << std::setfill('0') << date_time::absolute_value(td.hours()); ss << std::setw(2) << std::setfill('0') << date_time::absolute_value(td.minutes()); ss << std::setw(2) << std::setfill('0') << date_time::absolute_value(td.seconds()); //TODO the following is totally non-generic, yelling FIXME time_duration::fractional_seconds_type frac_sec = date_time::absolute_value(td.fractional_seconds()); if (frac_sec != 0) { ss << "." << std::setw(time_duration::num_fractional_digits()) << std::setfill('0') << frac_sec; } }// else return ss.str(); }
/*! \fn CPlayloop::sleep(int duration) */ int CPlayloop::sleep(time_duration duration) { int retval = 0; if( !duration.is_negative() ) { struct timespec ts_to_sleep, ts_remaining; ts_to_sleep.tv_sec = duration.total_seconds(); ts_to_sleep.tv_nsec = duration.fractional_seconds(); //boost::date_time::time_resolutions if (time_duration::resolution() == boost::date_time::micro) { ts_to_sleep.tv_nsec *= 1000; } int retval = nanosleep( &ts_to_sleep, &ts_remaining); if(retval != 0) cerr << "nanosleep returned early due to a signal!" << endl; } return retval; }