Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
// example of use of time conversions
#include "CondFormats/Common/interface/TimeConversions.h"

#include <iostream>

int main() {
  {
    std::cout << "boost frac digits " << boost::posix_time::time_duration::num_fractional_digits() << std::endl;
    ::timeval stv;
    ::gettimeofday(&stv, 0);

    cond::Time_t time = cond::time::from_timeval(stv);

    std::cout << stv.tv_sec << " " << stv.tv_usec << std::endl;
    std::cout << time << std::endl;
    stv = cond::time::to_timeval(time);
    std::cout << stv.tv_sec << " " << stv.tv_usec << std::endl;

    boost::posix_time::ptime bt = cond::time::to_boost(time);

    boost::posix_time::time_duration td = bt - cond::time::time0;

    std::cout << bt << std::endl;
    std::cout << "s. " << td.total_seconds() << "." << td.fractional_seconds() << std::endl;
    std::cout << "us " << td.total_microseconds() << std::endl;
    std::cout << "ns " << td.total_nanoseconds() << std::endl;
    std::cout << std::endl;

    // FIXME (when agree with Coral)
    //bt +=  boost::posix_time::nanoseconds(19*25);
    bt += cond::time::nanoseconds(19 * 25);

    td = bt - cond::time::time0;

    std::cout << bt << std::endl;
    std::cout << "s. " << td.total_seconds() << "." << td.fractional_seconds() << std::endl;
    std::cout << "us " << td.total_microseconds() << std::endl;
    std::cout << "ns " << td.total_nanoseconds() << std::endl;
    std::cout << std::endl;

    time = cond::time::from_boost(bt);
    cond::UnpackedTime utime = cond::time::unpack(time);
    std::cout << "s. " << utime.first << "." << utime.second << std::endl;
    stv = cond::time::to_timeval(time);
    std::cout << stv.tv_sec << " " << stv.tv_usec << std::endl;
  }

  return 0;
}