File indexing completed on 2024-04-06 12:01:59
0001
0002 #include "CondFormats/Common/interface/TimeConversions.h"
0003
0004 #include <iostream>
0005
0006 int main() {
0007 {
0008 std::cout << "boost frac digits " << boost::posix_time::time_duration::num_fractional_digits() << std::endl;
0009 ::timeval stv;
0010 ::gettimeofday(&stv, 0);
0011
0012 cond::Time_t time = cond::time::from_timeval(stv);
0013
0014 std::cout << stv.tv_sec << " " << stv.tv_usec << std::endl;
0015 std::cout << time << std::endl;
0016 stv = cond::time::to_timeval(time);
0017 std::cout << stv.tv_sec << " " << stv.tv_usec << std::endl;
0018
0019 boost::posix_time::ptime bt = cond::time::to_boost(time);
0020
0021 boost::posix_time::time_duration td = bt - cond::time::time0;
0022
0023 std::cout << bt << std::endl;
0024 std::cout << "s. " << td.total_seconds() << "." << td.fractional_seconds() << std::endl;
0025 std::cout << "us " << td.total_microseconds() << std::endl;
0026 std::cout << "ns " << td.total_nanoseconds() << std::endl;
0027 std::cout << std::endl;
0028
0029
0030
0031 bt += cond::time::nanoseconds(19 * 25);
0032
0033 td = bt - cond::time::time0;
0034
0035 std::cout << bt << std::endl;
0036 std::cout << "s. " << td.total_seconds() << "." << td.fractional_seconds() << std::endl;
0037 std::cout << "us " << td.total_microseconds() << std::endl;
0038 std::cout << "ns " << td.total_nanoseconds() << std::endl;
0039 std::cout << std::endl;
0040
0041 time = cond::time::from_boost(bt);
0042 cond::UnpackedTime utime = cond::time::unpack(time);
0043 std::cout << "s. " << utime.first << "." << utime.second << std::endl;
0044 stv = cond::time::to_timeval(time);
0045 std::cout << stv.tv_sec << " " << stv.tv_usec << std::endl;
0046 }
0047
0048 return 0;
0049 }