#ifndef _utl_LeapSeconds_h_ #define _utl_LeapSeconds_h_ #include #include #include #include namespace utl { /** \class LeapSeconds LeapSeconds.h utl/LeapSeconds.h Quick definition: a positive leap second is a GPS second where the UTC second is exceptionally allowed to take the value of 60, i.e. the seconds run as 58, 59, 60, 00, 01... A negative leap second is removed from the last second of a day preceding the midnight, i.e. the day runs only until second 58 and jumps directly to 00 of the next day. \image html utl_LeapSeconds.png \author Darko Veberic \date 16 Jul 2009 \version $Id$ \ingroup time */ class LeapSeconds : public Singleton { private: // pair contains leap and accumulated leaps typedef std::map > GPSToUnixMap; typedef GPSToUnixMap::const_iterator GPSToUnixIterator; typedef std::map UnixToGPSMap; typedef UnixToGPSMap::const_iterator UnixToGPSIterator; public: LeapSeconds() : fTZ(0) { Init(); SetUTC(); } ~LeapSeconds() { UnsetUTC(); } /// returns true if the GPS second is an UTC leap second bool ConvertGPSToUnix(const unsigned long gpsSecond, time_t& unixSecond) const; void ConvertUnixToGPS(const time_t unixSecond, unsigned long& gpsSecond) const; void Dump() const; private: void Init(); void SetUTC(); void UnsetUTC(); std::time_t fGPSEpochInUnixSeconds; GPSToUnixMap fGPSToUnixLeaps; UnixToGPSMap fUnixToGPSLeaps; std::string* fTZ; }; } #endif