DUDS
Distributed Update of Data from Something
LeapSeconds.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2017 Jeff Jackowski
9  */
12 #include <memory>
13 #include <map>
14 
15 namespace duds { namespace time { namespace planetary {
16 
17 using std::shared_ptr;
18 
32 class LeapSeconds {
33 public:
39  typedef std::map<
43 private:
47  shared_ptr<LeapMap> leaps;
58 public:
63  LeapSeconds();
71  LeapSeconds(const std::string &zoneinfo);
107  int readZoneinfo(const std::string &zoneinfo);
129  void add(const duds::time::interstellar::SecondTime leapOn,
130  const duds::time::interstellar::Seconds additional =
132  );
142  void set(const duds::time::interstellar::SecondTime leapOn,
144  );
150  const duds::time::interstellar::SecondTime &when
151  ) const;
152  /*
153  * Returns the sum of all leap seconds in use at the given time.
154  * @param when The time to inspect for leap seconds.
155  * /
156  template <class ISTime>
157  typename ISTime::duration leapSeconds(const ISTime &when) const {
158  return std::chrono::duration_cast<typename ISTime::duration>(leapSeconds(
159  duds::time::interstellar::SecondTime(
160  std::chrono::duration_cast<duds::time::interstellar::Seconds>(
161  when.time_since_epoch()
162  )
163  )
164  ));
165  } */
166  /*
167  template <class ISTime>
168  LeapBounds getLeapBounds(const ISTime &time) const {
169  return getLeapBounds(
170  }
171  */
180  const duds::time::interstellar::SecondTime time
181  ) const;
192  shared_ptr<const LeapMap> leapMap() const;
197  LeapMap leapMapCopy() const;
198 };
199 
200 } } }
201 
shared_ptr< LeapMap > leaps
The leap seconds.
Definition: LeapSeconds.hpp:47
duds::time::interstellar::Seconds currentUntil() const
Returns the time when the leap second data may no longer be up to date.
Definition: LeapSeconds.cpp:96
void setCurrent(const duds::time::interstellar::Seconds when)
Sets a timestamp for when the leap second information becomes outdated.
Definition: LeapSeconds.cpp:91
std::chrono::duration< std::int64_t > Seconds
Stores a duration in seconds.
duds::general::Spinlock block
Used to make access and changes thread-safe.
Definition: LeapSeconds.hpp:57
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.
SecondClock::time_point SecondTime
A point in time in Interstellar Time stored in Seconds.
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.
LeapSeconds()
Makes a new LeapSeconds object with no leap seconds and a current time as far in the past as possible...
Definition: LeapSeconds.cpp:40
std::map< duds::time::interstellar::SecondTime, duds::time::interstellar::Seconds > LeapMap
The data structure used to hold leap seconds.
Definition: LeapSeconds.hpp:42
Stores when leap seconds occur to allow conversions between Interstellar Time or TAI and planetary ti...
Definition: LeapSeconds.hpp:32
LeapMap leapMapCopy() const
Returns a copy of the current map of leap seconds.
duds::time::interstellar::Seconds currUntil
A time stamp indicating when the stored information may be outdated.
Definition: LeapSeconds.hpp:51
A simple spinlock following the lockable and timed lockable concepts so that it can be used with std:...
Definition: Spinlock.hpp:52
int readZoneinfo(const std::string &zoneinfo)
Reads the indicated zoneinfo database file.
Definition: LeapSeconds.cpp:47
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...
A container holding the number of leap seconds and the time bounds over which the leap seconds are ap...
Definition: LeapBounds.hpp:38
shared_ptr< const LeapMap > leapMap() const
Returns a new shared pointer to the current map of leap seconds.