89SCENARIO(
"Verify operation of timespecAddNsec",
"[timeutils]" )
93 WHEN(
"adding less than 1e9 nanoseconds" )
100 REQUIRE( ts.tv_sec == 1 );
101 REQUIRE( ts.tv_nsec == 10 );
104 REQUIRE( ts.tv_sec == 1 );
105 REQUIRE( ts.tv_nsec == 110 );
108 REQUIRE( ts.tv_sec == 1 );
109 REQUIRE( ts.tv_nsec == 1110 );
112 REQUIRE( ts.tv_sec == 1 );
113 REQUIRE( ts.tv_nsec == 11110 );
116 REQUIRE( ts.tv_sec == 1 );
117 REQUIRE( ts.tv_nsec == 111110 );
120 REQUIRE( ts.tv_sec == 1 );
121 REQUIRE( ts.tv_nsec == 1111110 );
124 REQUIRE( ts.tv_sec == 1 );
125 REQUIRE( ts.tv_nsec == 11111110 );
128 REQUIRE( ts.tv_sec == 1 );
129 REQUIRE( ts.tv_nsec == 111111110 );
132 WHEN(
"adding more than 1e9 nanoseconds but less than 2e9" )
139 REQUIRE( ts.tv_sec == 2 );
140 REQUIRE( ts.tv_nsec == 0 );
143 REQUIRE( ts.tv_sec == 3 );
144 REQUIRE( ts.tv_nsec == 10 );
147 REQUIRE( ts.tv_sec == 4 );
148 REQUIRE( ts.tv_nsec == 110 );
151 REQUIRE( ts.tv_sec == 5 );
152 REQUIRE( ts.tv_nsec == 1110 );
155 REQUIRE( ts.tv_sec == 6 );
156 REQUIRE( ts.tv_nsec == 11110 );
159 REQUIRE( ts.tv_sec == 7 );
160 REQUIRE( ts.tv_nsec == 111110 );
163 REQUIRE( ts.tv_sec == 8 );
164 REQUIRE( ts.tv_nsec == 1111110 );
167 REQUIRE( ts.tv_sec == 9 );
168 REQUIRE( ts.tv_nsec == 11111110 );
171 REQUIRE( ts.tv_sec == 10 );
172 REQUIRE( ts.tv_nsec == 111111110 );
175 WHEN(
"adding more than 2e9" )
182 REQUIRE( ts.tv_sec == 3 );
183 REQUIRE( ts.tv_nsec == 10 );
256SCENARIO(
"Verify calculation of MJD",
"[timeutils]" )
258 GIVEN(
"a valid Gregorian date" )
260 WHEN(
"integer seconds" )
263 REQUIRE( mjd == 59214.0 );
267 GIVEN(
"a valid Gregorian date" )
269 WHEN(
"floating seconds" )
272 REQUIRE( fabs( mjd - 59214.00011846875 ) < 1e-14 );
281SCENARIO(
"Verify parsing of an ISO 8601 time string",
"[timeutils]" )
283 GIVEN(
"a valid ISO 8601 time string" )
285 WHEN(
"integer seconds" )
287 int yr, mon, day, hr, min;
293 REQUIRE( yr == 2020 );
294 REQUIRE( mon == 12 );
295 REQUIRE( day == 31 );
301 WHEN(
"fractional seconds" )
303 int yr, mon, day, hr, min;
309 REQUIRE( yr == 2020 );
310 REQUIRE( mon == 12 );
311 REQUIRE( day == 31 );
314 REQUIRE( fabs( sec - 10.2357 ) < 1e-14 );
318 GIVEN(
"an invalid ISO 8601 time string" )
320 WHEN(
"string too short" )
322 int yr, mon, day, hr, min;
int ISO8601dateBreakdown(int &yr, int &mon, int &day, int &hr, int &min, double &sec, const std::string &fdate)
Parse an ISO8601 date of the form "YYYY-MM-DDTHH:MM:SS.S" into the individual components.
double Cal2mjd(int yr, int mon, int day, int hr, int min, double sec)
Converts a Gregorian calendar date into modified Julian date (MJD).