Exemplo n.º 1
0
/**
 * Return the number of seconds in a time_duration, as a double, including
 * fractional seconds.
 */
double DateAndTime::secondsFromDuration(time_duration duration) {
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
  // Nanosecond resolution
  return static_cast<double>(duration.total_nanoseconds()) / 1e9;
#else
  // Microsecond resolution
  return static_cast<double>(duration.total_microseconds()) / 1e6;
#endif
}
Exemplo n.º 2
0
std::string TimeConversion::toString(const boost::posix_time::ptime ts, const int secPrecision) const
{
	using namespace boost::posix_time;

	// determine the nanoseconds given in ts
	const int h = ts.time_of_day().hours();
	const int m = ts.time_of_day().minutes();
	const int s = ts.time_of_day().seconds();
	const time_duration r = time_duration(h, m, s);
	const time_duration rest = ts.time_of_day() - r;
	const int nanoseconds = int(rest.total_nanoseconds()); // not more than 1 bil nanoseconds here.

	return toString(to_tm(ts), nanoseconds, secPrecision);
}
Exemplo n.º 3
0
/** time duration in nanoseconds. Duration is limited to
 * MAX_NANOSECONDS and MIN_NANOSECONDS to avoid overflows.
 * @param td :: time_duration instance.
 * @return an int64 of the number of nanoseconds
 */
int64_t DateAndTime::nanosecondsFromDuration(const time_duration &td) {
  int64_t nano;
#ifdef BOOST_DATE_TIME_HAS_NANOSECONDS
  // Nanosecond resolution
  nano = td.total_nanoseconds();
#else
  // Microsecond resolution
  nano = (td.total_microseconds() * 1000);
#endif
  // Use these limits to avoid integer overflows
  if (nano > MAX_NANOSECONDS)
    return MAX_NANOSECONDS;
  else if (nano < MIN_NANOSECONDS)
    return MIN_NANOSECONDS;
  else
    return nano;
}