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

#include <tz.hpp>

Public Member Functions

 DB ()
boost::local_time::time_zone_ptr get_tz_ptr (const std::string &region)
 Get boost time-zone pointer from string.
std::vector< std::string > get_regions ()
 Get known time zone regions.

Private Attributes

boost::local_time::tz_database m_tz_db

Detailed Description

The class provides access to Boost time-zone database. It relies on Boost time-zone database file installed by oksutils package and pointed by BOOST_DATE_TIME_TZ_SPEC process environment variable.

Definition at line 26 of file tz.hpp.

Constructor & Destructor Documentation

◆ DB()

oks::tz::DB::DB ( )

Find and read Boost time-zone database.

Definition at line 21 of file oks_tz.cpp.

22{
23 const char* tz_spec_file = ::getenv("BOOST_DATE_TIME_TZ_SPEC");
24
25 if (!tz_spec_file || !*tz_spec_file) {
26 throw std::runtime_error("cannot read value of BOOST_DATE_TIME_TZ_SPEC environment variable");
27 }
28
29 TLOG_DEBUG(1) << "Boost time-zone specification file is \'" << tz_spec_file << '\'';
30
31 try {
32 m_tz_db.load_from_file(tz_spec_file);
33 } catch (const std::exception& ex) {
34 std::ostringstream text;
35 text << "cannot read Boost time-zone specification file \"" << tz_spec_file << "\": " << ex.what();
36 throw std::runtime_error(text.str().c_str());
37 }
38}
boost::local_time::tz_database m_tz_db
Definition tz.hpp:56
#define TLOG_DEBUG(lvl,...)
Definition Logging.hpp:116

Member Function Documentation

◆ get_regions()

std::vector< std::string > oks::tz::DB::get_regions ( )

Get known time zone regions.

This is a helper function for several utilities dealing with Boost time-zone database.

Returns
vector of known regions
Exceptions
std::exceptionif something goes wrong

Definition at line 55 of file oks_tz.cpp.

56{
57 return m_tz_db.region_list();
58}

◆ get_tz_ptr()

boost::local_time::time_zone_ptr oks::tz::DB::get_tz_ptr ( const std::string & region)

Get boost time-zone pointer from string.

This is a helper method for several utilities dealing with Boost time-zone database.

Parameters
regionname of time zone
Returns
time-zone boost pointer
Exceptions
std::exceptionif something goes wrong

Definition at line 41 of file oks_tz.cpp.

42{
43 boost::local_time::time_zone_ptr tz_ptr = m_tz_db.time_zone_from_region(region);
44
45 if (!tz_ptr) {
46 std::ostringstream text;
47 text << "cannot find time-zone \'" << region << '\'';
48 throw std::runtime_error(text.str().c_str());
49 }
50
51 return tz_ptr;
52}

Member Data Documentation

◆ m_tz_db

boost::local_time::tz_database oks::tz::DB::m_tz_db
private

Definition at line 56 of file tz.hpp.


The documentation for this class was generated from the following files: