DUDS
Distributed Update of Data from Something
Planetary.cpp
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  */
11 
12 namespace duds { namespace time { namespace planetary {
13 
14 // boost::posix_time::ptime epoch(boost::gregorian::date(1970,1,1));
15 const boost::gregorian::date EarthDateZero(boost::gregorian::date(1970,1,1));
16 const boost::posix_time::ptime EarthTimeZero(EarthDateZero);
17 
18 unique_ptr<Earth> earth;
19 
21 
22 const boost::gregorian::date &Earth::dateZero() {
23  return EarthDateZero;
24 }
25 
26 const boost::posix_time::ptime &Earth::timeZero() {
27  return EarthTimeZero;
28 }
29 
30 void Earth::make(const std::string &path) {
31  earth = std::unique_ptr<Earth>(new Earth());
32  earth->leaps.readZoneinfo(path);
33 }
34 
35 std::time_t Earth::timeUtc(
37 ) const {
39  return (std::time_t)((t - ls).time_since_epoch().count());
40 }
41 
42 boost::gregorian::date Earth::date(
44 ) const {
46  // TAI to UTC
47  return EarthDateZero + boost::gregorian::days(
48  (t - ls).time_since_epoch().count() / 86400
49  );
50 }
51 
52 boost::gregorian::date Earth::dateUtcToTai(
54 ) const {
56  // UTC to TAI
57  return EarthDateZero + boost::gregorian::days(
58  (t + ls).time_since_epoch().count() / 86400
59  );
60 }
61 
62 boost::posix_time::ptime Earth::posix(
64 ) const {
66  // TAI to UTC
67  return EarthTimeZero + boost::posix_time::milliseconds(
68  (t - ls).time_since_epoch().count()
69  );
70 }
71 
72 boost::posix_time::ptime Earth::posixUtcToTai(
74 ) const {
76  // UTC to TAI
77  return EarthTimeZero + boost::posix_time::milliseconds(
78  (t + ls).time_since_epoch().count()
79  );
80 }
81 
82 } } }
static const boost::gregorian::date & dateZero()
Definition: Planetary.cpp:22
std::time_t timeUtc(const duds::time::interstellar::SecondTime &t) const
Converts from IST to UTC and provides a std::time_t result.
Definition: Planetary.cpp:35
std::chrono::duration< std::int64_t > Seconds
Stores a duration in seconds.
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.
const boost::posix_time::ptime EarthTimeZero(EarthDateZero)
const boost::gregorian::date EarthDateZero(boost::gregorian::date(1970, 1, 1))
boost::gregorian::date date(const duds::time::interstellar::SecondTime &t) const
Converts from IST to UTC and provides a date result.
Definition: Planetary.cpp:42
An extention to the C++ std::chrono::time_point template to make time points easier to work with...
boost::gregorian::date dateUtcToTai(const duds::time::interstellar::SecondTime &t) const
Converts from UTC to TAI and provides a date result.
Definition: Planetary.cpp:52
std::chrono::duration< std::int64_t, std::milli > Milliseconds
Stores a duration in milliseconds.
unique_ptr< Earth > earth
Definition: Planetary.cpp:18
static const boost::posix_time::ptime & timeZero()
Definition: Planetary.cpp:26
static void make(const std::string &path="/usr/share/zoneinfo-leaps/UTC")
Makes the Earth planetary time object using the given zoneinfo file for data on leap seconds...
Definition: Planetary.cpp:30
boost::posix_time::ptime posix(const duds::time::interstellar::MilliTime &t) const
Converts from IST to UTC and provides a ptime result.
Definition: Planetary.cpp:62
boost::posix_time::ptime posixUtcToTai(const duds::time::interstellar::MilliTime &t) const
Converts from UTC to TAI and provides a ptime result.
Definition: Planetary.cpp:72