DUNE-DAQ
DUNE Trigger and Data Acquisition software
Loading...
Searching...
No Matches
oks::tz Namespace Reference

Classes

class  DB

Functions

boost::posix_time::ptime str_2_posix_time (const std::string &in, boost::local_time::time_zone_ptr tz_ptr, const char *value)
uint64_t posix_time_2_to_ns (boost::posix_time::ptime t)
std::string posix_time_2_iso_string (boost::posix_time::ptime t)

Function Documentation

◆ posix_time_2_iso_string()

std::string oks::tz::posix_time_2_iso_string ( boost::posix_time::ptime t)

Definition at line 115 of file oks_tz.cpp.

116{
117 return boost::posix_time::to_iso_string(t);
118}

◆ posix_time_2_to_ns()

uint64_t oks::tz::posix_time_2_to_ns ( boost::posix_time::ptime t)

Definition at line 108 of file oks_tz.cpp.

109{
110 static boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
111 return ((t - epoch).total_nanoseconds());
112}

◆ str_2_posix_time()

boost::posix_time::ptime oks::tz::str_2_posix_time ( const std::string & in,
boost::local_time::time_zone_ptr tz_ptr,
const char * value )

Definition at line 67 of file oks_tz.cpp.

68{
69 std::string s(in);
70 std::replace(s.begin(), s.end(), 'T', ' ');
71
72 boost::posix_time::ptime t;
73
74 // convert string to time
75 try
76 {
77 t = boost::posix_time::time_from_string(s);
78 }
79 catch (const std::exception& ex)
80 {
81 std::ostringstream text;
82 text << "cannot parse " << value << " = \'" << in << "\': \"" << ex.what() << "\" (ISO 8601 format (YYYY-MM-DD HH:MM:SS) is expected).";
83 throw std::runtime_error(text.str().c_str());
84 }
85
86
87 // convert local time to UTC, if the time zone was provided
88 if (tz_ptr)
89 {
90 try
91 {
92 boost::local_time::local_date_time lt(t.date(), t.time_of_day(), tz_ptr, boost::local_time::local_date_time::EXCEPTION_ON_ERROR);
93 TLOG_DEBUG(1) << "Build zone\'s time \'" << in << "\' => \'" << lt.to_string() << "\' using \'" << tz_ptr->to_posix_string() << '\'' ;
94 t = lt.utc_time();
95 }
96 catch(std::exception& e)
97 {
98 std::ostringstream text;
99 text << "cannot parse " << value << " = \'" << in << "\' in time zone \"" << tz_ptr->to_posix_string() << "\": \"" << e.what() << '\"' << std::endl;
100 throw std::runtime_error(text.str().c_str());
101 }
102 }
103
104 return t;
105}
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:112