INSTINCT Code Coverage Report


Directory: src/
File: Navigation/Time/InsTime.cpp
Date: 2025-11-25 23:34:18
Exec Total Coverage
Lines: 12 55 21.8%
Functions: 3 14 21.4%
Branches: 11 72 15.3%

Line Branch Exec Source
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
18 namespace NAV
19 {
20 ✗ InsTime::operator std::string() const
21 {
22 ✗ std::stringstream stream;
23 ✗ stream << *this;
24 ✗ return stream.str();
25 ✗ }
26
27 ✗ InsTime_MJD::operator std::string() const
28 {
29 ✗ std::stringstream stream;
30 ✗ stream << *this;
31 ✗ return stream.str();
32 ✗ }
33
34 ✗ InsTime_JD::operator std::string() const
35 {
36 ✗ std::stringstream stream;
37 ✗ stream << *this;
38 ✗ return stream.str();
39 ✗ }
40
41 ✗ InsTime_GPSweekTow::operator std::string() const
42 {
43 ✗ std::stringstream stream;
44 ✗ stream << *this;
45 ✗ return stream.str();
46 ✗ }
47
48 ✗ InsTime_YMDHMS::operator std::string() const
49 {
50 ✗ std::stringstream stream;
51 ✗ stream << *this;
52 ✗ return stream.str();
53 ✗ }
54
55 ✗ InsTime_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
64 12896 std::ostream& operator<<(std::ostream& os, const InsTime& insTime)
65 {
66
1/2
✓ Branch 2 taken 12896 times.
✗ Branch 3 not taken.
25792 return os << fmt::format("{}", insTime);
67 }
68
69 ✗ std::ostream& operator<<(std::ostream& os, const InsTime_MJD& mjd)
70 {
71 ✗ return os << fmt::format("{}", mjd);
72 }
73
74 ✗ std::ostream& operator<<(std::ostream& os, const InsTime_JD& jd)
75 {
76 ✗ return os << fmt::format("{}", jd);
77 }
78
79 ✗ std::ostream& operator<<(std::ostream& os, const InsTime_GPSweekTow& gpsWeekTow)
80 {
81 ✗ return os << fmt::format("{}", gpsWeekTow);
82 }
83
84 32 std::ostream& operator<<(std::ostream& os, const InsTime_YMDHMS& ymdhms)
85 {
86
1/2
✓ Branch 2 taken 32 times.
✗ Branch 3 not taken.
64 return os << fmt::format("{}", ymdhms);
87 }
88
89 ✗ std::ostream& operator<<(std::ostream& os, const InsTime_YDoySod& yDoySod)
90 {
91 ✗ return os << fmt::format("{}", yDoySod);
92 }
93
94 ✗ void 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
104 14 void from_json(const json& j, InsTime& insTime)
105 {
106 14 InsTime_MJD mjd;
107
108
2/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
14 if (j.contains("mjd_day"))
109 {
110
2/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
14 j.at("mjd_day").get_to(mjd.mjd_day);
111 }
112
2/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
✗ Branch 4 not taken.
14 if (j.contains("mjd_frac"))
113 {
114
2/4
✓ Branch 1 taken 14 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 14 times.
✗ Branch 5 not taken.
14 j.at("mjd_frac").get_to(mjd.mjd_frac);
115 }
116
1/2
✓ Branch 2 taken 14 times.
✗ Branch 3 not taken.
14 insTime = InsTime{ mjd };
117 14 }
118
119 } // namespace NAV
120