julian-date.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 INESC TEC
4  * Copyright (c) 2021 CNES
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Code from https://gitlab.inesctec.pt/pmms/ns3-satellite
20  *
21  * Author: Pedro Silva <pmms@inesctec.pt>
22  * Author: Bastien Tauran <bastien.tauran@viveris.fr>
23  */
24 
25 #ifndef JULIANDATE_H
26 #define JULIANDATE_H
27 
28 #include <ns3/nstime.h>
29 
30 #include <functional>
31 #include <ostream>
32 #include <stdint.h>
33 #include <string>
34 #include <utility>
35 
36 namespace ns3
37 {
38 
45 struct DateTime
46 {
48  {
49  UTC,
50  UT1,
51  TAI,
52  TT,
53  GPST,
54  POSIX
55  };
56 
57  uint32_t year, month, day;
60 
61  friend std::ostream& operator<<(std::ostream& os, DateTime::TimeSystem ts);
62 };
63 
79 {
82 
83  public:
84  static const uint32_t PosixYear;
85  static const uint32_t MinYear;
86  static const uint32_t MaxYear;
87  static const double PosixEpoch;
88  static const uint32_t J2000Epoch;
89  static const uint32_t Posix1992;
90  static const uint32_t HourToMs;
91  static const uint32_t DayToMs;
92  static const Time TtToTai;
93  static const Time TaiToGps;
94 
98  JulianDate(void);
99 
108  JulianDate(double jd);
109 
115  JulianDate(uint32_t days, uint32_t ms_day);
116 
122  JulianDate(const std::string& date, TimeSystem ts = DateTime::UTC);
123 
129  double GetDouble(TimeSystem ts = DateTime::UTC) const;
130 
135  DateTime GetDateTime(void) const;
136 
141  DateTime GetDateTime(TimeSystem ts) const;
142 
152  std::string ToString(void) const;
153 
164  std::string ToString(TimeSystem ts) const;
165 
170  std::pair<double, double> GetPolarMotion(void) const;
171 
176  double GetOmegaEarth(void) const;
177 
182  double GetGmst(void) const;
183 
192  void SetDate(double jd);
193 
199  void SetDate(uint32_t days, uint32_t ms_day);
200 
206  void SetDate(const std::string& date, TimeSystem ts = DateTime::UTC);
207 
213  JulianDate operator+(const Time& t) const;
214 
219  void operator+=(const Time& t);
220 
226  JulianDate operator-(const Time& t) const;
227 
232  void operator-=(const Time& t);
233 
239  Time operator-(const JulianDate& jd) const;
240 
246  bool operator<(const JulianDate& jd) const;
247 
253  bool operator<=(const JulianDate& jd) const;
254 
260  bool operator>(const JulianDate& jd) const;
261 
267  bool operator>=(const JulianDate& jd) const;
268 
274  bool operator==(const JulianDate& jd) const;
275 
281  bool operator!=(const JulianDate& jd) const;
282 
293  friend std::ostream& operator<<(std::ostream& os, const JulianDate& jd);
294 
295  private:
304  static bool IsLeapYear(uint32_t year);
305 
311  static Time TaiMinusUtc(uint32_t daysInPosix);
312 
318  static Time Dut1(uint32_t daysInPosix);
319 
326  static DateTime GregorianDate(uint32_t days, uint32_t ms_day);
327 
334  static Time OffsetFromUtc(uint32_t daysInPosix, TimeSystem ts);
335 
343  static Time OffsetToUtc(uint32_t daysInPosix, uint32_t ms_day, TimeSystem ts);
344 
349  DateTime GregorianDate(void) const;
350 
359  Time OffsetFromUtc(void) const;
360 
369  Time OffsetToUtc(void) const;
370 
371  uint32_t m_days;
372  uint32_t m_ms_day;
374 };
375 
376 } // namespace ns3
377 
378 #endif /* JULIANDATE_H */
Class to handle Julian days and provide respective Earth Orientation Parameters (EOP).
Definition: julian-date.h:79
static bool IsLeapYear(uint32_t year)
Check if it is a leap year.
Definition: julian-date.cc:405
JulianDate(void)
Default constructor.
Definition: julian-date.cc:89
double GetGmst(void) const
Retrieve the Greenwich Mean Sidereal Time.
Definition: julian-date.cc:187
static const Time TaiToGps
offset from TAI to GPST
Definition: julian-date.h:93
void SetDate(double jd)
Set the Julian days.
Definition: julian-date.cc:218
uint32_t m_days
full days since epoch.
Definition: julian-date.h:371
double GetDouble(TimeSystem ts=DateTime::UTC) const
GetDouble Get the Julian days.
Definition: julian-date.cc:113
bool operator>(const JulianDate &jd) const
operator > (compare Julian dates).
Definition: julian-date.cc:357
bool operator==(const JulianDate &jd) const
operator == (compare Julian dates).
Definition: julian-date.cc:375
JulianDate operator-(const Time &t) const
operator - (negative time adjustment).
Definition: julian-date.cc:298
JulianDate operator+(const Time &t) const
operator + (positive time adjustment).
Definition: julian-date.cc:272
Time OffsetFromUtc(void) const
Returns the offset from UTC.
Definition: julian-date.cc:485
TimeSystem m_time_scale
external time system.
Definition: julian-date.h:373
static const uint32_t PosixYear
POSIX/Unix epoch year.
Definition: julian-date.h:84
static const uint32_t DayToMs
milliseconds in a day
Definition: julian-date.h:91
static const uint32_t MinYear
Minimum year supported.
Definition: julian-date.h:85
Time OffsetToUtc(void) const
Returns the offset to UTC.
Definition: julian-date.cc:518
static Time TaiMinusUtc(uint32_t daysInPosix)
The difference between TAI and UTC time systems.
Definition: julian-date.cc:413
static const Time TtToTai
offset from TT to TAI
Definition: julian-date.h:92
static const double PosixEpoch
1 Jan 1970, 0h
Definition: julian-date.h:87
uint32_t m_ms_day
milliseconds of the day.
Definition: julian-date.h:372
static const uint32_t HourToMs
milliseconds in an hour
Definition: julian-date.h:90
std::string ToString(void) const
Get the string representation of the Gregorian calendar date.
Definition: julian-date.cc:137
DateTime GetDateTime(void) const
Get the Gregorian calendar date in current time system.
Definition: julian-date.cc:125
bool operator<(const JulianDate &jd) const
operator < (compare Julian dates).
Definition: julian-date.cc:339
double GetOmegaEarth(void) const
Retrieve Earth's angular velocity.
Definition: julian-date.cc:174
bool operator!=(const JulianDate &jd) const
operator != (compare Julian dates).
Definition: julian-date.cc:384
static Time Dut1(uint32_t daysInPosix)
Retrieve the DUT1 (UT1 - UTC) value for a given day.
Definition: julian-date.cc:424
DateTime::TimeSystem TimeSystem
equivalent to C++11 using TimeSystem = DateTime::TimeSystem.
Definition: julian-date.h:81
std::pair< double, double > GetPolarMotion(void) const
Retrieve the polar motion cofficients measured/predicted.
Definition: julian-date.cc:161
DateTime GregorianDate(void) const
Convert into Gregorian calendar.
Definition: julian-date.cc:433
bool operator<=(const JulianDate &jd) const
operator <= (compare Julian dates).
Definition: julian-date.cc:348
friend std::ostream & operator<<(std::ostream &os, const JulianDate &jd)
operator << (print as GregorianDate).
Definition: julian-date.cc:393
bool operator>=(const JulianDate &jd) const
operator >= (compare Julian dates).
Definition: julian-date.cc:366
void operator+=(const Time &t)
operator += (positive time adjustment).
Definition: julian-date.cc:292
static const uint32_t J2000Epoch
1 Jan 2000, 12h
Definition: julian-date.h:88
void operator-=(const Time &t)
operator -= (negative time adjustment).
Definition: julian-date.cc:324
static const uint32_t Posix1992
1 Jan 1992 (POSIX days)
Definition: julian-date.h:89
static const uint32_t MaxYear
Maximum year supported.
Definition: julian-date.h:86
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
The DateTime struct.
Definition: julian-date.h:46
uint32_t year
Definition: julian-date.h:57
uint32_t day
Definition: julian-date.h:57
uint32_t minutes
Definition: julian-date.h:58
@ POSIX
Unix/POSIX Time.
Definition: julian-date.h:54
@ UTC
Coordinated Universal Time [French: Temps Universel Coordonné].
Definition: julian-date.h:49
@ TAI
International Atomic Time [French: Temps Atomique International].
Definition: julian-date.h:51
@ TT
Terrestrial Time.
Definition: julian-date.h:52
@ UT1
Universal Time.
Definition: julian-date.h:50
@ GPST
Global Positioning System (GPS) Time.
Definition: julian-date.h:53
TimeSystem time_system
Definition: julian-date.h:59
uint32_t seconds
Definition: julian-date.h:58
uint32_t month
Definition: julian-date.h:57
uint32_t hours
Definition: julian-date.h:58
uint32_t millisecs
Definition: julian-date.h:58
friend std::ostream & operator<<(std::ostream &os, DateTime::TimeSystem ts)
Definition: julian-date.cc:60