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 21 of file tz.hpp.

Constructor & Destructor Documentation

◆ DB()

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

Find and read Boost time-zone database.

Definition at line 15 of file oks_tz.cpp.

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

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

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

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

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

Member Data Documentation

◆ m_tz_db

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

Definition at line 54 of file tz.hpp.


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