string duration_string(const ros::Duration &d) { char buf[40]; boost::posix_time::time_duration td = d.toBoost(); if (td.hours() > 0) { snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%dhr %d:%02ds (%ds)", td.hours(), td.minutes(), td.seconds(), td.total_seconds()); } else if (td.minutes() > 0) { snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%d:%02ds (%ds)", td.minutes(), td.seconds(), td.total_seconds()); } else { snprintf(buf, sizeof(buf) / sizeof(buf[0]), "%.1fs", d.toSec()); } return string(buf); }