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 105 of file oks_tz.cpp.

106{
107 return boost::posix_time::to_iso_string(t);
108}

◆ posix_time_2_to_ns()

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

Definition at line 98 of file oks_tz.cpp.

99{
100 static boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
101 return ((t - epoch).total_nanoseconds());
102}

◆ 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 61 of file oks_tz.cpp.

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