12 #include <boost/exception/errinfo_file_name.hpp> 17 namespace duds {
namespace time {
namespace planetary {
35 is.read((
char*)buf, 4);
36 bei.
val = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | buf[3];
48 std::ifstream zf(zonefile, std::ios_base::in | std::ios_base::binary);
51 boost::errinfo_file_name(zonefile));
56 beuint32_t lsc, lstime, numls, transt, ltt, abr;
57 zf >> lsc >> transt >> ltt >> abr;
60 boost::errinfo_file_name(zonefile));
62 zf.seekg(transt.
val * 5 + ltt.
val * 6 + abr.val, std::ios_base::cur);
63 shared_ptr<LeapMap> ls(std::make_shared<LeapMap>());
65 for (; zf.good() && (lsc.
val > 0); --lsc.
val) {
70 std::pair<LeapMap::iterator, bool> res = ls->emplace(std::make_pair(
77 boost::errinfo_file_name(zonefile));
83 boost::errinfo_file_name(zonefile));
86 std::lock_guard<duds::general::Spinlock> lock(
block);
92 std::lock_guard<duds::general::Spinlock> lock(
block);
97 std::lock_guard<duds::general::Spinlock> lock(
block);
106 std::lock_guard<duds::general::Spinlock> lock(
block);
108 if (
leaps->empty()) {
110 leaps->emplace(std::make_pair(leapOn, additional));
113 LeapMap::iterator iter =
leaps->lower_bound(leapOn);
115 if (iter ==
leaps->end()) {
117 leaps->emplace(std::make_pair(leapOn, iter->second + additional));
119 }
else if (iter->first == leapOn) {
123 std::pair<LeapMap::iterator, bool> res =
124 leaps->insert(LeapMap::value_type(leapOn, iter->second));
126 for (; iter !=
leaps->end(); ++iter) {
127 iter->second += additional;
137 std::lock_guard<duds::general::Spinlock> lock(
block);
139 leaps->emplace(std::make_pair(leapOn, total));
145 std::lock_guard<duds::general::Spinlock> lock(
block);
146 LeapMap::const_iterator iter =
leaps->lower_bound(when);
147 if (iter ==
leaps->begin()) {
157 std::lock_guard<duds::general::Spinlock> lock(
block);
158 LeapMap::const_iterator iter =
leaps->lower_bound(time);
159 if (iter ==
leaps->begin()) {
164 if (iter ==
leaps->end()) {
177 std::lock_guard<duds::general::Spinlock> lock(
block);
178 return shared_ptr<LeapMap>(
leaps);
182 std::lock_guard<duds::general::Spinlock> lock(
block);
shared_ptr< LeapMap > leaps
The leap seconds.
duds::time::interstellar::Seconds currentUntil() const
Returns the time when the leap second data may no longer be up to date.
static constexpr TimePoint max()
Returns the latest time that can be represented.
void setCurrent(const duds::time::interstellar::Seconds when)
Sets a timestamp for when the leap second information becomes outdated.
An I/O error occured while reading a zoneinfo database file.
std::chrono::duration< std::int64_t > Seconds
Stores a duration in seconds.
duds::general::Spinlock block
Used to make access and changes thread-safe.
duds::time::interstellar::Seconds leapSeconds(const duds::time::interstellar::SecondTime &when) const
Returns the sum of all leap seconds in use at the given time.
void add(const duds::time::interstellar::SecondTime leapOn, const duds::time::interstellar::Seconds additional=duds::time::interstellar::Seconds(1))
Adds new leap second(s) at the given time and adjusts existing records to match.
void set(const duds::time::interstellar::SecondTime leapOn, const duds::time::interstellar::Seconds total)
Makes a new leap second entry.
std::istream & operator>>(std::istream &is, beuint32_t &bei)
LeapSeconds()
Makes a new LeapSeconds object with no leap seconds and a current time as far in the past as possible...
std::map< duds::time::interstellar::SecondTime, duds::time::interstellar::Seconds > LeapMap
The data structure used to hold leap seconds.
LeapMap leapMapCopy() const
Returns a copy of the current map of leap seconds.
The zoneinfo file claimed to have more leap second records than were read from the file...
An extention to the C++ std::chrono::time_point template to make time points easier to work with...
duds::time::interstellar::Seconds currUntil
A time stamp indicating when the stored information may be outdated.
More than one leap second was specified for the same time in a zoneinfo database file.
static constexpr TimePoint min()
Returns the earlist time that can be represented.
int readZoneinfo(const std::string &zoneinfo)
Reads the indicated zoneinfo database file.
More than one leap second was specified for the same time.
LeapBounds getLeapBounds(const duds::time::interstellar::SecondTime time) const
Create a LeapBounds object with the data for the time period covered for the given time...
#define DUDS_THROW_EXCEPTION(x)
Works like BOOST_THROW_EXCEPTION, but includes a stack trace if DUDS_ERRORS_VERBOSE is defined...
A container holding the number of leap seconds and the time bounds over which the leap seconds are ap...
shared_ptr< const LeapMap > leapMap() const
Returns a new shared pointer to the current map of leap seconds.