26#include <fmt/ostream.h>
29#include <nlohmann/json.hpp>
30using json = nlohmann::json;
66constexpr long double EPSILON = std::max(1e-17L, 10 * std::numeric_limits<long double>::epsilon());
97 return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
170 if (this->mjd_frac >= 1.0L)
172 this->mjd_day +=
static_cast<int32_t
>(this->
mjd_frac);
173 this->mjd_frac -=
static_cast<int32_t
>(this->
mjd_frac);
175 while (this->mjd_frac < 0.0L)
177 this->mjd_frac += 1.0L;
193 gcem::abs(diffDays) == 1)
205 return !(*
this == rhs);
212 return *
this < rhs || *
this == rhs;
219 return *
this > rhs || *
this == rhs;
234 return !(*
this <= rhs);
238 explicit operator std::string()
const;
253 if (this->jd_frac >= 1.0L)
255 this->jd_day +=
static_cast<int32_t
>(this->
jd_frac);
256 this->jd_frac -=
static_cast<int32_t
>(this->
jd_frac);
258 while (this->jd_frac < 0.0L)
260 this->jd_frac += 1.0L;
276 gcem::abs(diffDays) == 1)
288 return !(*
this == rhs);
295 return *
this < rhs || *
this == rhs;
302 return *
this > rhs || *
this == rhs;
317 return !(*
this <= rhs);
321 explicit operator std::string()
const;
343 while (this->tow < 0.0L)
354 while (this->gpsWeek < 0)
371 gcem::abs(diffWeeks) == 1)
382 return !(*
this == rhs);
389 return *
this < rhs || *
this == rhs;
396 return *
this > rhs || *
this == rhs;
413 return !(*
this <= rhs);
417 explicit operator std::string()
const;
441 if (digits >= 0) { this->sec = math::round(this->sec,
static_cast<size_t>(digits)); }
447 while (this->sec < 0.0L)
452 if (digits >= 0) { this->sec = math::round(this->sec,
static_cast<size_t>(digits)); }
459 while (this->min < 0)
470 while (this->hour < 0)
487 while (this->day < 1)
498 while (this->month < 1)
527 return !(*
this == rhs);
534 return *
this < rhs || *
this == rhs;
541 return *
this > rhs || *
this == rhs;
561 return !(*
this <= rhs);
565 explicit operator std::string()
const;
587 while (this->sod < 0)
598 while (this->doy < 1)
615 gcem::abs(diffDays) == 1)
627 return !(*
this == rhs);
634 return *
this < rhs || *
this == rhs;
641 return *
this > rhs || *
this == rhs;
658 return !(*
this <= rhs);
662 explicit operator std::string()
const;
687 : _mjd(jd.jd_day - InsTimeUtil::DIFF_MJD_TO_JD_DAYS, jd.jd_frac - InsTimeUtil::DIFF_MJD_TO_JD_FRAC)
713 int32_t y = yearMonthDayHMS.
year + 4800 - a;
716 auto jd_day =
static_cast<int32_t
>(yearMonthDayHMS.
day
717 + gcem::floor((153.0 *
static_cast<double>(m) + 2.0) / 5.0)
719 + gcem::floor(
static_cast<double>(y) / 4.0)
720 - gcem::floor(
static_cast<double>(y) / 100.0)
721 + gcem::floor(
static_cast<double>(y) / 400.0)
723 auto jd_frac = (yearMonthDayHMS.
sec
738 auto year = yearDoySod.
year;
739 auto doy = yearDoySod.
doy;
740 auto sod = yearDoySod.
sod;
759 constexpr InsTime(int32_t gpsCycle, int32_t gpsWeek,
long double tow,
TimeSystem timesys = GPST)
770 constexpr InsTime(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t min,
long double sec,
TimeSystem timesys = UTC)
792 return { _mjd.
mjd_day, mjdFrac };
805 return { jd_day, jd_frac };
821 return { 0, 0, tow };
840 double a = 32044.0 + jd.
jd_day;
841 double b = gcem::floor((4.0 * a + 3.0) / 146097.0);
842 double c = a - gcem::floor((b * 146097.0) / 4.0);
844 double d = gcem::floor((4.0 * c + 3.0) / 1461.0);
845 double e = c - gcem::floor((1461.0 * d) / 4.0);
846 double m = gcem::floor((5.0 * e + 2.0) / 153.0);
848 auto day =
static_cast<uint16_t
>(e - gcem::floor((153.0 * m + 2.0) / 5.0) + 1);
849 auto month =
static_cast<uint16_t
>(m + 3 - 12 * gcem::floor(m / 10.0));
850 auto year =
static_cast<uint16_t
>(b * 100 + d - 4800.0 + gcem::floor(m / 10.0));
854 return { year, month, day, 0, 0, sec, digits };
864 auto year = yearMonthDayHMS.
year;
867 + yearMonthDayHMS.
sec
871 for (int32_t i = 1; i < yearMonthDayHMS.
month; i++)
875 doy += yearMonthDayHMS.
day;
877 return { year, doy, sod };
996 return std::chrono::duration<long double>(diffSec);
1004 auto duration_mjd_frac = std::chrono::duration<long double, std::ratio<InsTimeUtil::SECONDS_PER_DAY>>(duration).count();
1006 this->_mjd.mjd_frac + duration_mjd_frac);
1015 auto duration_mjd_frac = std::chrono::duration<long double, std::ratio<InsTimeUtil::SECONDS_PER_DAY>>(duration).count();
1017 this->_mjd.mjd_frac - duration_mjd_frac);
1027 return InsTime(time) += duration;
1036 return InsTime(time) -= duration;
1042 explicit operator std::string()
const;
1045 [[nodiscard]]
constexpr bool empty()
const
1069 *
this += std::chrono::duration<long double>(diff);
1148struct hash<NAV::InsTime>
1157 return hash1 | (hash2 << 32);
1162#ifndef DOXYGEN_IGNORE
1165struct fmt::formatter<NAV::InsTime_MJD> : ostream_formatter
1168struct fmt::formatter<NAV::InsTime_JD> : ostream_formatter
1171struct fmt::formatter<NAV::InsTime_GPSweekTow> : ostream_formatter
1174struct fmt::formatter<NAV::InsTime_YMDHMS> : ostream_formatter
1177struct fmt::formatter<NAV::InsTime_YDoySod> : ostream_formatter
1180struct fmt::formatter<NAV::InsTime> : ostream_formatter
std::ostream & operator<<(std::ostream &os, const NAV::CycleSlipDetector::Result &obj)
Stream insertion operator overload.
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
TimeSystem_
List of all time systems.
Definition TimeSystem.hpp:26
@ IRNSST
Indian Regional Navigation Satellite System Time.
Definition TimeSystem.hpp:34
@ GST
Galileo System Time.
Definition TimeSystem.hpp:31
@ BDT
BeiDou Time.
Definition TimeSystem.hpp:32
@ GLNT
GLONASS Time (GLONASST)
Definition TimeSystem.hpp:30
@ TimeSys_None
No Time system.
Definition TimeSystem.hpp:27
@ QZSST
Quasi-Zenith Satellite System Time.
Definition TimeSystem.hpp:33
@ GPST
GPS Time.
Definition TimeSystem.hpp:29
@ UTC
Coordinated Universal Time.
Definition TimeSystem.hpp:28
The class is responsible for all time-related tasks.
Definition InsTime.hpp:667
constexpr InsTime(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t min, long double sec, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:770
constexpr InsTime(const InsTime &)=default
Copy constructor.
constexpr InsTime()=default
Default Constructor.
constexpr InsTime_JD toJD(TimeSystem timesys=UTC) const
Converts this time object into a different format.
Definition InsTime.hpp:798
constexpr bool operator>=(const InsTime &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:975
constexpr InsTime & operator+=(const std::chrono::duration< long double > &duration)
Adds a duration to this time point.
Definition InsTime.hpp:1002
constexpr InsTime & operator=(InsTime &&)=default
Move assignment operator.
constexpr InsTime_YDoySod toYDoySod(TimeSystem timesys=UTC) const
Converts this time object into a different format.
Definition InsTime.hpp:860
constexpr InsTime & operator=(const InsTime &)=default
Copy assignment operator.
constexpr InsTime(int32_t gpsCycle, int32_t gpsWeek, long double tow, TimeSystem timesys=GPST)
Constructor.
Definition InsTime.hpp:759
constexpr int differenceToUTC(TimeSystem timesys) const
Returns the time difference in [s] of a time system and UTC.
Definition InsTime.hpp:1074
constexpr InsTime_GPSweekTow toGPSweekTow(TimeSystem timesys=GPST) const
Converts this time object into a different format.
Definition InsTime.hpp:811
constexpr friend std::chrono::duration< long double > operator-(const InsTime &lhs, const InsTime &rhs)
Substracts 2 points in time.
Definition InsTime.hpp:991
constexpr InsTime(const InsTime_GPSweekTow &gpsWeekTow, TimeSystem timesys=GPST)
Constructor.
Definition InsTime.hpp:695
constexpr InsTime & operator-=(const std::chrono::duration< long double > &duration)
Substracts a duration to this time point.
Definition InsTime.hpp:1013
constexpr InsTime(const InsTime_YDoySod &yearDoySod, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:736
constexpr friend InsTime operator-(const InsTime &time, const std::chrono::duration< long double > &duration)
Substracts a duration from a time point.
Definition InsTime.hpp:1034
constexpr bool operator<(const InsTime &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:979
static constexpr uint16_t leapGps2UTC(const InsTime_JD &jd)
Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_JD object.
Definition InsTime.hpp:938
constexpr InsTime_YMDHMS toYMDHMS(TimeSystem timesys=UTC, int digits=-1) const
Converts this time object into a different format.
Definition InsTime.hpp:828
constexpr bool operator>(const InsTime &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:983
static constexpr uint16_t leapGps2UTC(const InsTime_GPSweekTow &gpsWeekTow)
Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_GPSweekTow object.
Definition InsTime.hpp:914
~InsTime()=default
Destructor.
constexpr uint16_t leapGps2UTC() const
Returns the current number of leap seconds (offset GPST to UTC)
Definition InsTime.hpp:898
constexpr InsTime_MJD toMJD(TimeSystem timesys=UTC) const
Converts this time object into a different format.
Definition InsTime.hpp:789
constexpr InsTime(const InsTime_MJD &mjd, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:677
constexpr bool empty() const
Checks if the Time object has a value.
Definition InsTime.hpp:1045
static constexpr uint16_t leapGps2UTC(const InsTime &insTime)
Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime object.
Definition InsTime.hpp:906
static constexpr uint16_t leapGps2UTC(const InsTime_YDoySod &yearDoySod)
Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_YDoySod object.
Definition InsTime.hpp:922
constexpr InsTime(const InsTime_YMDHMS &yearMonthDayHMS, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:710
constexpr bool operator!=(const InsTime &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:967
constexpr friend InsTime operator+(const InsTime &time, const std::chrono::duration< long double > &duration)
Adds a duration to a time point.
Definition InsTime.hpp:1025
void MakeTimeFromGloOrbit(double UTC_sec)
Adds the difference [seconds] between toe (OBRIT-0 last element) and toc (ORBIT-0 first element) to t...
Definition InsTime.hpp:1060
constexpr InsTime toFullDay() const
Returns the current time rounded/cutted to a full day (changes time to 0:0:0h UTC of current day)
Definition InsTime.hpp:882
constexpr long double toUnixTime() const
Converts this time object into a UNIX timestamp in [s].
Definition InsTime.hpp:888
constexpr bool operator<=(const InsTime &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:971
constexpr bool operator==(const InsTime &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:963
void reset()
Resets the InsTime object.
Definition InsTime.hpp:1051
constexpr bool isLeapYear() const
Checks if the current time is a leap year.
Definition InsTime.hpp:953
static constexpr uint16_t leapGps2UTC(const InsTime_MJD &mjd_in)
Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_MJD object.
Definition InsTime.hpp:946
constexpr InsTime(const InsTime_JD &jd, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:686
constexpr InsTime(InsTime &&)=default
Move constructor.
static constexpr uint16_t leapGps2UTC(const InsTime_YMDHMS &yearMonthDayHMS)
Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_YMDHMS object.
Definition InsTime.hpp:930
Time System defintions.
Definition TimeSystem.hpp:39
constexpr long double EPSILON
Definition InsTime.hpp:66
constexpr int32_t MINUTES_PER_HOUR
Minutes / Hour.
Definition InsTime.hpp:54
constexpr long double DIFF_MJD_TO_JD_FRAC
Difference of the fraction between MJD and JD.
Definition InsTime.hpp:47
constexpr int32_t MINUTES_PER_DAY
Minutes / Day.
Definition InsTime.hpp:55
constexpr int32_t SECONDS_PER_DAY
Seconds / Day.
Definition InsTime.hpp:59
constexpr int32_t daysInMonth(int32_t month, int32_t year)
Returns the number of days in the specified month of the year.
Definition InsTime.hpp:104
constexpr int32_t END_OF_THE_CENTURY_MJD
Modified Julian Date of the end of the century (15.01.2954)
Definition InsTime.hpp:40
constexpr int32_t SECONDS_PER_WEEK
Seconds / Week.
Definition InsTime.hpp:60
constexpr int32_t DIFF_TO_6_1_1980_MJD
06.01.1980 in Modified Julian Date
Definition InsTime.hpp:42
constexpr int32_t DAYS_PER_WEEK
Days / Week.
Definition InsTime.hpp:51
constexpr bool isLeapYear(int32_t year)
Returns true if the provided year is a leap year, false otherwise.
Definition InsTime.hpp:95
constexpr int32_t MONTHS_PER_YEAR
Months / Year.
Definition InsTime.hpp:49
constexpr int32_t DAYS_PER_YEAR
Days / Year.
Definition InsTime.hpp:50
constexpr int32_t DIFF_MJD_TO_JD_DAYS
Difference of the days between MJD and JD.
Definition InsTime.hpp:46
constexpr int32_t HOURS_PER_DAY
Hours / Day.
Definition InsTime.hpp:52
constexpr int32_t HOURS_PER_WEEK
Hours / Week.
Definition InsTime.hpp:53
constexpr int32_t MINUTES_PER_WEEK
Minutes / Week.
Definition InsTime.hpp:56
constexpr std::array< int32_t, 20 > GPS_LEAP_SEC_MJD
Maps GPS leap seconds to a time: array<mjd_day>, index + 1 is amount of leap seconds.
Definition InsTime.hpp:69
constexpr int32_t WEEKS_PER_GPS_CYCLE
Weeks per GPS cycle.
Definition InsTime.hpp:41
constexpr int32_t DIFF_BDT_WEEK_TO_GPST_WEEK
BeiDou starts zero at 1-Jan-2006 and GPS starts 6-Jan-1980.
Definition InsTime.hpp:44
constexpr int32_t SECONDS_PER_HOUR
Seconds / Hour.
Definition InsTime.hpp:58
constexpr int32_t SECONDS_PER_MINUTE
Seconds / Minute.
Definition InsTime.hpp:57
constexpr int32_t DIFF_TO_1_1_1970_MJD
01.01.1970 00:00:00 UTC in Modified Julian Date (UNIX epoch)
Definition InsTime.hpp:43
GPS week and time of week in GPS standard time [GPST].
Definition InsTime.hpp:326
constexpr bool operator>=(const InsTime_GPSweekTow &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:394
constexpr bool operator!=(const InsTime_GPSweekTow &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:380
int32_t gpsCycle
Contains GPS cycle in GPS standard time [GPST].
Definition InsTime.hpp:327
constexpr bool operator<=(const InsTime_GPSweekTow &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:387
int32_t gpsWeek
Contains GPS week in GPS standard time [GPST].
Definition InsTime.hpp:328
constexpr InsTime_GPSweekTow(int32_t gpsCycle, int32_t gpsWeek, long double tow)
Constructor.
Definition InsTime.hpp:335
constexpr bool operator<(const InsTime_GPSweekTow &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:401
constexpr bool operator>(const InsTime_GPSweekTow &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:411
constexpr bool operator==(const InsTime_GPSweekTow &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:364
long double tow
Contains GPS time of week in seconds in GPS standard time [GPST].
Definition InsTime.hpp:329
Julien Date [UTC].
Definition InsTime.hpp:243
int32_t jd_day
Full days since 1. January −4712 [UTC].
Definition InsTime.hpp:244
constexpr bool operator<(const InsTime_JD &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:307
constexpr InsTime_JD(int32_t jd_day, long double jd_frac)
Constructor.
Definition InsTime.hpp:250
constexpr bool operator>=(const InsTime_JD &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:300
constexpr bool operator>(const InsTime_JD &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:315
long double jd_frac
Decimal fractions of a day of the Julien Date [UTC].
Definition InsTime.hpp:245
constexpr bool operator<=(const InsTime_JD &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:293
constexpr bool operator!=(const InsTime_JD &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:286
constexpr bool operator==(const InsTime_JD &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:268
Modified Julien Date [UTC].
Definition InsTime.hpp:157
constexpr bool operator>=(const InsTime_MJD &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:217
constexpr bool operator!=(const InsTime_MJD &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:203
long double mjd_frac
Decimal fractions of a day of the Modified Julien Date [UTC].
Definition InsTime.hpp:159
constexpr bool operator>(const InsTime_MJD &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:232
constexpr InsTime_MJD(int32_t mjd_day, long double mjd_frac)
Constructor.
Definition InsTime.hpp:167
constexpr bool operator==(const InsTime_MJD &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:185
constexpr bool operator<=(const InsTime_MJD &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:210
constexpr bool operator<(const InsTime_MJD &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:224
constexpr InsTime_MJD()=default
Default constructor.
int32_t mjd_day
Full days since 17. November 1858 [UTC].
Definition InsTime.hpp:158
GPS year and day of year in GPS standard time [GPST].
Definition InsTime.hpp:570
long double sod
Contains second of day in GPS standard time [GPST].
Definition InsTime.hpp:573
constexpr bool operator<(const InsTime_YDoySod &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:646
int32_t year
Contains year in GPS standard time [GPST].
Definition InsTime.hpp:571
constexpr bool operator!=(const InsTime_YDoySod &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:625
constexpr bool operator>(const InsTime_YDoySod &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:656
constexpr bool operator==(const InsTime_YDoySod &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:608
int32_t doy
Contains day of year in GPS standard time [GPST].
Definition InsTime.hpp:572
constexpr bool operator<=(const InsTime_YDoySod &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:632
constexpr bool operator>=(const InsTime_YDoySod &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:639
constexpr InsTime_YDoySod(int32_t year, int32_t doy, long double sod)
Constructor.
Definition InsTime.hpp:579
Universal Time Coordinated [UTC].
Definition InsTime.hpp:422
int32_t min
Contains minute in Universal Time Coordinated [UTC].
Definition InsTime.hpp:427
constexpr bool operator>=(const InsTime_YMDHMS &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:539
int32_t year
Contains year in Universal Time Coordinated [UTC].
Definition InsTime.hpp:423
constexpr bool operator<(const InsTime_YMDHMS &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:546
constexpr InsTime_YMDHMS(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t min, long double sec, int digits=-1)
Constructor.
Definition InsTime.hpp:438
constexpr bool operator==(const InsTime_YMDHMS &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:508
constexpr bool operator!=(const InsTime_YMDHMS &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:525
long double sec
Contains second in Universal Time Coordinated [UTC].
Definition InsTime.hpp:428
int32_t month
Contains month in Universal Time Coordinated [UTC].
Definition InsTime.hpp:424
constexpr bool operator>(const InsTime_YMDHMS &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:559
int32_t hour
Contains hour in Universal Time Coordinated [UTC].
Definition InsTime.hpp:426
int32_t day
Contains day in Universal Time Coordinated [UTC].
Definition InsTime.hpp:425
constexpr bool operator<=(const InsTime_YMDHMS &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:532
std::size_t operator()(const NAV::InsTime &t) const
Hash function for InsTime.
Definition InsTime.hpp:1152