0.3.0
Loading...
Searching...
No Matches
InsTime.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
17
18#pragma once
19
20#include <cstdint>
21#include <string>
22#include <array>
23#include <limits>
24#include <iostream>
25#include <chrono>
26
27#include <fmt/ostream.h>
28#include "gcem.hpp"
29
30#include <nlohmann/json.hpp>
31using json = nlohmann::json;
32
33#include "TimeSystem.hpp"
35
36namespace NAV
37{
39namespace InsTimeUtil
40{
41constexpr int32_t END_OF_THE_CENTURY_MJD = 400000;
42constexpr int32_t WEEKS_PER_GPS_CYCLE = 1024;
43constexpr int32_t DIFF_TO_6_1_1980_MJD = 44244;
44constexpr int32_t DIFF_TO_1_1_1970_MJD = 40587;
45constexpr int32_t DIFF_BDT_WEEK_TO_GPST_WEEK = 1356;
46
47constexpr int32_t DIFF_MJD_TO_JD_DAYS = 2400000;
48constexpr long double DIFF_MJD_TO_JD_FRAC = 0.5L;
49
50constexpr int32_t MONTHS_PER_YEAR = 12;
51constexpr int32_t DAYS_PER_YEAR = 365;
52constexpr int32_t DAYS_PER_WEEK = 7;
53constexpr int32_t HOURS_PER_DAY = 24;
55constexpr int32_t MINUTES_PER_HOUR = 60;
58constexpr int32_t SECONDS_PER_MINUTE = 60;
62
67constexpr long double EPSILON = std::max(1e-17L, 10 * std::numeric_limits<long double>::epsilon());
68
70constexpr std::array<int32_t, 20> GPS_LEAP_SEC_MJD = {
71 0, // + 0 at 1 Jan 1980 and before
72 44786, // + 1 at 1 Jul 1981 = diff UTC-TAI: 20
73 45151, // + 2 at 1 Jul 1982 = diff UTC-TAI: 21
74 45516, // + 3 at 1 Jul 1983 = diff UTC-TAI: 22
75 46247, // + 4 at 1 Jul 1985 = diff UTC-TAI: 23
76 47161, // + 5 at 1 Jan 1988 = diff UTC-TAI: 24
77 47892, // + 6 at 1 Jan 1990 = diff UTC-TAI: 25
78 48257, // + 7 at 1 Jan 1991 = diff UTC-TAI: 26
79 48804, // + 8 at 1 Jul 1992 = diff UTC-TAI: 27
80 49169, // + 9 at 1 Jul 1993 = diff UTC-TAI: 28
81 49534, // +10 at 1 Jul 1994 = diff UTC-TAI: 29
82 50083, // +11 at 1 Jan 1996 = diff UTC-TAI: 30
83 50630, // +12 at 1 Jul 1997 = diff UTC-TAI: 31
84 51179, // +13 at 1 Jan 1999 = diff UTC-TAI: 32
85 53736, // +14 at 1 Jan 2006 = diff UTC-TAI: 33
86 54832, // +15 at 1 Jan 2009 = diff UTC-TAI: 34
87 56109, // +16 at 1 Jul 2012 = diff UTC-TAI: 35
88 57204, // +17 at 1 Jul 2015 = diff UTC-TAI: 36
89 57754, // +18 at 1 Jan 2017 = diff UTC-TAI: 37
90 99999, // future
91};
92
96constexpr bool isLeapYear(int32_t year)
97{
98 return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
99}
100
105constexpr int32_t daysInMonth(int32_t month, int32_t year)
106{
107 --month; // Make month 0 based
108 if (month >= InsTimeUtil::MONTHS_PER_YEAR)
109 {
110 year += month / InsTimeUtil::MONTHS_PER_YEAR;
112 }
113 while (month < 0)
114 {
115 month += MONTHS_PER_YEAR;
116 year--;
117 }
118 ++month; // Make month 1 based
119
120 switch (month)
121 {
122 case 1:
123 return 31;
124 case 2:
125 if (isLeapYear(year))
126 {
127 return 29;
128 }
129 return 28;
130 case 3:
131 return 31;
132 case 4:
133 return 30;
134 case 5:
135 return 31;
136 case 6:
137 return 30;
138 case 7:
139 return 31;
140 case 8:
141 return 31;
142 case 9:
143 return 30;
144 case 10:
145 return 31;
146 case 11:
147 return 30;
148 case 12:
149 return 31;
150 default:
151 return 366;
152 }
153}
154
159constexpr std::string formatDuration(double seconds, size_t digits = 9)
160{
161 std::string str;
162 if (seconds >= SECONDS_PER_DAY)
163 {
164 auto days = static_cast<int32_t>(seconds) / SECONDS_PER_DAY;
165 str += fmt::format("{}{:d}d", str.empty() ? "" : " ", days);
166 seconds -= days * SECONDS_PER_DAY;
167 }
168 if (seconds >= SECONDS_PER_HOUR)
169 {
170 auto hours = static_cast<int32_t>(seconds) / SECONDS_PER_HOUR;
171 str += fmt::format("{}{:d}h", str.empty() ? "" : " ", hours);
172 seconds -= hours * SECONDS_PER_HOUR;
173 }
174 if (seconds >= SECONDS_PER_MINUTE)
175 {
176 auto minutes = static_cast<int32_t>(seconds) / SECONDS_PER_MINUTE;
177 str += fmt::format("{}{:d}m", str.empty() ? "" : " ", minutes);
178 seconds -= minutes * SECONDS_PER_MINUTE;
179 }
180 if (seconds > 1e-9)
181 {
182 size_t d = 0;
183 for (; d < digits + 1; d++)
184 {
185 if (2.0 * std::abs(std::round(seconds * std::pow(10.0, d)) - seconds * std::pow(10.0, d))
186 < std::pow(10.0, -(static_cast<double>(digits) - static_cast<double>(d))))
187 {
188 break;
189 }
190 }
191 str += fmt::format("{}{:.{}f}s", str.empty() ? "" : " ", seconds, d);
192 }
193 return str;
194}
195
196} // namespace InsTimeUtil
197
200{
201 int32_t mjd_day = 0;
202 long double mjd_frac = 0.0L;
203
205 constexpr InsTime_MJD() = default;
206
210 constexpr InsTime_MJD(int32_t mjd_day, long double mjd_frac)
212 {
213 if (this->mjd_frac >= 1.0L)
214 {
215 this->mjd_day += static_cast<int32_t>(this->mjd_frac);
216 this->mjd_frac -= static_cast<int32_t>(this->mjd_frac);
217 }
218 while (this->mjd_frac < 0.0L)
219 {
220 this->mjd_frac += 1.0L;
221 this->mjd_day--;
222 }
223 }
224
228 constexpr bool operator==(const InsTime_MJD& rhs) const
229 {
230 if (mjd_day == rhs.mjd_day)
231 {
232 auto difference = gcem::abs(mjd_frac - rhs.mjd_frac);
233 return difference <= InsTimeUtil::EPSILON;
234 }
235 if (auto diffDays = mjd_day - rhs.mjd_day;
236 gcem::abs(diffDays) == 1)
237 {
238 auto difference = 1 + diffDays * (mjd_frac - rhs.mjd_frac);
239 return difference <= InsTimeUtil::EPSILON;
240 }
241 return false;
242 }
243
246 constexpr bool operator!=(const InsTime_MJD& rhs) const
247 {
248 return !(*this == rhs);
249 }
250
253 constexpr bool operator<=(const InsTime_MJD& rhs) const
254 {
255 return *this < rhs || *this == rhs;
256 }
257
260 constexpr bool operator>=(const InsTime_MJD& rhs) const
261 {
262 return *this > rhs || *this == rhs;
263 }
264
267 constexpr bool operator<(const InsTime_MJD& rhs) const
268 {
269 return (mjd_day < rhs.mjd_day || (mjd_day == rhs.mjd_day && mjd_frac < rhs.mjd_frac))
270 && *this != rhs;
271 }
272
275 constexpr bool operator>(const InsTime_MJD& rhs) const
276 {
277 return !(*this <= rhs);
278 }
279
281 explicit operator std::string() const;
282};
283
286{
287 int32_t jd_day{};
288 long double jd_frac{};
289
293 constexpr InsTime_JD(int32_t jd_day, long double jd_frac)
295 {
296 if (this->jd_frac >= 1.0L)
297 {
298 this->jd_day += static_cast<int32_t>(this->jd_frac);
299 this->jd_frac -= static_cast<int32_t>(this->jd_frac);
300 }
301 while (this->jd_frac < 0.0L)
302 {
303 this->jd_frac += 1.0L;
304 this->jd_day--;
305 }
306 }
307
311 constexpr bool operator==(const InsTime_JD& rhs) const
312 {
313 if (jd_day == rhs.jd_day)
314 {
315 auto difference = gcem::abs(jd_frac - rhs.jd_frac);
316 return difference <= InsTimeUtil::EPSILON;
317 }
318 if (auto diffDays = jd_day - rhs.jd_day;
319 gcem::abs(diffDays) == 1)
320 {
321 auto difference = 1 + diffDays * (jd_frac - rhs.jd_frac);
322 return difference <= InsTimeUtil::EPSILON;
323 }
324 return false;
325 }
326
329 constexpr bool operator!=(const InsTime_JD& rhs) const
330 {
331 return !(*this == rhs);
332 }
333
336 constexpr bool operator<=(const InsTime_JD& rhs) const
337 {
338 return *this < rhs || *this == rhs;
339 }
340
343 constexpr bool operator>=(const InsTime_JD& rhs) const
344 {
345 return *this > rhs || *this == rhs;
346 }
347
350 constexpr bool operator<(const InsTime_JD& rhs) const
351 {
352 return (jd_day < rhs.jd_day || (jd_day == rhs.jd_day && jd_frac < rhs.jd_frac))
353 && *this != rhs;
354 }
355
358 constexpr bool operator>(const InsTime_JD& rhs) const
359 {
360 return !(*this <= rhs);
361 }
362
364 explicit operator std::string() const;
365};
366
369{
370 int32_t gpsCycle{};
371 int32_t gpsWeek{};
372 long double tow{};
373
378 constexpr InsTime_GPSweekTow(int32_t gpsCycle, int32_t gpsWeek, long double tow)
380 {
381 if (this->tow >= InsTimeUtil::SECONDS_PER_WEEK)
382 {
383 this->gpsWeek += static_cast<int32_t>(this->tow / InsTimeUtil::SECONDS_PER_WEEK);
384 this->tow = gcem::fmod(this->tow, InsTimeUtil::SECONDS_PER_WEEK);
385 }
386 while (this->tow < 0.0L)
387 {
389 this->gpsWeek--;
390 }
391
392 if (this->gpsWeek >= InsTimeUtil::WEEKS_PER_GPS_CYCLE)
393 {
394 this->gpsCycle += this->gpsWeek / InsTimeUtil::WEEKS_PER_GPS_CYCLE;
395 this->gpsWeek %= InsTimeUtil::WEEKS_PER_GPS_CYCLE;
396 }
397 while (this->gpsWeek < 0)
398 {
399 this->gpsWeek += InsTimeUtil::WEEKS_PER_GPS_CYCLE;
400 this->gpsCycle--;
401 }
402 };
403
407 constexpr bool operator==(const InsTime_GPSweekTow& rhs) const
408 {
409 if (gpsCycle == rhs.gpsCycle && gpsWeek == rhs.gpsWeek)
410 {
411 return gcem::abs(tow - rhs.tow) <= InsTimeUtil::EPSILON;
412 }
414 gcem::abs(diffWeeks) == 1)
415 {
416 return gcem::abs(tow + diffWeeks * InsTimeUtil::SECONDS_PER_WEEK - rhs.tow) <= InsTimeUtil::EPSILON;
417 }
418 return false;
419 }
420
423 constexpr bool operator!=(const InsTime_GPSweekTow& rhs) const
424 {
425 return !(*this == rhs);
426 }
427
430 constexpr bool operator<=(const InsTime_GPSweekTow& rhs) const
431 {
432 return *this < rhs || *this == rhs;
433 }
434
437 constexpr bool operator>=(const InsTime_GPSweekTow& rhs) const
438 {
439 return *this > rhs || *this == rhs;
440 }
441
444 constexpr bool operator<(const InsTime_GPSweekTow& rhs) const
445 {
446 return (gpsCycle < rhs.gpsCycle
447 || (gpsCycle == rhs.gpsCycle && gpsWeek < rhs.gpsWeek)
448 || (gpsCycle == rhs.gpsCycle && gpsWeek == rhs.gpsWeek && tow < rhs.tow))
449 && *this != rhs;
450 }
451
454 constexpr bool operator>(const InsTime_GPSweekTow& rhs) const
455 {
456 return !(*this <= rhs);
457 }
458
460 explicit operator std::string() const;
461};
462
465{
466 int32_t year{};
467 int32_t month{};
468 int32_t day{};
469 int32_t hour{};
470 int32_t min{};
471 long double sec{};
472
481 constexpr InsTime_YMDHMS(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t min, long double sec, int digits = -1)
483 {
484 if (digits >= 0) { this->sec = math::round(this->sec, static_cast<size_t>(digits)); }
485 if (this->sec >= InsTimeUtil::SECONDS_PER_MINUTE)
486 {
487 this->min += static_cast<int32_t>(this->sec / InsTimeUtil::SECONDS_PER_MINUTE);
488 this->sec = gcem::fmod(this->sec, InsTimeUtil::SECONDS_PER_MINUTE);
489 }
490 while (this->sec < 0.0L)
491 {
493 this->min--;
494 }
495 if (digits >= 0) { this->sec = math::round(this->sec, static_cast<size_t>(digits)); }
496
497 if (this->min >= InsTimeUtil::MINUTES_PER_HOUR)
498 {
499 this->hour += this->min / InsTimeUtil::MINUTES_PER_HOUR;
501 }
502 while (this->min < 0)
503 {
505 this->hour--;
506 }
507
508 if (this->hour >= InsTimeUtil::HOURS_PER_DAY)
509 {
510 this->day += this->hour / InsTimeUtil::HOURS_PER_DAY;
511 this->hour %= InsTimeUtil::HOURS_PER_DAY;
512 }
513 while (this->hour < 0)
514 {
515 this->hour += InsTimeUtil::HOURS_PER_DAY;
516 this->day--;
517 }
518
519 while (this->day >= InsTimeUtil::DAYS_PER_YEAR + static_cast<int32_t>(InsTimeUtil::isLeapYear(this->year)))
520 {
521 this->day -= InsTimeUtil::DAYS_PER_YEAR + static_cast<int32_t>(InsTimeUtil::isLeapYear(this->year));
522 this->year++;
523 }
524
525 while (this->day > InsTimeUtil::daysInMonth(this->month, this->year))
526 {
527 this->day -= InsTimeUtil::daysInMonth(this->month, this->year);
528 this->month++;
529 }
530 while (this->day < 1)
531 {
532 this->month--;
533 this->day += InsTimeUtil::daysInMonth(this->month, this->year);
534 }
535
536 while (this->month > InsTimeUtil::MONTHS_PER_YEAR)
537 {
538 this->month -= InsTimeUtil::MONTHS_PER_YEAR;
539 this->year++;
540 }
541 while (this->month < 1)
542 {
543 this->month += InsTimeUtil::MONTHS_PER_YEAR;
544 this->year--;
545 }
546 }
547
551 constexpr bool operator==(const InsTime_YMDHMS& rhs) const
552 {
553 if (year == rhs.year && month == rhs.month && day == rhs.day && hour == rhs.hour && min == rhs.min)
554 {
555 return gcem::abs(sec - rhs.sec) <= InsTimeUtil::EPSILON;
556 }
557 InsTime_YMDHMS this_plus = InsTime_YMDHMS(this->year, this->month, this->day, this->hour, this->min, this->sec + 10);
558 InsTime_YMDHMS rhs_plus = InsTime_YMDHMS(rhs.year, rhs.month, rhs.day, rhs.hour, rhs.min, rhs.sec + 10);
559 if (this_plus.year == rhs_plus.year && this_plus.month == rhs_plus.month && this_plus.day == rhs_plus.day && this_plus.hour == rhs_plus.hour && this_plus.min == rhs_plus.min)
560 {
561 return gcem::abs(this_plus.sec - rhs_plus.sec) <= InsTimeUtil::EPSILON;
562 }
563 return false;
564 }
565
568 constexpr bool operator!=(const InsTime_YMDHMS& rhs) const
569 {
570 return !(*this == rhs);
571 }
572
575 constexpr bool operator<=(const InsTime_YMDHMS& rhs) const
576 {
577 return *this < rhs || *this == rhs;
578 }
579
582 constexpr bool operator>=(const InsTime_YMDHMS& rhs) const
583 {
584 return *this > rhs || *this == rhs;
585 }
586
589 constexpr bool operator<(const InsTime_YMDHMS& rhs) const
590 {
591 return (year < rhs.year
592 || (year == rhs.year && month < rhs.month)
593 || (year == rhs.year && month == rhs.month && day < rhs.day)
594 || (year == rhs.year && month == rhs.month && day == rhs.day && hour < rhs.hour)
595 || (year == rhs.year && month == rhs.month && day == rhs.day && hour == rhs.hour && min < rhs.min)
596 || (year == rhs.year && month == rhs.month && day == rhs.day && hour == rhs.hour && min == rhs.min && sec < rhs.sec))
597 && *this != rhs;
598 }
599
602 constexpr bool operator>(const InsTime_YMDHMS& rhs) const
603 {
604 return !(*this <= rhs);
605 }
606
608 explicit operator std::string() const;
609};
610
613{
614 int32_t year{};
615 int32_t doy{};
616 long double sod{};
617
622 constexpr InsTime_YDoySod(int32_t year, int32_t doy, long double sod)
623 : year(year), doy(doy), sod(sod)
624 {
625 if (this->sod >= InsTimeUtil::SECONDS_PER_DAY)
626 {
627 this->doy += static_cast<int32_t>(this->sod / InsTimeUtil::SECONDS_PER_DAY);
628 this->sod = gcem::fmod(this->sod, InsTimeUtil::SECONDS_PER_DAY);
629 }
630 while (this->sod < 0)
631 {
632 this->sod += InsTimeUtil::SECONDS_PER_DAY;
633 this->doy--;
634 }
635
636 while (this->doy > InsTimeUtil::DAYS_PER_YEAR + static_cast<int32_t>(InsTimeUtil::isLeapYear(this->year)))
637 {
638 this->doy -= InsTimeUtil::DAYS_PER_YEAR + static_cast<int32_t>(InsTimeUtil::isLeapYear(this->year));
639 this->year++;
640 }
641 while (this->doy < 1)
642 {
643 this->doy += InsTimeUtil::DAYS_PER_YEAR + static_cast<int32_t>(InsTimeUtil::isLeapYear(this->year - 1));
644 this->year--;
645 }
646 }
647
651 constexpr bool operator==(const InsTime_YDoySod& rhs) const
652 {
653 if (year == rhs.year && doy == rhs.doy)
654 {
655 return gcem::abs(sod - rhs.sod) <= InsTimeUtil::EPSILON;
656 }
657 if (auto diffDays = year * InsTimeUtil::DAYS_PER_YEAR + doy - (rhs.year * InsTimeUtil::DAYS_PER_YEAR + rhs.doy);
658 gcem::abs(diffDays) == 1)
659 {
660 auto difference = gcem::abs(sod + diffDays * InsTimeUtil::SECONDS_PER_DAY - rhs.sod);
661 return difference <= InsTimeUtil::EPSILON;
662 }
663 return false;
664 }
665
668 constexpr bool operator!=(const InsTime_YDoySod& rhs) const
669 {
670 return !(*this == rhs);
671 }
672
675 constexpr bool operator<=(const InsTime_YDoySod& rhs) const
676 {
677 return *this < rhs || *this == rhs;
678 }
679
682 constexpr bool operator>=(const InsTime_YDoySod& rhs) const
683 {
684 return *this > rhs || *this == rhs;
685 }
686
689 constexpr bool operator<(const InsTime_YDoySod& rhs) const
690 {
691 return (year < rhs.year
692 || (year == rhs.year && doy < rhs.doy)
693 || (year == rhs.year && doy == rhs.doy && sod < rhs.sod))
694 && *this != rhs;
695 }
696
699 constexpr bool operator>(const InsTime_YDoySod& rhs) const
700 {
701 return !(*this <= rhs);
702 }
703
705 explicit operator std::string() const;
706};
707
710{
711 public:
712 /* ------------------------------ Constructors ------------------------------ */
713
715 constexpr InsTime() = default;
716
720 constexpr explicit InsTime(const InsTime_MJD& mjd, TimeSystem timesys = UTC)
721 : _mjd(mjd)
722 {
723 *this -= std::chrono::duration<long double>(differenceToUTC(timesys));
724 }
725
729 constexpr explicit InsTime(const InsTime_JD& jd, TimeSystem timesys = UTC)
730 : _mjd(jd.jd_day - InsTimeUtil::DIFF_MJD_TO_JD_DAYS, jd.jd_frac - InsTimeUtil::DIFF_MJD_TO_JD_FRAC)
731 {
732 *this -= std::chrono::duration<long double>(differenceToUTC(timesys));
733 }
734
738 constexpr explicit InsTime(const InsTime_GPSweekTow& gpsWeekTow, TimeSystem timesys = GPST)
739 {
740 auto mjd_day = static_cast<int32_t>((gpsWeekTow.gpsCycle * InsTimeUtil::WEEKS_PER_GPS_CYCLE + gpsWeekTow.gpsWeek) * InsTimeUtil::DAYS_PER_WEEK
741 + gcem::floor(gpsWeekTow.tow / InsTimeUtil::SECONDS_PER_DAY)
743 long double mjd_frac = gcem::fmod(gpsWeekTow.tow, InsTimeUtil::SECONDS_PER_DAY) / InsTimeUtil::SECONDS_PER_DAY;
744
745 _mjd = InsTime_MJD(mjd_day, mjd_frac);
746
747 *this -= std::chrono::duration<long double>(differenceToUTC(timesys));
748 }
749
753 constexpr explicit InsTime(const InsTime_YMDHMS& yearMonthDayHMS, TimeSystem timesys = UTC)
754 {
755 auto a = static_cast<int32_t>((14 - yearMonthDayHMS.month) / static_cast<double>(InsTimeUtil::MONTHS_PER_YEAR));
756 int32_t y = yearMonthDayHMS.year + 4800 - a;
757 int32_t m = yearMonthDayHMS.month + InsTimeUtil::MONTHS_PER_YEAR * a - 3;
758
759 auto jd_day = static_cast<int32_t>(yearMonthDayHMS.day
760 + gcem::floor((153.0 * static_cast<double>(m) + 2.0) / 5.0)
762 + gcem::floor(static_cast<double>(y) / 4.0)
763 - gcem::floor(static_cast<double>(y) / 100.0)
764 + gcem::floor(static_cast<double>(y) / 400.0)
765 - 32045);
766 auto jd_frac = (yearMonthDayHMS.sec
767 + static_cast<long double>(yearMonthDayHMS.min) * InsTimeUtil::SECONDS_PER_MINUTE
768 + static_cast<long double>(yearMonthDayHMS.hour - 12.0) * InsTimeUtil::SECONDS_PER_HOUR)
770
771 _mjd = InsTime(InsTime_JD(jd_day, jd_frac)).toMJD();
772
773 *this -= std::chrono::duration<long double>(differenceToUTC(timesys));
774 }
775
779 constexpr explicit InsTime(const InsTime_YDoySod& yearDoySod, TimeSystem timesys = UTC)
780 {
781 auto year = yearDoySod.year;
782 auto doy = yearDoySod.doy;
783 auto sod = yearDoySod.sod;
784
785 int32_t month = 1;
786 while (doy > InsTimeUtil::daysInMonth(month, year))
787 {
788 doy -= InsTimeUtil::daysInMonth(month, year);
789 month++;
790 }
791
792 _mjd = InsTime(InsTime_YMDHMS(year, month, doy, 0, 0, sod)).toMJD();
793
794 *this -= std::chrono::duration<long double>(differenceToUTC(timesys));
795 }
796
802 constexpr InsTime(int32_t gpsCycle, int32_t gpsWeek, long double tow, TimeSystem timesys = GPST)
803 : InsTime(InsTime_GPSweekTow(gpsCycle, gpsWeek, tow), timesys) {}
804
813 constexpr InsTime(int32_t year, int32_t month, int32_t day, int32_t hour, int32_t min, long double sec, TimeSystem timesys = UTC)
814 : InsTime(InsTime_YMDHMS(year, month, day, hour, min, sec), timesys) {}
815
817 ~InsTime() = default;
819 constexpr InsTime(const InsTime&) = default;
821 constexpr InsTime(InsTime&&) = default;
823 constexpr InsTime& operator=(const InsTime&) = default;
825 constexpr InsTime& operator=(InsTime&&) = default;
826
827 /* ------------------------ Transformation functions ------------------------ */
828
832 [[nodiscard]] constexpr InsTime_MJD toMJD(TimeSystem timesys = UTC) const
833 {
834 long double mjdFrac = _mjd.mjd_frac + static_cast<long double>(differenceToUTC(timesys)) / static_cast<long double>(InsTimeUtil::SECONDS_PER_DAY);
835 return { _mjd.mjd_day, mjdFrac };
836 }
837
841 [[nodiscard]] constexpr InsTime_JD toJD(TimeSystem timesys = UTC) const
842 {
843 auto jd_day = _mjd.mjd_day + InsTimeUtil::DIFF_MJD_TO_JD_DAYS;
844 auto jd_frac = _mjd.mjd_frac + InsTimeUtil::DIFF_MJD_TO_JD_FRAC;
845
846 jd_frac += static_cast<long double>(differenceToUTC(timesys)) / static_cast<long double>(InsTimeUtil::SECONDS_PER_DAY);
847
848 return { jd_day, jd_frac };
849 }
850
854 [[nodiscard]] constexpr InsTime_GPSweekTow toGPSweekTow(TimeSystem timesys = GPST) const
855 {
856 InsTime_MJD mjd_leap = _mjd;
857 // Convert from UTC to intended time system
858 mjd_leap.mjd_frac += static_cast<long double>(differenceToUTC(timesys)) / static_cast<long double>(InsTimeUtil::SECONDS_PER_DAY);
859
860 // Put everything in the time of week, as it gets splitted in InsTime_GPSweekTow constructor
861 auto tow = static_cast<long double>((mjd_leap.mjd_day - InsTimeUtil::DIFF_TO_6_1_1980_MJD)) * InsTimeUtil::SECONDS_PER_DAY
863
864 return { 0, 0, tow };
865 }
866
871 [[nodiscard]] constexpr InsTime_YMDHMS toYMDHMS(TimeSystem timesys = UTC, int digits = -1) const
872 {
873 // transform MJD to JD
874 InsTime_JD jd = toJD();
875 jd.jd_frac = jd.jd_frac + 0.5L;
876 jd.jd_frac += static_cast<long double>(differenceToUTC(timesys)) / static_cast<long double>(InsTimeUtil::SECONDS_PER_DAY);
877 if (jd.jd_frac >= 1.0L)
878 {
879 jd.jd_day += static_cast<int32_t>(jd.jd_frac);
880 jd.jd_frac -= gcem::floor(jd.jd_frac);
881 }
882 // transform JD to YMDHMS
883 double a = 32044.0 + jd.jd_day;
884 double b = gcem::floor((4.0 * a + 3.0) / 146097.0);
885 double c = a - gcem::floor((b * 146097.0) / 4.0);
886
887 double d = gcem::floor((4.0 * c + 3.0) / 1461.0);
888 double e = c - gcem::floor((1461.0 * d) / 4.0);
889 double m = gcem::floor((5.0 * e + 2.0) / 153.0);
890
891 auto day = static_cast<uint16_t>(e - gcem::floor((153.0 * m + 2.0) / 5.0) + 1);
892 auto month = static_cast<uint16_t>(m + 3 - 12 * gcem::floor(m / 10.0));
893 auto year = static_cast<uint16_t>(b * 100 + d - 4800.0 + gcem::floor(m / 10.0));
894
895 long double sec = jd.jd_frac * InsTimeUtil::SECONDS_PER_DAY;
896
897 return { year, month, day, 0, 0, sec, digits };
898 }
899
903 [[nodiscard]] constexpr InsTime_YDoySod toYDoySod(TimeSystem timesys = UTC) const
904 {
905 InsTime_YMDHMS yearMonthDayHMS = toYMDHMS();
906
907 auto year = yearMonthDayHMS.year;
908 long double sod = static_cast<long double>(yearMonthDayHMS.hour * InsTimeUtil::SECONDS_PER_HOUR
909 + yearMonthDayHMS.min * InsTimeUtil::SECONDS_PER_MINUTE)
910 + yearMonthDayHMS.sec
911 + static_cast<long double>(differenceToUTC(timesys));
912
913 int32_t doy = 0;
914 for (int32_t i = 1; i < yearMonthDayHMS.month; i++)
915 {
916 doy += InsTimeUtil::daysInMonth(i, year);
917 }
918 doy += yearMonthDayHMS.day;
919
920 return { year, doy, sod };
921 }
922
925 [[nodiscard]] constexpr InsTime toFullDay() const
926 {
927 return InsTime(InsTime_MJD(_mjd.mjd_day, 0.0L));
928 }
929
932 [[nodiscard]] constexpr long double toUnixTime() const
933 {
934 return static_cast<long double>((_mjd.mjd_day - InsTimeUtil::DIFF_TO_1_1_1970_MJD) * InsTimeUtil::SECONDS_PER_DAY)
936 }
937
938 /* ----------------------------- Leap functions ----------------------------- */
939
942 [[nodiscard]] constexpr uint16_t leapGps2UTC() const
943 {
944 return leapGps2UTC(_mjd);
945 }
946
950 static constexpr uint16_t leapGps2UTC(const InsTime& insTime)
951 {
952 return leapGps2UTC(insTime._mjd);
953 }
954
958 static constexpr uint16_t leapGps2UTC(const InsTime_GPSweekTow& gpsWeekTow)
959 {
960 return leapGps2UTC(InsTime(gpsWeekTow).toMJD());
961 }
962
966 static constexpr uint16_t leapGps2UTC(const InsTime_YDoySod& yearDoySod)
967 {
968 return leapGps2UTC(InsTime(yearDoySod).toMJD());
969 }
970
974 static constexpr uint16_t leapGps2UTC(const InsTime_YMDHMS& yearMonthDayHMS)
975 {
976 return leapGps2UTC(InsTime(yearMonthDayHMS).toMJD());
977 }
978
982 static constexpr uint16_t leapGps2UTC(const InsTime_JD& jd)
983 {
984 return leapGps2UTC(InsTime(jd).toMJD());
985 }
986
990 static constexpr uint16_t leapGps2UTC(const InsTime_MJD& mjd_in)
991 {
992 return static_cast<uint16_t>(std::ranges::upper_bound(InsTimeUtil::GPS_LEAP_SEC_MJD, mjd_in.mjd_day) - InsTimeUtil::GPS_LEAP_SEC_MJD.begin() - 1);
993 }
994
997 [[nodiscard]] constexpr bool isLeapYear() const
998 {
999 return InsTimeUtil::isLeapYear(toYMDHMS().year);
1000 }
1001
1002 /* --------------------- Comparison operator overloading -------------------- */
1003
1007 constexpr bool operator==(const InsTime& rhs) const { return _mjd == rhs._mjd; }
1011 constexpr bool operator!=(const InsTime& rhs) const { return !(*this == rhs); }
1015 constexpr bool operator<=(const InsTime& rhs) const { return *this < rhs || *this == rhs; }
1019 constexpr bool operator>=(const InsTime& rhs) const { return *this > rhs || *this == rhs; }
1023 constexpr bool operator<(const InsTime& rhs) const { return _mjd < rhs._mjd; }
1027 constexpr bool operator>(const InsTime& rhs) const { return !(*this <= rhs); }
1028
1029 /* --------------------- Arithmetic operator overloading -------------------- */
1030
1035 constexpr friend std::chrono::duration<long double> operator-(const InsTime& lhs, const InsTime& rhs)
1036 {
1037 auto diffDays = lhs._mjd.mjd_day - rhs._mjd.mjd_day;
1038 auto diffFrac = lhs._mjd.mjd_frac - rhs._mjd.mjd_frac;
1039 long double diffSec = (diffFrac + static_cast<long double>(diffDays)) * InsTimeUtil::SECONDS_PER_DAY;
1040 return std::chrono::duration<long double>(diffSec);
1041 }
1042
1046 constexpr InsTime& operator+=(const std::chrono::duration<long double>& duration)
1047 {
1048 auto duration_mjd_frac = std::chrono::duration<long double, std::ratio<InsTimeUtil::SECONDS_PER_DAY>>(duration).count();
1049 this->_mjd = InsTime_MJD(this->_mjd.mjd_day,
1050 this->_mjd.mjd_frac + duration_mjd_frac);
1051 return *this;
1052 }
1053
1057 constexpr InsTime& operator-=(const std::chrono::duration<long double>& duration)
1058 {
1059 auto duration_mjd_frac = std::chrono::duration<long double, std::ratio<InsTimeUtil::SECONDS_PER_DAY>>(duration).count();
1060 this->_mjd = InsTime_MJD(this->_mjd.mjd_day,
1061 this->_mjd.mjd_frac - duration_mjd_frac);
1062 return *this;
1063 }
1064
1069 constexpr friend InsTime operator+(const InsTime& time, const std::chrono::duration<long double>& duration)
1070 {
1071 return InsTime(time) += duration;
1072 }
1073
1078 constexpr friend InsTime operator-(const InsTime& time, const std::chrono::duration<long double>& duration)
1079 {
1080 return InsTime(time) -= duration;
1081 }
1082
1083 /* ---------------------------- Utility Functions --------------------------- */
1084
1086 explicit operator std::string() const;
1087
1089 [[nodiscard]] constexpr bool empty() const
1090 {
1091 return _mjd.mjd_day == 0 && _mjd.mjd_frac == 0.0L;
1092 }
1093
1095 void reset()
1096 {
1097 _mjd.mjd_day = 0;
1098 _mjd.mjd_frac = 0.0L;
1099 }
1100
1104 void MakeTimeFromGloOrbit(double UTC_sec)
1105 {
1106 auto ymdhms = toYMDHMS();
1107 // difference between toe (OBRIT-0 last element) and toc (ORBIT-0 first element) in seconds
1108 long double diff = gcem::fmod(static_cast<long double>(UTC_sec), InsTimeUtil::SECONDS_PER_DAY)
1109 - (ymdhms.hour * InsTimeUtil::SECONDS_PER_HOUR
1110 + ymdhms.min * InsTimeUtil::SECONDS_PER_MINUTE
1111 + ymdhms.sec);
1112 // std::cout << "orbit diff " << diff << "\n";
1113 *this += std::chrono::duration<long double>(diff);
1114 }
1115
1118 [[nodiscard]] constexpr int differenceToUTC(TimeSystem timesys) const
1119 {
1120 switch (TimeSystem_(timesys))
1121 {
1122 case GPST: // = GPS Time (UTC + leap_seconds)
1123 return this->leapGps2UTC();
1124 case GLNT: // = GLONASS Time (UTC+ 3h)
1126 case GST: // = GALILEO Time (~ GPS) (UTC = GST - 18) is synchronized with TAI with a nominal offset below 50 ns
1127 return this->leapGps2UTC();
1128 case QZSST:
1129 return this->leapGps2UTC(); // TODO citation for synchronization accuracy
1130 case IRNSST:
1131 return this->leapGps2UTC(); // TODO citation for synchronization accuracy
1132 case BDT: // = BeiDou Time (UTC) is synchronized with UTC within 100 ns<
1133 return this->leapGps2UTC() - 14;
1134 case UTC:
1135 case TimeSys_None:
1136 return 0;
1137 }
1138 return 0;
1139 }
1140
1141 private:
1144};
1145
1150std::ostream& operator<<(std::ostream& os, const InsTime_MJD& mjd);
1155std::ostream& operator<<(std::ostream& os, const InsTime_JD& jd);
1160std::ostream& operator<<(std::ostream& os, const InsTime_GPSweekTow& gpsWeekTow);
1165std::ostream& operator<<(std::ostream& os, const InsTime_YMDHMS& ymdhms);
1170std::ostream& operator<<(std::ostream& os, const InsTime_YDoySod& yDoySod);
1175std::ostream& operator<<(std::ostream& os, const InsTime& insTime);
1176
1180void to_json(json& j, const InsTime& insTime);
1184void from_json(const json& j, InsTime& insTime);
1185
1186} // namespace NAV
1187
1188namespace std
1189{
1191template<>
1192struct hash<NAV::InsTime>
1193{
1196 std::size_t operator()(const NAV::InsTime& t) const
1197 {
1198 auto hash1 = std::hash<int32_t>{}(t.toMJD().mjd_day);
1199 auto hash2 = std::hash<long double>{}(t.toMJD().mjd_frac);
1200
1201 return hash1 | (hash2 << 32);
1202 }
1203};
1204} // namespace std
1205
1206#ifndef DOXYGEN_IGNORE
1207
1209template<>
1210struct fmt::formatter<NAV::InsTime_MJD> : fmt::formatter<std::string>
1211{
1216 template<typename FormatContext>
1217 auto format(const NAV::InsTime_MJD& mjd, FormatContext& ctx) const
1218 {
1219 return fmt::format_to(ctx.out(), "day={}, frac={}", mjd.mjd_day, static_cast<double>(mjd.mjd_frac));
1220 }
1221};
1223template<>
1224struct fmt::formatter<NAV::InsTime_JD> : fmt::formatter<std::string>
1225{
1230 template<typename FormatContext>
1231 auto format(const NAV::InsTime_JD& jd, FormatContext& ctx) const
1232 {
1233 return fmt::format_to(ctx.out(), "day={}, frac={}", jd.jd_day, static_cast<double>(jd.jd_frac));
1234 }
1235};
1237template<>
1238struct fmt::formatter<NAV::InsTime_GPSweekTow> : fmt::formatter<std::string>
1239{
1244 template<typename FormatContext>
1245 auto format(const NAV::InsTime_GPSweekTow& gpsWeekTow, FormatContext& ctx) const
1246 {
1247 return fmt::format_to(ctx.out(), "cycle={}, week={}, tow={}",
1248 gpsWeekTow.gpsCycle, gpsWeekTow.gpsWeek, static_cast<double>(gpsWeekTow.tow));
1249 }
1250};
1252template<>
1253struct fmt::formatter<NAV::InsTime_YMDHMS> : fmt::formatter<std::string>
1254{
1259 template<typename FormatContext>
1260 auto format(const NAV::InsTime_YMDHMS& ymdhms, FormatContext& ctx) const
1261 {
1262 return fmt::format_to(ctx.out(), "{}-{}-{} {}:{}:{:.6g}",
1263 ymdhms.year, ymdhms.month, ymdhms.day,
1264 ymdhms.hour, ymdhms.min, static_cast<double>(ymdhms.sec));
1265 }
1266};
1268template<>
1269struct fmt::formatter<NAV::InsTime_YDoySod> : fmt::formatter<std::string>
1270{
1275 template<typename FormatContext>
1276 auto format(const NAV::InsTime_YDoySod& yDoySod, FormatContext& ctx) const
1277 {
1278 return fmt::format_to(ctx.out(), "year={}, doy={}, sod={:.6g}",
1279 yDoySod.year, yDoySod.doy, static_cast<double>(yDoySod.sod));
1280 }
1281};
1283template<>
1284struct fmt::formatter<NAV::InsTime> : fmt::formatter<std::string>
1285{
1290 template<typename FormatContext>
1291 auto format(const NAV::InsTime& insTime, FormatContext& ctx) const
1292 {
1293 return fmt::format_to(ctx.out(), "{} ({})", insTime.toYMDHMS(), insTime.toGPSweekTow());
1294 }
1295};
1296
1297#endif
nlohmann::json json
json namespace
Definition FlowManager.hpp:21
Simple Math functions.
constexpr T round(const T &value, size_t digits)
Round the number to the specified amount of digits.
Definition Math.hpp:41
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
std::ostream & operator<<(std::ostream &os, const SatelliteSystem &satSys)
Stream insertion operator overload.
Time System defintions.
TimeSystem_
List of all time systems.
Definition TimeSystem.hpp:27
@ IRNSST
Indian Regional Navigation Satellite System Time.
Definition TimeSystem.hpp:35
@ GST
Galileo System Time.
Definition TimeSystem.hpp:32
@ BDT
BeiDou Time.
Definition TimeSystem.hpp:33
@ GLNT
GLONASS Time (GLONASST)
Definition TimeSystem.hpp:31
@ TimeSys_None
No Time system.
Definition TimeSystem.hpp:28
@ QZSST
Quasi-Zenith Satellite System Time.
Definition TimeSystem.hpp:34
@ GPST
GPS Time.
Definition TimeSystem.hpp:30
@ UTC
Coordinated Universal Time.
Definition TimeSystem.hpp:29
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
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:813
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:841
constexpr bool operator>=(const InsTime &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:1019
constexpr InsTime & operator+=(const std::chrono::duration< long double > &duration)
Adds a duration to this time point.
Definition InsTime.hpp:1046
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:903
InsTime_MJD _mjd
Modified Julien Date of this InsTime object.
Definition InsTime.hpp:1143
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:802
constexpr int differenceToUTC(TimeSystem timesys) const
Returns the time difference in [s] of a time system and UTC.
Definition InsTime.hpp:1118
constexpr InsTime_GPSweekTow toGPSweekTow(TimeSystem timesys=GPST) const
Converts this time object into a different format.
Definition InsTime.hpp:854
constexpr friend std::chrono::duration< long double > operator-(const InsTime &lhs, const InsTime &rhs)
Substracts 2 points in time.
Definition InsTime.hpp:1035
constexpr InsTime(const InsTime_GPSweekTow &gpsWeekTow, TimeSystem timesys=GPST)
Constructor.
Definition InsTime.hpp:738
constexpr InsTime & operator-=(const std::chrono::duration< long double > &duration)
Substracts a duration to this time point.
Definition InsTime.hpp:1057
constexpr InsTime(const InsTime_YDoySod &yearDoySod, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:779
constexpr friend InsTime operator-(const InsTime &time, const std::chrono::duration< long double > &duration)
Substracts a duration from a time point.
Definition InsTime.hpp:1078
constexpr bool operator<(const InsTime &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:1023
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:982
constexpr InsTime_YMDHMS toYMDHMS(TimeSystem timesys=UTC, int digits=-1) const
Converts this time object into a different format.
Definition InsTime.hpp:871
constexpr bool operator>(const InsTime &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:1027
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:958
~InsTime()=default
Destructor.
constexpr uint16_t leapGps2UTC() const
Returns the current number of leap seconds (offset GPST to UTC)
Definition InsTime.hpp:942
constexpr InsTime_MJD toMJD(TimeSystem timesys=UTC) const
Converts this time object into a different format.
Definition InsTime.hpp:832
constexpr InsTime(const InsTime_MJD &mjd, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:720
constexpr bool empty() const
Checks if the Time object has a value.
Definition InsTime.hpp:1089
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:950
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:966
constexpr InsTime(const InsTime_YMDHMS &yearMonthDayHMS, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:753
constexpr bool operator!=(const InsTime &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:1011
constexpr friend InsTime operator+(const InsTime &time, const std::chrono::duration< long double > &duration)
Adds a duration to a time point.
Definition InsTime.hpp:1069
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:1104
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:925
constexpr long double toUnixTime() const
Converts this time object into a UNIX timestamp in [s].
Definition InsTime.hpp:932
constexpr bool operator<=(const InsTime &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:1015
constexpr bool operator==(const InsTime &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:1007
void reset()
Resets the InsTime object.
Definition InsTime.hpp:1095
constexpr bool isLeapYear() const
Checks if the current time is a leap year.
Definition InsTime.hpp:997
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:990
constexpr InsTime(const InsTime_JD &jd, TimeSystem timesys=UTC)
Constructor.
Definition InsTime.hpp:729
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:974
Time System defintions.
Definition TimeSystem.hpp:40
Utility Namespace for Time related tasks.
Definition InsTime.hpp:40
constexpr long double EPSILON
Definition InsTime.hpp:67
constexpr int32_t MINUTES_PER_HOUR
Minutes / Hour.
Definition InsTime.hpp:55
constexpr long double DIFF_MJD_TO_JD_FRAC
Difference of the fraction between MJD and JD.
Definition InsTime.hpp:48
constexpr int32_t MINUTES_PER_DAY
Minutes / Day.
Definition InsTime.hpp:56
constexpr int32_t SECONDS_PER_DAY
Seconds / Day.
Definition InsTime.hpp:60
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:105
constexpr int32_t END_OF_THE_CENTURY_MJD
Modified Julian Date of the end of the century (15.01.2954)
Definition InsTime.hpp:41
constexpr int32_t SECONDS_PER_WEEK
Seconds / Week.
Definition InsTime.hpp:61
constexpr int32_t DIFF_TO_6_1_1980_MJD
06.01.1980 in Modified Julian Date
Definition InsTime.hpp:43
constexpr int32_t DAYS_PER_WEEK
Days / Week.
Definition InsTime.hpp:52
constexpr bool isLeapYear(int32_t year)
Returns true if the provided year is a leap year, false otherwise.
Definition InsTime.hpp:96
constexpr int32_t MONTHS_PER_YEAR
Months / Year.
Definition InsTime.hpp:50
constexpr int32_t DAYS_PER_YEAR
Days / Year.
Definition InsTime.hpp:51
constexpr int32_t DIFF_MJD_TO_JD_DAYS
Difference of the days between MJD and JD.
Definition InsTime.hpp:47
constexpr int32_t HOURS_PER_DAY
Hours / Day.
Definition InsTime.hpp:53
constexpr int32_t HOURS_PER_WEEK
Hours / Week.
Definition InsTime.hpp:54
constexpr int32_t MINUTES_PER_WEEK
Minutes / Week.
Definition InsTime.hpp:57
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:70
constexpr int32_t WEEKS_PER_GPS_CYCLE
Weeks per GPS cycle.
Definition InsTime.hpp:42
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:45
constexpr int32_t SECONDS_PER_HOUR
Seconds / Hour.
Definition InsTime.hpp:59
constexpr std::string formatDuration(double seconds, size_t digits=9)
Formats a duration given in seconds into days, hours, minutes and seconds.
Definition InsTime.hpp:159
constexpr int32_t SECONDS_PER_MINUTE
Seconds / Minute.
Definition InsTime.hpp:58
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:44
GPS week and time of week in GPS standard time [GPST].
Definition InsTime.hpp:369
constexpr bool operator>=(const InsTime_GPSweekTow &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:437
constexpr bool operator!=(const InsTime_GPSweekTow &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:423
int32_t gpsCycle
Contains GPS cycle in GPS standard time [GPST].
Definition InsTime.hpp:370
constexpr bool operator<=(const InsTime_GPSweekTow &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:430
int32_t gpsWeek
Contains GPS week in GPS standard time [GPST].
Definition InsTime.hpp:371
constexpr InsTime_GPSweekTow(int32_t gpsCycle, int32_t gpsWeek, long double tow)
Constructor.
Definition InsTime.hpp:378
constexpr bool operator<(const InsTime_GPSweekTow &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:444
constexpr bool operator>(const InsTime_GPSweekTow &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:454
constexpr bool operator==(const InsTime_GPSweekTow &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:407
long double tow
Contains GPS time of week in seconds in GPS standard time [GPST].
Definition InsTime.hpp:372
Julien Date [UTC].
Definition InsTime.hpp:286
int32_t jd_day
Full days since 1. January −4712 [UTC].
Definition InsTime.hpp:287
constexpr bool operator<(const InsTime_JD &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:350
constexpr InsTime_JD(int32_t jd_day, long double jd_frac)
Constructor.
Definition InsTime.hpp:293
constexpr bool operator>=(const InsTime_JD &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:343
constexpr bool operator>(const InsTime_JD &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:358
long double jd_frac
Decimal fractions of a day of the Julien Date [UTC].
Definition InsTime.hpp:288
constexpr bool operator<=(const InsTime_JD &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:336
constexpr bool operator!=(const InsTime_JD &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:329
constexpr bool operator==(const InsTime_JD &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:311
Modified Julien Date [UTC].
Definition InsTime.hpp:200
constexpr bool operator>=(const InsTime_MJD &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:260
constexpr bool operator!=(const InsTime_MJD &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:246
long double mjd_frac
Decimal fractions of a day of the Modified Julien Date [UTC].
Definition InsTime.hpp:202
constexpr bool operator>(const InsTime_MJD &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:275
constexpr InsTime_MJD(int32_t mjd_day, long double mjd_frac)
Constructor.
Definition InsTime.hpp:210
constexpr bool operator==(const InsTime_MJD &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:228
constexpr bool operator<=(const InsTime_MJD &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:253
constexpr bool operator<(const InsTime_MJD &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:267
constexpr InsTime_MJD()=default
Default constructor.
int32_t mjd_day
Full days since 17. November 1858 [UTC].
Definition InsTime.hpp:201
GPS year and day of year in GPS standard time [GPST].
Definition InsTime.hpp:613
long double sod
Contains second of day in GPS standard time [GPST].
Definition InsTime.hpp:616
constexpr bool operator<(const InsTime_YDoySod &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:689
int32_t year
Contains year in GPS standard time [GPST].
Definition InsTime.hpp:614
constexpr bool operator!=(const InsTime_YDoySod &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:668
constexpr bool operator>(const InsTime_YDoySod &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:699
constexpr bool operator==(const InsTime_YDoySod &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:651
int32_t doy
Contains day of year in GPS standard time [GPST].
Definition InsTime.hpp:615
constexpr bool operator<=(const InsTime_YDoySod &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:675
constexpr bool operator>=(const InsTime_YDoySod &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:682
constexpr InsTime_YDoySod(int32_t year, int32_t doy, long double sod)
Constructor.
Definition InsTime.hpp:622
Universal Time Coordinated [UTC].
Definition InsTime.hpp:465
int32_t min
Contains minute in Universal Time Coordinated [UTC].
Definition InsTime.hpp:470
constexpr bool operator>=(const InsTime_YMDHMS &rhs) const
Greater or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:582
int32_t year
Contains year in Universal Time Coordinated [UTC].
Definition InsTime.hpp:466
constexpr bool operator<(const InsTime_YMDHMS &rhs) const
Smaller comparison operator (takes double precision into account)
Definition InsTime.hpp:589
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:481
constexpr bool operator==(const InsTime_YMDHMS &rhs) const
Equal comparison operator (takes double precision into account)
Definition InsTime.hpp:551
constexpr bool operator!=(const InsTime_YMDHMS &rhs) const
Inequal comparison operator (takes double precision into account)
Definition InsTime.hpp:568
long double sec
Contains second in Universal Time Coordinated [UTC].
Definition InsTime.hpp:471
int32_t month
Contains month in Universal Time Coordinated [UTC].
Definition InsTime.hpp:467
constexpr bool operator>(const InsTime_YMDHMS &rhs) const
Greater comparison operator (takes double precision into account)
Definition InsTime.hpp:602
int32_t hour
Contains hour in Universal Time Coordinated [UTC].
Definition InsTime.hpp:469
int32_t day
Contains day in Universal Time Coordinated [UTC].
Definition InsTime.hpp:468
constexpr bool operator<=(const InsTime_YMDHMS &rhs) const
Smaller or equal comparison operator (takes double precision into account)
Definition InsTime.hpp:575
std::size_t operator()(const NAV::InsTime &t) const
Hash function for InsTime.
Definition InsTime.hpp:1196