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

109{
110 return boost::posix_time::to_iso_string(t);
111}

◆ posix_time_2_to_ns()

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

Definition at line 101 of file oks_tz.cpp.

102{
103 static boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
104 return ((t - epoch).total_nanoseconds());
105}

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

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