0.3.0
Loading...
Searching...
No Matches
InsTime.cpp
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#include "InsTime.hpp"
10
11#include <iostream>
12#include <string>
13#include <sstream>
14#include <iomanip>
15
16#include "util/Logger.hpp"
17
18namespace NAV
19{
20InsTime::operator std::string() const
21{
22 std::stringstream stream;
23 stream << *this;
24 return stream.str();
25}
26
27InsTime_MJD::operator std::string() const
28{
29 std::stringstream stream;
30 stream << *this;
31 return stream.str();
32}
33
34InsTime_JD::operator std::string() const
35{
36 std::stringstream stream;
37 stream << *this;
38 return stream.str();
39}
40
41InsTime_GPSweekTow::operator std::string() const
42{
43 std::stringstream stream;
44 stream << *this;
45 return stream.str();
46}
47
48InsTime_YMDHMS::operator std::string() const
49{
50 std::stringstream stream;
51 stream << *this;
52 return stream.str();
53}
54
55InsTime_YDoySod::operator std::string() const
56{
57 std::stringstream stream;
58 stream << *this;
59 return stream.str();
60}
61
62// ----------------------- Out of Class Definitions --------------------------
63
64std::ostream& operator<<(std::ostream& os, const InsTime& insTime)
65{
66 return os << fmt::format("{}", insTime);
67}
68
69std::ostream& operator<<(std::ostream& os, const InsTime_MJD& mjd)
70{
71 return os << fmt::format("{}", mjd);
72}
73
74std::ostream& operator<<(std::ostream& os, const InsTime_JD& jd)
75{
76 return os << fmt::format("{}", jd);
77}
78
79std::ostream& operator<<(std::ostream& os, const InsTime_GPSweekTow& gpsWeekTow)
80{
81 return os << fmt::format("{}", gpsWeekTow);
82}
83
84std::ostream& operator<<(std::ostream& os, const InsTime_YMDHMS& ymdhms)
85{
86 return os << fmt::format("{}", ymdhms);
87}
88
89std::ostream& operator<<(std::ostream& os, const InsTime_YDoySod& yDoySod)
90{
91 return os << fmt::format("{}", yDoySod);
92}
93
94void to_json(json& j, const InsTime& insTime)
95{
96 auto mjd = insTime.toMJD();
97
98 j = json{
99 { "mjd_day", mjd.mjd_day },
100 { "mjd_frac", mjd.mjd_frac },
101 };
102}
103
104void from_json(const json& j, InsTime& insTime)
105{
106 InsTime_MJD mjd;
107
108 if (j.contains("mjd_day"))
109 {
110 j.at("mjd_day").get_to(mjd.mjd_day);
111 }
112 if (j.contains("mjd_frac"))
113 {
114 j.at("mjd_frac").get_to(mjd.mjd_frac);
115 }
116 insTime = InsTime{ mjd };
117}
118
119} // namespace NAV
nlohmann::json json
json namespace
The class is responsible for all time-related tasks.
Utility class for logging to console and file.
The class is responsible for all time-related tasks.
Definition InsTime.hpp:710
constexpr InsTime_MJD toMJD(TimeSystem timesys=UTC) const
Converts this time object into a different format.
Definition InsTime.hpp:832
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
Julien Date [UTC].
Definition InsTime.hpp:286
Modified Julien Date [UTC].
Definition InsTime.hpp:200
long double mjd_frac
Decimal fractions of a day of the Modified Julien Date [UTC].
Definition InsTime.hpp:202
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
Universal Time Coordinated [UTC].
Definition InsTime.hpp:465