0.4.1
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
9/// @file InsTime.hpp
10/// @brief The class is responsible for all time-related tasks
11/// @author T. Topp (topp@ins.uni-stuttgart.de)
12/// @author T. Lambertus (tomke-jantje.lambertus@nav.uni-stuttgart.de)
13/// @date 2020-12-02
14///
15/// @details This class contains all time-transformations functions. One instance is created for each InsTime object (defined in the structs).
16/// Internally, only the MJD-time (Modified Julien Date) is stored (here MJD is a struct which has mjd_day and mjd_frac).
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; ///< json namespace
32
33#include "TimeSystem.hpp"
35
36namespace NAV
37{
38/// @brief Utility Namespace for Time related tasks
39namespace InsTimeUtil
40{
41constexpr int32_t END_OF_THE_CENTURY_MJD = 400000; ///< Modified Julian Date of the end of the century (15.01.2954)
42constexpr int32_t WEEKS_PER_GPS_CYCLE = 1024; ///< Weeks per GPS cycle
43constexpr int32_t DIFF_TO_6_1_1980_MJD = 44244; ///< 06.01.1980 in Modified Julian Date
44constexpr int32_t DIFF_TO_1_1_1970_MJD = 40587; ///< 01.01.1970 00:00:00 UTC in Modified Julian Date (UNIX epoch)
45constexpr int32_t DIFF_BDT_WEEK_TO_GPST_WEEK = 1356; ///< BeiDou starts zero at 1-Jan-2006 and GPS starts 6-Jan-1980
46
47constexpr int32_t DIFF_MJD_TO_JD_DAYS = 2400000; ///< Difference of the days between MJD and JD
48constexpr long double DIFF_MJD_TO_JD_FRAC = 0.5L; ///< Difference of the fraction between MJD and JD
49
50constexpr int32_t MONTHS_PER_YEAR = 12; ///< Months / Year
51constexpr int32_t DAYS_PER_YEAR = 365; ///< Days / Year
52constexpr int32_t DAYS_PER_WEEK = 7; ///< Days / Week
53constexpr int32_t HOURS_PER_DAY = 24; ///< Hours / Day
54constexpr int32_t HOURS_PER_WEEK = HOURS_PER_DAY * DAYS_PER_WEEK; ///< Hours / Week
55constexpr int32_t MINUTES_PER_HOUR = 60; ///< Minutes / Hour
56constexpr int32_t MINUTES_PER_DAY = MINUTES_PER_HOUR * HOURS_PER_DAY; ///< Minutes / Day
57constexpr int32_t MINUTES_PER_WEEK = MINUTES_PER_DAY * DAYS_PER_WEEK; ///< Minutes / Week
58constexpr int32_t SECONDS_PER_MINUTE = 60; ///< Seconds / Minute
59constexpr int32_t SECONDS_PER_HOUR = SECONDS_PER_MINUTE * MINUTES_PER_HOUR; ///< Seconds / Hour
60constexpr int32_t SECONDS_PER_DAY = SECONDS_PER_MINUTE * MINUTES_PER_HOUR * HOURS_PER_DAY; ///< Seconds / Day
61constexpr int32_t SECONDS_PER_WEEK = SECONDS_PER_DAY * DAYS_PER_WEEK; ///< Seconds / Week
62
63/// Numerical precision/epsilon for 'long double' variables
64/// - Linux/x64: 1e-19
65/// - Windows/x64 1e-16
66/// - Linux/armv8: 1e-34 (Epsilon reports too small precision. Real precision is only approx. 1e-17)
67constexpr long double EPSILON = std::max(1e-17L, 10 * std::numeric_limits<long double>::epsilon());
68
69/// Maps GPS leap seconds to a time: array<mjd_day>, index + 1 is amount of leap seconds
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
93/// @brief Returns true if the provided year is a leap year, false otherwise
94/// @param[in] year The year to check
95/// @return True if the year is a leap year, otherwise false
96constexpr bool isLeapYear(int32_t year)
97{
98 return (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0));
99}
100
101/// @brief Returns the number of days in the specified month of the year
102/// @param[in] month Month [1-12]
103/// @param[in] year Year to determine the leap year
104/// @return Number of days in the specified month
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
155/// @brief Formats a duration given in seconds into days, hours, minutes and seconds
156/// @param[in] seconds Amount of seconds
157/// @param[in] digits Digits to round the seconds to
158/// @return Formatted string of the duration
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
198/// Modified Julien Date [UTC]
200{
201 int32_t mjd_day = 0; ///< Full days since 17. November 1858 [UTC]
202 long double mjd_frac = 0.0L; ///< Decimal fractions of a day of the Modified Julien Date [UTC]
203
204 /// @brief Default constructor
205 constexpr InsTime_MJD() = default;
206
207 /// @brief Constructor
208 /// @param[in] mjd_day Full days of the Modified Julien Date [UTC]
209 /// @param[in] mjd_frac Decimal fractions of a day of the Modified Julien Date [UTC]
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
225 /// @brief Equal comparison operator (takes double precision into account)
226 /// @param[in] rhs Right-hand side to compare with
227 /// @return Comparison result
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 /// @brief Inequal comparison operator (takes double precision into account)
244 /// @param[in] rhs Right-hand side to compare with
245 /// @return Comparison result
246 constexpr bool operator!=(const InsTime_MJD& rhs) const
247 {
248 return !(*this == rhs);
249 }
250 /// @brief Smaller or equal comparison operator (takes double precision into account)
251 /// @param[in] rhs Right-hand side to compare with
252 /// @return Comparison result
253 constexpr bool operator<=(const InsTime_MJD& rhs) const
254 {
255 return *this < rhs || *this == rhs;
256 }
257 /// @brief Greater or equal comparison operator (takes double precision into account)
258 /// @param[in] rhs Right-hand side to compare with
259 /// @return Comparison result
260 constexpr bool operator>=(const InsTime_MJD& rhs) const
261 {
262 return *this > rhs || *this == rhs;
263 }
264 /// @brief Smaller comparison operator (takes double precision into account)
265 /// @param[in] rhs Right-hand side to compare with
266 /// @return Comparison result
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 /// @brief Greater comparison operator (takes double precision into account)
273 /// @param[in] rhs Right-hand side to compare with
274 /// @return Comparison result
275 constexpr bool operator>(const InsTime_MJD& rhs) const
276 {
277 return !(*this <= rhs);
278 }
279
280 /// @brief Converts the object into a readable string
281 explicit operator std::string() const;
282};
283
284/// Julien Date [UTC]
286{
287 int32_t jd_day{}; ///< Full days since 1. January −4712 [UTC]
288 long double jd_frac{}; ///< Decimal fractions of a day of the Julien Date [UTC]
289
290 /// @brief Constructor
291 /// @param[in] jd_day Full days of the Julien Date [UTC]
292 /// @param[in] jd_frac Decimal fractions of a day of the Julien Date [UTC]
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
308 /// @brief Equal comparison operator (takes double precision into account)
309 /// @param[in] rhs Right-hand side to compare with
310 /// @return Comparison result
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 /// @brief Inequal comparison operator (takes double precision into account)
327 /// @param[in] rhs Right-hand side to compare with
328 /// @return Comparison result
329 constexpr bool operator!=(const InsTime_JD& rhs) const
330 {
331 return !(*this == rhs);
332 }
333 /// @brief Smaller or equal comparison operator (takes double precision into account)
334 /// @param[in] rhs Right-hand side to compare with
335 /// @return Comparison result
336 constexpr bool operator<=(const InsTime_JD& rhs) const
337 {
338 return *this < rhs || *this == rhs;
339 }
340 /// @brief Greater or equal comparison operator (takes double precision into account)
341 /// @param[in] rhs Right-hand side to compare with
342 /// @return Comparison result
343 constexpr bool operator>=(const InsTime_JD& rhs) const
344 {
345 return *this > rhs || *this == rhs;
346 }
347 /// @brief Smaller comparison operator (takes double precision into account)
348 /// @param[in] rhs Right-hand side to compare with
349 /// @return Comparison result
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 /// @brief Greater comparison operator (takes double precision into account)
356 /// @param[in] rhs Right-hand side to compare with
357 /// @return Comparison result
358 constexpr bool operator>(const InsTime_JD& rhs) const
359 {
360 return !(*this <= rhs);
361 }
362
363 /// @brief Converts the object into a readable string
364 explicit operator std::string() const;
365};
366
367/// GPS week and time of week in GPS standard time [GPST]
369{
370 int32_t gpsCycle{}; ///< Contains GPS cycle in GPS standard time [GPST]
371 int32_t gpsWeek{}; ///< Contains GPS week in GPS standard time [GPST]
372 long double tow{}; ///< Contains GPS time of week in seconds in GPS standard time [GPST]
373
374 /// @brief Constructor
375 /// @param[in] gpsCycle GPS cycle in GPS standard time [GPST]
376 /// @param[in] gpsWeek GPS week in GPS standard time [GPST]
377 /// @param[in] tow GPS time of week in seconds in GPS standard time [GPST]
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
404 /// @brief Equal comparison operator (takes double precision into account)
405 /// @param[in] rhs Right-hand side to compare with
406 /// @return Comparison result
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 /// @brief Inequal comparison operator (takes double precision into account)
421 /// @param[in] rhs Right-hand side to compare with
422 /// @return Comparison result
423 constexpr bool operator!=(const InsTime_GPSweekTow& rhs) const
424 {
425 return !(*this == rhs);
426 }
427 /// @brief Smaller or equal comparison operator (takes double precision into account)
428 /// @param[in] rhs Right-hand side to compare with
429 /// @return Comparison result
430 constexpr bool operator<=(const InsTime_GPSweekTow& rhs) const
431 {
432 return *this < rhs || *this == rhs;
433 }
434 /// @brief Greater or equal comparison operator (takes double precision into account)
435 /// @param[in] rhs Right-hand side to compare with
436 /// @return Comparison result
437 constexpr bool operator>=(const InsTime_GPSweekTow& rhs) const
438 {
439 return *this > rhs || *this == rhs;
440 }
441 /// @brief Smaller comparison operator (takes double precision into account)
442 /// @param[in] rhs Right-hand side to compare with
443 /// @return Comparison result
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 /// @brief Greater comparison operator (takes double precision into account)
452 /// @param[in] rhs Right-hand side to compare with
453 /// @return Comparison result
454 constexpr bool operator>(const InsTime_GPSweekTow& rhs) const
455 {
456 return !(*this <= rhs);
457 }
458
459 /// @brief Converts the object into a readable string
460 explicit operator std::string() const;
461};
462
463/// Universal Time Coordinated [UTC]
465{
466 int32_t year{}; ///< Contains year in Universal Time Coordinated [UTC]
467 int32_t month{}; ///< Contains month in Universal Time Coordinated [UTC]
468 int32_t day{}; ///< Contains day in Universal Time Coordinated [UTC]
469 int32_t hour{}; ///< Contains hour in Universal Time Coordinated [UTC]
470 int32_t min{}; ///< Contains minute in Universal Time Coordinated [UTC]
471 long double sec{}; ///< Contains second in Universal Time Coordinated [UTC]
472
473 /// @brief Constructor
474 /// @param[in] year Year in Universal Time Coordinated [UTC]
475 /// @param[in] month Month in Universal Time Coordinated (1 = January) [UTC]
476 /// @param[in] day Day in Universal Time Coordinated (1 = first day) [UTC]
477 /// @param[in] hour Hour in Universal Time Coordinated [UTC]
478 /// @param[in] min Minute in Universal Time Coordinated [UTC]
479 /// @param[in] sec Second in Universal Time Coordinated [UTC]
480 /// @param[in] digits Amount of digits for the seconds to round to
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
548 /// @brief Equal comparison operator (takes double precision into account)
549 /// @param[in] rhs Right-hand side to compare with
550 /// @return Comparison result
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 /// @brief Inequal comparison operator (takes double precision into account)
566 /// @param[in] rhs Right-hand side to compare with
567 /// @return Comparison result
568 constexpr bool operator!=(const InsTime_YMDHMS& rhs) const
569 {
570 return !(*this == rhs);
571 }
572 /// @brief Smaller or equal comparison operator (takes double precision into account)
573 /// @param[in] rhs Right-hand side to compare with
574 /// @return Comparison result
575 constexpr bool operator<=(const InsTime_YMDHMS& rhs) const
576 {
577 return *this < rhs || *this == rhs;
578 }
579 /// @brief Greater or equal comparison operator (takes double precision into account)
580 /// @param[in] rhs Right-hand side to compare with
581 /// @return Comparison result
582 constexpr bool operator>=(const InsTime_YMDHMS& rhs) const
583 {
584 return *this > rhs || *this == rhs;
585 }
586 /// @brief Smaller comparison operator (takes double precision into account)
587 /// @param[in] rhs Right-hand side to compare with
588 /// @return Comparison result
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 /// @brief Greater comparison operator (takes double precision into account)
600 /// @param[in] rhs Right-hand side to compare with
601 /// @return Comparison result
602 constexpr bool operator>(const InsTime_YMDHMS& rhs) const
603 {
604 return !(*this <= rhs);
605 }
606
607 /// @brief Converts the object into a readable string
608 explicit operator std::string() const;
609};
610
611/// GPS year and day of year in GPS standard time [GPST]
613{
614 int32_t year{}; ///< Contains year in GPS standard time [GPST]
615 int32_t doy{}; ///< Contains day of year in GPS standard time [GPST]
616 long double sod{}; ///< Contains second of day in GPS standard time [GPST]
617
618 /// @brief Constructor
619 /// @param[in] year Year in GPS standard time [GPST]
620 /// @param[in] doy Day of year in GPS standard time [1-365(/366)]
621 /// @param[in] sod Second of day in GPS standard time [GPST]
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
648 /// @brief Equal comparison operator (takes double precision into account)
649 /// @param[in] rhs Right-hand side to compare with
650 /// @return Comparison result
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 /// @brief Inequal comparison operator (takes double precision into account)
666 /// @param[in] rhs Right-hand side to compare with
667 /// @return Comparison result
668 constexpr bool operator!=(const InsTime_YDoySod& rhs) const
669 {
670 return !(*this == rhs);
671 }
672 /// @brief Smaller or equal comparison operator (takes double precision into account)
673 /// @param[in] rhs Right-hand side to compare with
674 /// @return Comparison result
675 constexpr bool operator<=(const InsTime_YDoySod& rhs) const
676 {
677 return *this < rhs || *this == rhs;
678 }
679 /// @brief Greater or equal comparison operator (takes double precision into account)
680 /// @param[in] rhs Right-hand side to compare with
681 /// @return Comparison result
682 constexpr bool operator>=(const InsTime_YDoySod& rhs) const
683 {
684 return *this > rhs || *this == rhs;
685 }
686 /// @brief Smaller comparison operator (takes double precision into account)
687 /// @param[in] rhs Right-hand side to compare with
688 /// @return Comparison result
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 /// @brief Greater comparison operator (takes double precision into account)
697 /// @param[in] rhs Right-hand side to compare with
698 /// @return Comparison result
699 constexpr bool operator>(const InsTime_YDoySod& rhs) const
700 {
701 return !(*this <= rhs);
702 }
703
704 /// @brief Converts the object into a readable string
705 explicit operator std::string() const;
706};
707
708/// The class is responsible for all time-related tasks
710{
711 public:
712 /* ------------------------------ Constructors ------------------------------ */
713
714 /// @brief Default Constructor
715 constexpr InsTime() = default;
716
717 /// @brief Constructor
718 /// @param[in] mjd Time in Modified Julien Date
719 /// @param[in] timesys Time System in which the previous values are given in
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
726 /// @brief Constructor
727 /// @param[in] jd Time in Julien Date
728 /// @param[in] timesys Time System in which the previous values are given in
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
735 /// @brief Constructor
736 /// @param[in] gpsWeekTow Time as week and time of week
737 /// @param[in] timesys Time System in which the previous values are given in
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
750 /// @brief Constructor
751 /// @param[in] yearMonthDayHMS Time in Universal Time Coordinated
752 /// @param[in] timesys Time System in which the previous values are given in
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
776 /// @brief Constructor
777 /// @param[in] yearDoySod Time as Year, day of year and seconds of day
778 /// @param[in] timesys Time System in which the previous values are given in
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
797 /// @brief Constructor
798 /// @param[in] gpsCycle GPS cycle in GPS standard time
799 /// @param[in] gpsWeek GPS week in GPS standard time
800 /// @param[in] tow GPS time of week in GPS standard time
801 /// @param[in] timesys Time System in which the previous values are given in
802 constexpr InsTime(int32_t gpsCycle, int32_t gpsWeek, long double tow, TimeSystem timesys = GPST)
803 : InsTime(InsTime_GPSweekTow(gpsCycle, gpsWeek, tow), timesys) {}
804
805 /// @brief Constructor
806 /// @param[in] year Year
807 /// @param[in] month Month (1 = January)
808 /// @param[in] day Day (1 = first day)
809 /// @param[in] hour Hour
810 /// @param[in] min Minute
811 /// @param[in] sec Second
812 /// @param[in] timesys Time System in which the previous values are given in
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
816 /// @brief Destructor
817 ~InsTime() = default;
818 /// @brief Copy constructor
819 constexpr InsTime(const InsTime&) = default;
820 /// @brief Move constructor
821 constexpr InsTime(InsTime&&) = default;
822 /// @brief Copy assignment operator
823 constexpr InsTime& operator=(const InsTime&) = default;
824 /// @brief Move assignment operator
825 constexpr InsTime& operator=(InsTime&&) = default;
826
827 /* ------------------------ Transformation functions ------------------------ */
828
829 /// @brief Converts this time object into a different format
830 /// @param timesys Time System in which the time should be given
831 /// @return InsTime_MJD structure of the this object
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
838 /// @brief Converts this time object into a different format
839 /// @param timesys Time System in which the time should be given
840 /// @return InsTime_JD structure of the this object
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
851 /// @brief Converts this time object into a different format
852 /// @param timesys Time System in which the time should be given
853 /// @return InsTime_GPSweekTow structure of the this object
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
867 /// @brief Converts this time object into a different format
868 /// @param timesys Time System in which the time should be given
869 /// @param digits Amount of digits for the seconds to round to
870 /// @return InsTime_YMDHMS structure of the this object
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
900 /// @brief Converts this time object into a different format
901 /// @param timesys Time System in which the time should be given
902 /// @return InsTime_YDoySod structure of the this object
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
923 /// @brief Returns the current time rounded/cutted to a full day (changes time to 0:0:0h UTC of current day)
924 /// @return The rounded/cutted time object
925 [[nodiscard]] constexpr InsTime toFullDay() const
926 {
927 return InsTime(InsTime_MJD(_mjd.mjd_day, 0.0L));
928 }
929
930 /// @brief Converts this time object into a UNIX timestamp in [s]
931 /// @attention Do not pass `long double` to the LOG_... functions, it can loop indefinitely
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
940 /// @brief Returns the current number of leap seconds (offset GPST to UTC)
941 /// @return Number of leap seconds
942 [[nodiscard]] constexpr uint16_t leapGps2UTC() const
943 {
944 return leapGps2UTC(_mjd);
945 }
946
947 /// @brief Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime object
948 /// @param[in] insTime Time point
949 /// @return Number of leap seconds
950 static constexpr uint16_t leapGps2UTC(const InsTime& insTime)
951 {
952 return leapGps2UTC(insTime._mjd);
953 }
954
955 /// @brief Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_GPSweekTow object
956 /// @param[in] gpsWeekTow Time point
957 /// @return Number of leap seconds
958 static constexpr uint16_t leapGps2UTC(const InsTime_GPSweekTow& gpsWeekTow)
959 {
960 return leapGps2UTC(InsTime(gpsWeekTow).toMJD());
961 }
962
963 /// @brief Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_YDoySod object
964 /// @param[in] yearDoySod Time point
965 /// @return Number of leap seconds
966 static constexpr uint16_t leapGps2UTC(const InsTime_YDoySod& yearDoySod)
967 {
968 return leapGps2UTC(InsTime(yearDoySod).toMJD());
969 }
970
971 /// @brief Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_YMDHMS object
972 /// @param[in] yearMonthDayHMS Time point
973 /// @return Number of leap seconds
974 static constexpr uint16_t leapGps2UTC(const InsTime_YMDHMS& yearMonthDayHMS)
975 {
976 return leapGps2UTC(InsTime(yearMonthDayHMS).toMJD());
977 }
978
979 /// @brief Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_JD object
980 /// @param[in] jd Time point
981 /// @return Number of leap seconds
982 static constexpr uint16_t leapGps2UTC(const InsTime_JD& jd)
983 {
984 return leapGps2UTC(InsTime(jd).toMJD());
985 }
986
987 /// @brief Returns the number of leap seconds (offset GPST to UTC) for the provided InsTime_MJD object
988 /// @param[in] mjd_in Time point
989 /// @return Number of leap seconds
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
995 /// @brief Checks if the current time is a leap year
996 /// @return True if the current time is a leap year, false otherwise
997 [[nodiscard]] constexpr bool isLeapYear() const
998 {
999 return InsTimeUtil::isLeapYear(toYMDHMS().year);
1000 }
1001
1002 /* --------------------- Comparison operator overloading -------------------- */
1003
1004 /// @brief Equal comparison operator (takes double precision into account)
1005 /// @param[in] rhs Right-hand side to compare with
1006 /// @return Comparison result
1007 constexpr bool operator==(const InsTime& rhs) const { return _mjd == rhs._mjd; }
1008 /// @brief Inequal comparison operator (takes double precision into account)
1009 /// @param[in] rhs Right-hand side to compare with
1010 /// @return Comparison result
1011 constexpr bool operator!=(const InsTime& rhs) const { return !(*this == rhs); }
1012 /// @brief Smaller or equal comparison operator (takes double precision into account)
1013 /// @param[in] rhs Right-hand side to compare with
1014 /// @return Comparison result
1015 constexpr bool operator<=(const InsTime& rhs) const { return *this < rhs || *this == rhs; }
1016 /// @brief Greater or equal comparison operator (takes double precision into account)
1017 /// @param[in] rhs Right-hand side to compare with
1018 /// @return Comparison result
1019 constexpr bool operator>=(const InsTime& rhs) const { return *this > rhs || *this == rhs; }
1020 /// @brief Smaller comparison operator (takes double precision into account)
1021 /// @param[in] rhs Right-hand side to compare with
1022 /// @return Comparison result
1023 constexpr bool operator<(const InsTime& rhs) const { return _mjd < rhs._mjd; }
1024 /// @brief Greater comparison operator (takes double precision into account)
1025 /// @param[in] rhs Right-hand side to compare with
1026 /// @return Comparison result
1027 constexpr bool operator>(const InsTime& rhs) const { return !(*this <= rhs); }
1028
1029 /* --------------------- Arithmetic operator overloading -------------------- */
1030
1031 /// @brief Substracts 2 points in time
1032 /// @param[in] lhs The left hand side time point
1033 /// @param[in] rhs The right hand side time point
1034 /// @return Time difference in [seconds]
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
1043 /// @brief Adds a duration to this time point
1044 /// @param[in] duration The duration to add
1045 /// @return Reference to this object
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
1054 /// @brief Substracts a duration to this time point
1055 /// @param[in] duration The duration to substract
1056 /// @return Reference to this object
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
1065 /// @brief Adds a duration to a time point
1066 /// @param[in] time The left hand side time point
1067 /// @param[in] duration The right hand side duration
1068 /// @return Time point with the added duration
1069 constexpr friend InsTime operator+(const InsTime& time, const std::chrono::duration<long double>& duration)
1070 {
1071 return InsTime(time) += duration;
1072 }
1073
1074 /// @brief Substracts a duration from a time point
1075 /// @param[in] time The left hand side time point
1076 /// @param[in] duration The right hand side duration
1077 /// @return Time point with the substracted duration
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
1085 /// @brief Converts the object into a readable string
1086 explicit operator std::string() const;
1087
1088 /// @brief Checks if the Time object has a value
1089 [[nodiscard]] constexpr bool empty() const
1090 {
1091 return _mjd.mjd_day == 0 && _mjd.mjd_frac == 0.0L;
1092 }
1093
1094 /// @brief Resets the InsTime object
1095 void reset()
1096 {
1097 _mjd.mjd_day = 0;
1098 _mjd.mjd_frac = 0.0L;
1099 }
1100
1101 /// @brief Adds the difference [seconds] between toe (OBRIT-0 last element) and toc (ORBIT-0 first element) to the current time
1102 /// (Changes time, so that it corresponds to the time of GLONASS ORBIT last element)
1103 /// @param[in] UTC_sec Seconds in UTC time
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
1116 /// @brief Returns the time difference in [s] of a time system and UTC
1117 /// @param[in] timesys Time system to get the difference from UTC
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:
1142 /// @brief Modified Julien Date of this InsTime object
1144};
1145
1146/// @brief Stream insertion operator overload
1147/// @param[in, out] os Output stream object to stream the time into
1148/// @param[in] mjd Object to print
1149/// @return Returns the output stream object in order to chain stream insertions
1150std::ostream& operator<<(std::ostream& os, const InsTime_MJD& mjd);
1151/// @brief Stream insertion operator overload
1152/// @param[in, out] os Output stream object to stream the time into
1153/// @param[in] jd Object to print
1154/// @return Returns the output stream object in order to chain stream insertions
1155std::ostream& operator<<(std::ostream& os, const InsTime_JD& jd);
1156/// @brief Stream insertion operator overload
1157/// @param[in, out] os Output stream object to stream the time into
1158/// @param[in] gpsWeekTow Object to print
1159/// @return Returns the output stream object in order to chain stream insertions
1160std::ostream& operator<<(std::ostream& os, const InsTime_GPSweekTow& gpsWeekTow);
1161/// @brief Stream insertion operator overload
1162/// @param[in, out] os Output stream object to stream the time into
1163/// @param[in] ymdhms Object to print
1164/// @return Returns the output stream object in order to chain stream insertions
1165std::ostream& operator<<(std::ostream& os, const InsTime_YMDHMS& ymdhms);
1166/// @brief Stream insertion operator overload
1167/// @param[in, out] os Output stream object to stream the time into
1168/// @param[in] yDoySod Object to print
1169/// @return Returns the output stream object in order to chain stream insertions
1170std::ostream& operator<<(std::ostream& os, const InsTime_YDoySod& yDoySod);
1171/// @brief Stream insertion operator overload
1172/// @param[in, out] os Output stream object to stream the time into
1173/// @param[in] insTime Object to print
1174/// @return Returns the output stream object in order to chain stream insertions
1175std::ostream& operator<<(std::ostream& os, const InsTime& insTime);
1176
1177/// @brief Converts the provided InsTime into a json object
1178/// @param[out] j Return Json object
1179/// @param[in] insTime Time to convert
1180void to_json(json& j, const InsTime& insTime);
1181/// @brief Converts the provided json object into an InsTime
1182/// @param[in] j Json object with the time values
1183/// @param[out] insTime Time to return
1184void from_json(const json& j, InsTime& insTime);
1185
1186} // namespace NAV
1187
1188namespace std
1189{
1190/// @brief Hash function for InsTime (needed for unordered_map)
1191template<>
1192struct hash<NAV::InsTime>
1193{
1194 /// @brief Hash function for InsTime
1195 /// @param[in] t Time
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
1208/// @brief Formatter
1209template<>
1210struct fmt::formatter<NAV::InsTime_MJD> : fmt::formatter<std::string>
1211{
1212 /// @brief Defines how to format this structs
1213 /// @param[in] mjd Struct to format
1214 /// @param[in, out] ctx Format context
1215 /// @return Output iterator
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};
1222/// @brief Formatter
1223template<>
1224struct fmt::formatter<NAV::InsTime_JD> : fmt::formatter<std::string>
1225{
1226 /// @brief Defines how to format this structs
1227 /// @param[in] jd Struct to format
1228 /// @param[in, out] ctx Format context
1229 /// @return Output iterator
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};
1236/// @brief Formatter
1237template<>
1238struct fmt::formatter<NAV::InsTime_GPSweekTow> : fmt::formatter<std::string>
1239{
1240 /// @brief Defines how to format this structs
1241 /// @param[in] gpsWeekTow Struct to format
1242 /// @param[in, out] ctx Format context
1243 /// @return Output iterator
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};
1251/// @brief Formatter
1252template<>
1253struct fmt::formatter<NAV::InsTime_YMDHMS> : fmt::formatter<std::string>
1254{
1255 /// @brief Defines how to format this structs
1256 /// @param[in] ymdhms Struct to format
1257 /// @param[in, out] ctx Format context
1258 /// @return Output iterator
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};
1267/// @brief Formatter
1268template<>
1269struct fmt::formatter<NAV::InsTime_YDoySod> : fmt::formatter<std::string>
1270{
1271 /// @brief Defines how to format this structs
1272 /// @param[in] yDoySod Struct to format
1273 /// @param[in, out] ctx Format context
1274 /// @return Output iterator
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};
1282/// @brief Formatter
1283template<>
1284struct fmt::formatter<NAV::InsTime> : fmt::formatter<std::string>
1285{
1286 /// @brief Defines how to format this structs
1287 /// @param[in] insTime Struct to format
1288 /// @param[in, out] ctx Format context
1289 /// @return Output iterator
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
Simple Math functions.
Time System defintions.
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.
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
constexpr T round(const T &value, size_t digits)
Round the number to the specified amount of digits.
Definition Math.hpp:41
TimeSystem_
List of all time systems.
@ IRNSST
Indian Regional Navigation Satellite System Time.
@ GST
Galileo System Time.
@ BDT
BeiDou Time.
@ GLNT
GLONASS Time (GLONASST)
@ TimeSys_None
No Time system.
@ QZSST
Quasi-Zenith Satellite System Time.
@ GPST
GPS Time.
@ UTC
Coordinated Universal Time.
void to_json(json &j, const Node &node)
Converts the provided node into a json object.
Definition Node.cpp:990
void from_json(const json &j, Node &node)
Converts the provided json object into a node object.
Definition Node.cpp:1007
std::ostream & operator<<(std::ostream &os, const SatelliteSystem &satSys)
Stream insertion operator overload.
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