1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.orekit.time;
18
19 import java.sql.Timestamp;
20 import java.time.Instant;
21 import java.time.LocalDateTime;
22 import java.time.OffsetDateTime;
23 import java.time.ZoneOffset;
24 import java.time.ZonedDateTime;
25 import java.time.format.DateTimeFormatter;
26 import java.util.Date;
27 import java.util.TimeZone;
28
29 import java.util.concurrent.TimeUnit;
30 import org.hamcrest.CoreMatchers;
31 import org.hamcrest.MatcherAssert;
32 import org.hipparchus.util.FastMath;
33 import org.hipparchus.util.Precision;
34 import org.junit.jupiter.api.Assertions;
35 import org.junit.jupiter.api.BeforeEach;
36 import org.junit.jupiter.api.Test;
37 import org.orekit.OrekitMatchers;
38 import org.orekit.Utils;
39 import org.orekit.annotation.DefaultDataContext;
40 import org.orekit.data.DataContext;
41 import org.orekit.errors.OrekitException;
42 import org.orekit.errors.OrekitIllegalArgumentException;
43 import org.orekit.errors.OrekitMessages;
44 import org.orekit.utils.Constants;
45
46 class AbsoluteDateTest {
47
48 @Test
49 @DefaultDataContext
50 void testStandardEpoch() {
51 TimeScale tai = TimeScalesFactory.getTAI();
52 TimeScale tt = TimeScalesFactory.getTT();
53 Assertions.assertEquals(-210866760000000L, AbsoluteDate.JULIAN_EPOCH.toDate(tt).getTime());
54 Assertions.assertEquals(-3506716800000L, AbsoluteDate.MODIFIED_JULIAN_EPOCH.toDate(tt).getTime());
55 Assertions.assertEquals(-631152000000L, AbsoluteDate.FIFTIES_EPOCH.toDate(tt).getTime());
56 Assertions.assertEquals(-378691200000L, AbsoluteDate.CCSDS_EPOCH.toDate(tai).getTime());
57 Assertions.assertEquals(935280019000L, AbsoluteDate.GALILEO_EPOCH.toDate(tai).getTime());
58 Assertions.assertEquals(315964819000L, AbsoluteDate.GPS_EPOCH.toDate(tai).getTime());
59 Assertions.assertEquals(315964819000L, AbsoluteDate.QZSS_EPOCH.toDate(tai).getTime());
60 Assertions.assertEquals(1136073633000L, AbsoluteDate.BEIDOU_EPOCH.toDate(tai).getTime());
61 Assertions.assertEquals(820443629000L, AbsoluteDate.GLONASS_EPOCH.toDate(tai).getTime());
62 Assertions.assertEquals(935280019000L, AbsoluteDate.NAVIC_EPOCH.toDate(tai).getTime());
63 Assertions.assertEquals(946728000000L, AbsoluteDate.J2000_EPOCH.toDate(tt).getTime());
64 }
65
66 @Test
67 @DefaultDataContext
68 void testStandardEpochStrings() {
69 Assertions.assertEquals("-4712-01-01T12:00:00.000",
70 AbsoluteDate.JULIAN_EPOCH.toString(TimeScalesFactory.getTT()));
71 Assertions.assertEquals("1858-11-17T00:00:00.000",
72 AbsoluteDate.MODIFIED_JULIAN_EPOCH.toString(TimeScalesFactory.getTT()));
73 Assertions.assertEquals("1950-01-01T00:00:00.000",
74 AbsoluteDate.FIFTIES_EPOCH.toString(TimeScalesFactory.getTT()));
75 Assertions.assertEquals("1958-01-01T00:00:00.000",
76 AbsoluteDate.CCSDS_EPOCH.toString(TimeScalesFactory.getTAI()));
77 Assertions.assertEquals("1999-08-21T23:59:47.000",
78 AbsoluteDate.GALILEO_EPOCH.toString(TimeScalesFactory.getUTC()));
79 Assertions.assertEquals("1980-01-06T00:00:00.000",
80 AbsoluteDate.GPS_EPOCH.toString(TimeScalesFactory.getUTC()));
81 Assertions.assertEquals("1980-01-06T00:00:00.000",
82 AbsoluteDate.QZSS_EPOCH.toString(TimeScalesFactory.getUTC()));
83 Assertions.assertEquals("2006-01-01T00:00:00.000",
84 AbsoluteDate.BEIDOU_EPOCH.toString(TimeScalesFactory.getUTC()));
85 Assertions.assertEquals("1995-12-31T21:00:00.000",
86 AbsoluteDate.GLONASS_EPOCH.toString(TimeScalesFactory.getUTC()));
87 Assertions.assertEquals("1999-08-21T23:59:47.000",
88 AbsoluteDate.NAVIC_EPOCH.toString(TimeScalesFactory.getUTC()));
89 Assertions.assertEquals("2000-01-01T12:00:00.000",
90 AbsoluteDate.J2000_EPOCH.toString(TimeScalesFactory.getTT()));
91 Assertions.assertEquals("1970-01-01T00:00:00.000",
92 AbsoluteDate.JAVA_EPOCH.toString(TimeScalesFactory.getUTC()));
93 }
94
95 @Test
96 void testJulianEpochRate() {
97
98 for (int i = 0; i < 10; ++i) {
99 AbsoluteDate j200i = AbsoluteDate.createJulianEpoch(2000.0 + i);
100 AbsoluteDate j2000 = AbsoluteDate.J2000_EPOCH;
101 double expected = i * Constants.JULIAN_YEAR;
102 Assertions.assertEquals(expected, j200i.durationFrom(j2000), 4.0e-15 * expected);
103 }
104
105 }
106
107 @Test
108 void testBesselianEpochRate() {
109
110 for (int i = 0; i < 10; ++i) {
111 AbsoluteDate b195i = AbsoluteDate.createBesselianEpoch(1950.0 + i);
112 AbsoluteDate b1950 = AbsoluteDate.createBesselianEpoch(1950.0);
113 double expected = i * Constants.BESSELIAN_YEAR;
114 Assertions.assertEquals(expected, b195i.durationFrom(b1950), 4.0e-15 * expected);
115 }
116
117 }
118
119 @Test
120 void testLieske() {
121
122
123
124
125
126
127
128 final double publishedEpsilon = 1.0e-6 * Constants.JULIAN_YEAR;
129 checkEpochs(1899.999142, 1900.000000, publishedEpsilon);
130 checkEpochs(1900.000000, 1900.000858, publishedEpsilon);
131 checkEpochs(1950.000000, 1949.999790, publishedEpsilon);
132 checkEpochs(1950.000210, 1950.000000, publishedEpsilon);
133 checkEpochs(2000.000000, 1999.998722, publishedEpsilon);
134 checkEpochs(2000.001278, 2000.000000, publishedEpsilon);
135
136
137 final double accurateEpsilon = 1.2e-13 * Constants.JULIAN_YEAR;
138 checkEpochs(1899.99914161068724704, 1900.00000000000000000, accurateEpsilon);
139 checkEpochs(1900.00000000000000000, 1900.00085837097878165, accurateEpsilon);
140 checkEpochs(1950.00000000000000000, 1949.99979044229979466, accurateEpsilon);
141 checkEpochs(1950.00020956217615449, 1950.00000000000000000, accurateEpsilon);
142 checkEpochs(2000.00000000000000000, 1999.99872251362080766, accurateEpsilon);
143 checkEpochs(2000.00127751366506194, 2000.00000000000000000, accurateEpsilon);
144
145 }
146
147 private void checkEpochs(final double besselianEpoch, final double julianEpoch, final double epsilon) {
148 final AbsoluteDate b = AbsoluteDate.createBesselianEpoch(besselianEpoch);
149 final AbsoluteDate j = AbsoluteDate.createJulianEpoch(julianEpoch);
150 Assertions.assertEquals(0.0, b.durationFrom(j), epsilon);
151 }
152
153 @Test
154 void testParse() {
155 Assertions.assertEquals(AbsoluteDate.MODIFIED_JULIAN_EPOCH,
156 new AbsoluteDate("1858-W46-3", TimeScalesFactory.getTT()));
157 Assertions.assertEquals(AbsoluteDate.JULIAN_EPOCH,
158 new AbsoluteDate("-4712-01-01T12:00:00.000", TimeScalesFactory.getTT()));
159 Assertions.assertEquals(AbsoluteDate.FIFTIES_EPOCH,
160 new AbsoluteDate("1950-01-01", TimeScalesFactory.getTT()));
161 Assertions.assertEquals(AbsoluteDate.CCSDS_EPOCH,
162 new AbsoluteDate("1958-001", TimeScalesFactory.getTAI()));
163 }
164
165 @Test
166 void testLocalTimeParsing() {
167 TimeScale utc = TimeScalesFactory.getUTC();
168 Assertions.assertEquals(new AbsoluteDate("2011-12-31T23:00:00", utc),
169 new AbsoluteDate("2012-01-01T03:30:00+04:30", utc));
170 Assertions.assertEquals(new AbsoluteDate("2011-12-31T23:00:00", utc),
171 new AbsoluteDate("2012-01-01T03:30:00+0430", utc));
172 Assertions.assertEquals(new AbsoluteDate("2011-12-31T23:30:00", utc),
173 new AbsoluteDate("2012-01-01T03:30:00+04", utc));
174 Assertions.assertEquals(new AbsoluteDate("2012-01-01T05:17:00", utc),
175 new AbsoluteDate("2011-12-31T22:17:00-07:00", utc));
176 Assertions.assertEquals(new AbsoluteDate("2012-01-01T05:17:00", utc),
177 new AbsoluteDate("2011-12-31T22:17:00-0700", utc));
178 Assertions.assertEquals(new AbsoluteDate("2012-01-01T05:17:00", utc),
179 new AbsoluteDate("2011-12-31T22:17:00-07", utc));
180 }
181
182 @Test
183 void testTimeZoneDisplay() {
184 final TimeScale utc = TimeScalesFactory.getUTC();
185 final AbsoluteDate date = new AbsoluteDate("2000-01-01T01:01:01.000", utc);
186 Assertions.assertEquals("2000-01-01T01:01:01.000Z", date.toString());
187 Assertions.assertEquals("2000-01-01T11:01:01.000+10:00", date.toString( 600));
188 Assertions.assertEquals("1999-12-31T23:01:01.000-02:00", date.toString(-120));
189 Assertions.assertEquals("2000-01-01T01:01:01.000+00:00", date.toString(0));
190
191
192 TimeZone tz = TimeZone.getTimeZone("Europe/Paris");
193 Assertions.assertEquals("2001-01-22T11:30:00.000+01:00",
194 new AbsoluteDate("2001-01-22T10:30:00", utc).toString(tz));
195
196
197 Assertions.assertEquals("2001-06-23T11:30:00.000+02:00",
198 new AbsoluteDate("2001-06-23T09:30:00", utc).toString(tz));
199
200
201 tz = TimeZone.getTimeZone("UTC");
202 Assertions.assertEquals("2001-06-23T09:30:00.000+00:00",
203 new AbsoluteDate("2001-06-23T09:30:00", utc).toString(tz));
204
205 }
206
207 @Test
208 void testLocalTimeLeapSecond() {
209
210 TimeScale utc = TimeScalesFactory.getUTC();
211 AbsoluteDate beforeLeap = new AbsoluteDate("2012-06-30T23:59:59.8", utc);
212 AbsoluteDate inLeap = new AbsoluteDate("2012-06-30T23:59:60.5", utc);
213 Assertions.assertEquals(0.7, inLeap.durationFrom(beforeLeap), 1.0e-12);
214 for (int minutesFromUTC = -1500; minutesFromUTC < 1500; ++minutesFromUTC) {
215 DateTimeComponents dtcBeforeLeap = beforeLeap.getComponents(minutesFromUTC);
216 DateTimeComponents dtcInsideLeap = inLeap.getComponents(minutesFromUTC);
217 Assertions.assertEquals(dtcBeforeLeap.getDate(), dtcInsideLeap.getDate());
218 Assertions.assertEquals(dtcBeforeLeap.getTime().getHour(), dtcInsideLeap.getTime().getHour());
219 Assertions.assertEquals(dtcBeforeLeap.getTime().getMinute(), dtcInsideLeap.getTime().getMinute());
220 Assertions.assertEquals(minutesFromUTC, dtcBeforeLeap.getTime().getMinutesFromUTC());
221 Assertions.assertEquals(minutesFromUTC, dtcInsideLeap.getTime().getMinutesFromUTC());
222 Assertions.assertEquals(59.8, dtcBeforeLeap.getTime().getSecond(), 1.0e-10);
223 Assertions.assertEquals(60.5, dtcInsideLeap.getTime().getSecond(), 1.0e-10);
224 }
225
226 }
227
228 @Test
229 void testTimeZoneLeapSecond() {
230
231 TimeScale utc = TimeScalesFactory.getUTC();
232 final TimeZone tz = TimeZone.getTimeZone("Europe/Paris");
233 AbsoluteDate localBeforeMidnight = new AbsoluteDate("2012-06-30T21:59:59.800", utc);
234 Assertions.assertEquals("2012-06-30T23:59:59.800+02:00",
235 localBeforeMidnight.toString(tz));
236 Assertions.assertEquals("2012-07-01T00:00:00.800+02:00",
237 localBeforeMidnight.shiftedBy(1.0).toString(tz));
238
239 AbsoluteDate beforeLeap = new AbsoluteDate("2012-06-30T23:59:59.8", utc);
240 AbsoluteDate inLeap = new AbsoluteDate("2012-06-30T23:59:60.5", utc);
241 Assertions.assertEquals(0.7, inLeap.durationFrom(beforeLeap), 1.0e-12);
242 Assertions.assertEquals("2012-07-01T01:59:59.800+02:00", beforeLeap.toString(tz));
243 Assertions.assertEquals("2012-07-01T01:59:60.500+02:00", inLeap.toString(tz));
244
245 }
246
247 @Test
248 void testParseLeap() {
249 TimeScale utc = TimeScalesFactory.getUTC();
250 AbsoluteDate beforeLeap = new AbsoluteDate("2012-06-30T23:59:59.8", utc);
251 AbsoluteDate inLeap = new AbsoluteDate("2012-06-30T23:59:60.5", utc);
252 Assertions.assertEquals(0.7, inLeap.durationFrom(beforeLeap), 1.0e-12);
253 Assertions.assertEquals("2012-06-30T23:59:60.500", inLeap.toString(utc));
254 }
255
256 @Test
257 void testOutput() {
258 TimeScale tt = TimeScalesFactory.getTT();
259 Assertions.assertEquals("1950-01-01T01:01:01.000",
260 AbsoluteDate.FIFTIES_EPOCH.shiftedBy(3661.0).toString(tt));
261 Assertions.assertEquals("2000-01-01T13:01:01.000",
262 AbsoluteDate.J2000_EPOCH.shiftedBy(3661.0).toString(tt));
263 }
264
265 @Test
266 void testJ2000() {
267 Assertions.assertEquals("2000-01-01T12:00:00.000",
268 AbsoluteDate.J2000_EPOCH.toString(TimeScalesFactory.getTT()));
269 Assertions.assertEquals("2000-01-01T11:59:27.816",
270 AbsoluteDate.J2000_EPOCH.toString(TimeScalesFactory.getTAI()));
271 Assertions.assertEquals("2000-01-01T11:58:55.816",
272 AbsoluteDate.J2000_EPOCH.toString(utc));
273 }
274
275 @Test
276 void testFraction() {
277 AbsoluteDate d =
278 new AbsoluteDate(new DateComponents(2000, 1, 1), new TimeComponents(11, 59, 27.816),
279 TimeScalesFactory.getTAI());
280 Assertions.assertEquals(0, d.durationFrom(AbsoluteDate.J2000_EPOCH), 1.0e-10);
281 }
282
283 @Test
284 void testScalesOffset() {
285 AbsoluteDate date = new AbsoluteDate(new DateComponents(2006, 2, 24),
286 new TimeComponents(15, 38, 0),
287 utc);
288 Assertions.assertEquals(33,
289 date.timeScalesOffset(TimeScalesFactory.getTAI(), utc),
290 1.0e-10);
291 }
292
293 @Test
294 void testUTC() {
295 AbsoluteDate date = new AbsoluteDate(new DateComponents(2002, 1, 1),
296 new TimeComponents(0, 0, 1),
297 utc);
298 Assertions.assertEquals("2002-01-01T00:00:01.000Z", date.toString());
299 }
300
301 @Test
302 void test1970() {
303 AbsoluteDate date = new AbsoluteDate(new Date(0L), utc);
304 Assertions.assertEquals("1970-01-01T00:00:00.000Z", date.toString());
305 }
306
307 @Test
308 void test1970Instant() {
309 Assertions.assertEquals("1970-01-01T00:00:00.000Z", new AbsoluteDate(Instant.EPOCH, utc).toString());
310 Assertions.assertEquals("1970-01-01T00:00:00.000Z", new AbsoluteDate(Instant.ofEpochMilli(0L), utc).toString());
311 Assertions.assertEquals("1970-01-01T00:00:00.000Z", new AbsoluteDate(Instant.EPOCH, (UTCScale) utc).toString());
312 Assertions.assertEquals("1970-01-01T00:00:00.000Z", new AbsoluteDate(Instant.ofEpochMilli(0L), (UTCScale) utc).toString());
313 }
314
315 @Test
316 void testInstantAccuracy() {
317 Assertions.assertEquals("1970-01-02T00:16:40.123456789Z", new AbsoluteDate(Instant.ofEpochSecond(87400, 123456789), utc).toString());
318 Assertions.assertEquals("1970-01-07T00:10:00.123456789Z", new AbsoluteDate(Instant.ofEpochSecond(519000, 123456789), utc).toString());
319 Assertions.assertEquals("1970-01-02T00:16:40.123456789Z", new AbsoluteDate(Instant.ofEpochSecond(87400, 123456789), (UTCScale) utc).toString());
320 Assertions.assertEquals("1970-01-07T00:10:00.123456789Z", new AbsoluteDate(Instant.ofEpochSecond(519000, 123456789), (UTCScale) utc).toString());
321 }
322
323 @Test
324 void testToInstant() {
325 Assertions.assertEquals(Instant.ofEpochSecond(0), new AbsoluteDate("1970-01-01T00:00:00.000Z", utc).toInstant());
326 Assertions.assertEquals(Instant.ofEpochSecond(0), new AbsoluteDate("1970-01-01T00:00:00.000Z", utc).toInstant(TimeScalesFactory.getTimeScales()));
327
328 Instant expectedInstant = Instant.ofEpochSecond(519000, 123456789);
329 Assertions.assertEquals(expectedInstant, new AbsoluteDate("1970-01-07T00:10:00.123456789Z", utc).toInstant());
330 Assertions.assertEquals(expectedInstant, new AbsoluteDate("1970-01-07T00:10:00.123456789Z", utc).toInstant(TimeScalesFactory.getTimeScales()));
331
332 Assertions.assertEquals(OffsetDateTime.parse("2024-05-15T09:32:36.123456789Z", DateTimeFormatter.ISO_DATE_TIME).toInstant(),
333 new AbsoluteDate("2024-05-15T09:32:36.123456789Z", utc).toInstant());
334 Assertions.assertEquals(OffsetDateTime.parse("2024-05-15T09:32:36.123456789Z", DateTimeFormatter.ISO_DATE_TIME).toInstant(),
335 new AbsoluteDate("2024-05-15T09:32:36.123456789Z", utc).toInstant(TimeScalesFactory.getTimeScales()));
336 }
337
338 @Test
339 void testUtcGpsOffset() {
340 AbsoluteDate date1 = new AbsoluteDate(new DateComponents(2005, 8, 9),
341 new TimeComponents(16, 31, 17),
342 utc);
343 AbsoluteDate date2 = new AbsoluteDate(new DateComponents(2006, 8, 9),
344 new TimeComponents(16, 31, 17),
345 utc);
346 AbsoluteDate dateRef = new AbsoluteDate(new DateComponents(1980, 1, 6),
347 TimeComponents.H00,
348 utc);
349
350
351 long noLeapGap = ((9347 * 24 + 16) * 60 + 31) * 60 + 17;
352 long realGap = (long) date1.durationFrom(dateRef);
353 Assertions.assertEquals(13L, realGap - noLeapGap);
354
355
356 noLeapGap = ((9712 * 24 + 16) * 60 + 31) * 60 + 17;
357 realGap = (long) date2.durationFrom(dateRef);
358 Assertions.assertEquals(14L, realGap - noLeapGap);
359
360 }
361
362 @Test
363 void testMJDDate() {
364 AbsoluteDate dateA = AbsoluteDate.createMJDDate(51544, 0.5 * Constants.JULIAN_DAY,
365 TimeScalesFactory.getTT());
366 Assertions.assertEquals(0.0, AbsoluteDate.J2000_EPOCH.durationFrom(dateA), 1.0e-15);
367 AbsoluteDate dateB = AbsoluteDate.createMJDDate(53774, 0.0, TimeScalesFactory.getUTC());
368 AbsoluteDate dateC = new AbsoluteDate("2006-02-08T00:00:00", TimeScalesFactory.getUTC());
369 Assertions.assertEquals(0.0, dateC.durationFrom(dateB), 1.0e-15);
370 }
371
372 @Test
373 void testJDDate() {
374 final AbsoluteDate date = AbsoluteDate.createJDDate(2400000, 0.5 * Constants.JULIAN_DAY,
375 TimeScalesFactory.getTT());
376 Assertions.assertEquals(0.0, AbsoluteDate.MODIFIED_JULIAN_EPOCH.durationFrom(date), 1.0e-15);
377 }
378
379
380 @Test
381 void testIssue1310JDDateInTDB() {
382
383
384 final TDBScale TDBscale = TimeScalesFactory.getTDB();
385 final AbsoluteDate refDate = new AbsoluteDate("2023-08-01T00:00:00.000", TDBscale);
386
387
388
389 final AbsoluteDate wrongDate = AbsoluteDate.createJDDate(2460157,
390 Constants.JULIAN_DAY / 2.0d, TDBscale);
391 final AbsoluteDate properDate = AbsoluteDate.createJDDate(2460157,
392 Constants.JULIAN_DAY/2.0d, TDBscale, TimeScalesFactory.getTT());
393
394
395
396
397
398 Assertions.assertEquals(0.0, wrongDate.durationFrom(refDate), 1.270e-05);
399
400
401 Assertions.assertEquals(0.0, properDate.durationFrom(refDate), 2.132e-13);
402 }
403
404 @Test
405 void testMedian() {
406 final AbsoluteDate date1 = new AbsoluteDate(2003, 6, 13, 14, 15,
407 new TimeOffset(53, TimeOffset.SECOND, 12, TimeOffset.ATTOSECOND),
408 TimeScalesFactory.getTT());
409 final AbsoluteDate date2 = new AbsoluteDate(2003, 6, 13, 14, 17,
410 new TimeOffset(25, TimeOffset.SECOND, 120, TimeOffset.ATTOSECOND),
411 TimeScalesFactory.getTT());
412 final AbsoluteDate dateM = new AbsoluteDate(2003, 6, 13, 14, 16,
413 new TimeOffset(39, TimeOffset.SECOND, 66, TimeOffset.ATTOSECOND),
414 TimeScalesFactory.getTT());
415 Assertions.assertEquals(dateM, AbsoluteDate.createMedian(date1, date2));
416 Assertions.assertEquals(dateM, AbsoluteDate.createMedian(date2, date1));
417 }
418
419 @Test
420 void testMedianInfinite() {
421 Assertions.assertEquals(AbsoluteDate.FUTURE_INFINITY,
422 AbsoluteDate.createMedian(AbsoluteDate.FUTURE_INFINITY,
423 AbsoluteDate.ARBITRARY_EPOCH));
424 Assertions.assertEquals(AbsoluteDate.PAST_INFINITY,
425 AbsoluteDate.createMedian(AbsoluteDate.PAST_INFINITY,
426 AbsoluteDate.ARBITRARY_EPOCH));
427 }
428
429 @Test
430 void testOffsets() {
431 final TimeScale tai = TimeScalesFactory.getTAI();
432 AbsoluteDate leapStartUTC = new AbsoluteDate(1976, 12, 31, 23, 59, 59, utc);
433 AbsoluteDate leapEndUTC = new AbsoluteDate(1977, 1, 1, 0, 0, 0, utc);
434 AbsoluteDate leapStartTAI = new AbsoluteDate(1977, 1, 1, 0, 0, 14, tai);
435 AbsoluteDate leapEndTAI = new AbsoluteDate(1977, 1, 1, 0, 0, 16, tai);
436 Assertions.assertEquals(leapStartUTC, leapStartTAI);
437 Assertions.assertEquals(leapEndUTC, leapEndTAI);
438 Assertions.assertEquals(1, leapEndUTC.offsetFrom(leapStartUTC, utc), 1.0e-10);
439 Assertions.assertEquals(1, leapEndTAI.offsetFrom(leapStartTAI, utc), 1.0e-10);
440 Assertions.assertEquals(2, leapEndUTC.offsetFrom(leapStartUTC, tai), 1.0e-10);
441 Assertions.assertEquals(2, leapEndTAI.offsetFrom(leapStartTAI, tai), 1.0e-10);
442 Assertions.assertEquals(2, leapEndUTC.durationFrom(leapStartUTC), 1.0e-10);
443 Assertions.assertEquals(2, leapEndTAI.durationFrom(leapStartTAI), 1.0e-10);
444 }
445
446 @Test
447 void testBeforeAndAfterLeap() {
448 final TimeScale tai = TimeScalesFactory.getTAI();
449 AbsoluteDate leapStart = new AbsoluteDate(1977, 1, 1, 0, 0, 14, tai);
450 AbsoluteDate leapEnd = new AbsoluteDate(1977, 1, 1, 0, 0, 16, tai);
451 for (int i = -10; i < 10; ++i) {
452 final double dt = 1.1 * (2 * i - 1);
453 AbsoluteDate d1 = leapStart.shiftedBy(dt);
454 AbsoluteDate d2 = new AbsoluteDate(leapStart, dt, tai);
455 AbsoluteDate d3 = new AbsoluteDate(leapStart, dt, utc);
456 AbsoluteDate d4 = new AbsoluteDate(leapEnd, dt, tai);
457 AbsoluteDate d5 = new AbsoluteDate(leapEnd, dt, utc);
458 Assertions.assertTrue(FastMath.abs(d1.durationFrom(d2)) < 1.0e-10);
459 if (dt < 0) {
460 Assertions.assertTrue(FastMath.abs(d2.durationFrom(d3)) < 1.0e-10);
461 Assertions.assertTrue(d4.durationFrom(d5) > (1.0 - 1.0e-10));
462 } else {
463 Assertions.assertTrue(d2.durationFrom(d3) < (-1.0 + 1.0e-10));
464 Assertions.assertTrue(FastMath.abs(d4.durationFrom(d5)) < 1.0e-10);
465 }
466 }
467 }
468
469 @Test
470 void testSymmetry() {
471 final TimeScale tai = TimeScalesFactory.getTAI();
472 AbsoluteDate leapStart = new AbsoluteDate(1977, 1, 1, 0, 0, 14, tai);
473 for (int i = -10; i < 10; ++i) {
474 final double dt = 1.1 * (2 * i - 1);
475 Assertions.assertEquals(dt, new AbsoluteDate(leapStart, dt, utc).offsetFrom(leapStart, utc), 1.0e-10);
476 Assertions.assertEquals(dt, new AbsoluteDate(leapStart, dt, tai).offsetFrom(leapStart, tai), 1.0e-10);
477 Assertions.assertEquals(dt, leapStart.shiftedBy(dt).durationFrom(leapStart), 1.0e-10);
478 }
479 }
480
481 @SuppressWarnings("unlikely-arg-type")
482 @Test
483 void testEquals() {
484 AbsoluteDate d1 =
485 new AbsoluteDate(new DateComponents(2006, 2, 25),
486 new TimeComponents(17, 10, 34),
487 utc);
488 AbsoluteDate d2 = new AbsoluteDate(new DateComponents(2006, 2, 25),
489 new TimeComponents(17, 10, 0),
490 utc).shiftedBy(34);
491 Assertions.assertEquals(d1, d2);
492 Assertions.assertNotEquals(d1, this);
493 }
494
495 @Test
496 void testComponents() {
497
498
499 DateComponents date = new DateComponents(2000, 1, 1);
500 TimeComponents time = new TimeComponents(11, 59, 10);
501 TimeScale[] scales = {
502 TimeScalesFactory.getTAI(), TimeScalesFactory.getUTC(),
503 TimeScalesFactory.getTT(), TimeScalesFactory.getTCG()
504 };
505 for (int i = 0; i < scales.length; ++i) {
506 AbsoluteDate in = new AbsoluteDate(date, time, scales[i]);
507 for (int j = 0; j < scales.length; ++j) {
508 DateTimeComponents pair = in.getComponents(scales[j]);
509 if (i == j) {
510 Assertions.assertEquals(date, pair.getDate());
511 Assertions.assertEquals(time, pair.getTime());
512 } else {
513 Assertions.assertNotSame(date, pair.getDate());
514 Assertions.assertNotSame(time, pair.getTime());
515 }
516 }
517 }
518 }
519
520 @Test
521 void testMonth() {
522 TimeScale utc = TimeScalesFactory.getUTC();
523 Assertions.assertEquals(new AbsoluteDate(2011, 2, 23, utc),
524 new AbsoluteDate(2011, Month.FEBRUARY, 23, utc));
525 Assertions.assertEquals(new AbsoluteDate(2011, 2, 23, 1, 2, 3.4, utc),
526 new AbsoluteDate(2011, Month.FEBRUARY, 23, 1, 2, 3.4, utc));
527 }
528
529 @Test
530 void testCCSDSUnsegmentedNoExtension() {
531
532 AbsoluteDate reference = new AbsoluteDate("2002-05-23T12:34:56.789", utc);
533 double lsb = FastMath.pow(2.0, -24);
534
535 byte[] timeCCSDSEpoch = new byte[] { 0x53, 0x7F, 0x40, -0x70, -0x37, -0x05, -0x19 };
536 for (int preamble = 0x00; preamble < 0x80; ++preamble) {
537 if (preamble == 0x1F) {
538
539 AbsoluteDate ccsds1 =
540 AbsoluteDate.parseCCSDSUnsegmentedTimeCode((byte) preamble, (byte) 0x0, timeCCSDSEpoch, null);
541 Assertions.assertEquals(0, ccsds1.durationFrom(reference), lsb / 2);
542 } else {
543 try {
544 AbsoluteDate.parseCCSDSUnsegmentedTimeCode((byte) preamble, (byte) 0x0, timeCCSDSEpoch, null);
545 Assertions.fail("an exception should have been thrown");
546 } catch (OrekitException iae) {
547
548 }
549
550 }
551 }
552
553
554 byte[] timeJ2000Epoch = new byte[] { 0x04, 0x7E, -0x0B, -0x10, -0x07, 0x16, -0x79 };
555 try {
556 AbsoluteDate.parseCCSDSUnsegmentedTimeCode((byte) 0x2F, (byte) 0x0, timeJ2000Epoch, null);
557 Assertions.fail("an exception should have been thrown");
558 } catch (OrekitException iae) {
559
560 }
561
562
563 AbsoluteDate ccsds3 =
564 AbsoluteDate.parseCCSDSUnsegmentedTimeCode((byte) 0x2F, (byte) 0x0, timeJ2000Epoch, AbsoluteDate.J2000_EPOCH);
565 Assertions.assertEquals(0, ccsds3.durationFrom(reference), lsb / 2);
566
567 }
568
569 @Test
570 void testCCSDSUnsegmentedWithExtendedPreamble() {
571
572 AbsoluteDate reference = new AbsoluteDate("2095-03-03T22:02:45.789012345678901", utc);
573 int leap = (int) FastMath.rint(utc.offsetFromTAI(reference).toDouble());
574
575 byte extendedPreamble = (byte) -0x80;
576 byte identification = (byte) 0x10;
577 byte coarseLength1 = (byte) 0x0C;
578 byte fineLength1 = (byte) 0x03;
579 byte coarseLength2 = (byte) 0x20;
580 byte fineLength2 = (byte) 0x10;
581 byte[] timeCCSDSEpoch = new byte[] {
582 0x01, 0x02, 0x03, 0x04, (byte)(0x05 - leap),
583 -0x37, -0x04, -0x4A, -0x74, -0x2C, -0x3C, -0x48
584 };
585 byte preamble1 = (byte) (extendedPreamble | identification | coarseLength1 | fineLength1);
586 byte preamble2 = (byte) (coarseLength2 | fineLength2);
587 AbsoluteDate ccsds1 =
588 AbsoluteDate.parseCCSDSUnsegmentedTimeCode(preamble1, preamble2, timeCCSDSEpoch, null);
589
590
591
592 Assertions.assertEquals(-8.0e-18, ccsds1.durationFrom(reference), 1.0e-18);
593
594 }
595
596 @Test
597 void testCCSDSDaySegmented() {
598
599 AbsoluteDate reference = new AbsoluteDate("2002-05-23T12:34:56.789012345678", TimeScalesFactory.getUTC());
600 double lsb = 1.0e-13;
601 byte[] timeCCSDSEpoch = new byte[] { 0x3F, 0x55, 0x02, -0x4D, 0x2C, -0x6B, 0x00, -0x44, 0x61, 0x4E };
602
603 for (int preamble = 0x00; preamble < 0x100; ++preamble) {
604 if (preamble == 0x42) {
605
606 AbsoluteDate ccsds1 =
607 AbsoluteDate.parseCCSDSDaySegmentedTimeCode((byte) preamble, timeCCSDSEpoch, null);
608 Assertions.assertEquals(0, ccsds1.durationFrom(reference), lsb / 2);
609 } else {
610 try {
611 AbsoluteDate.parseCCSDSDaySegmentedTimeCode((byte) preamble, timeCCSDSEpoch, null);
612 Assertions.fail("an exception should have been thrown");
613 } catch (OrekitException iae) {
614
615 }
616
617 }
618 }
619
620
621 byte[] timeJ2000Epoch = new byte[] { 0x03, 0x69, 0x02, -0x4D, 0x2C, -0x6B, 0x00, -0x44, 0x61, 0x4E };
622 try {
623 AbsoluteDate.parseCCSDSDaySegmentedTimeCode((byte) 0x4A, timeJ2000Epoch, null);
624 Assertions.fail("an exception should have been thrown");
625 } catch (OrekitException iae) {
626
627 }
628
629
630 AbsoluteDate ccsds3 =
631 AbsoluteDate.parseCCSDSDaySegmentedTimeCode((byte) 0x4A, timeJ2000Epoch, DateComponents.J2000_EPOCH);
632 Assertions.assertEquals(0, ccsds3.durationFrom(reference), lsb / 2);
633
634
635 byte[] timeMicrosecond = new byte[] { 0x03, 0x69, 0x02, -0x4D, 0x2C, -0x6B, 0x00, 0x0C };
636 AbsoluteDate ccsds4 =
637 AbsoluteDate.parseCCSDSDaySegmentedTimeCode((byte) 0x49, timeMicrosecond, DateComponents.J2000_EPOCH);
638 Assertions.assertEquals(-0.345678e-6, ccsds4.durationFrom(reference), lsb / 2);
639
640 }
641
642 @Test
643 void testCCSDSCalendarSegmented() {
644
645 AbsoluteDate reference = new AbsoluteDate("2002-05-23T12:34:56.789012345678", TimeScalesFactory.getUTC());
646 double lsb = 1.0e-13;
647
648
649 byte[] timeMonthDay = new byte[] { 0x07, -0x2E, 0x05, 0x17, 0x0C, 0x22, 0x38, 0x4E, 0x5A, 0x0C, 0x22, 0x38, 0x4E };
650 for (int preamble = 0x00; preamble < 0x100; ++preamble) {
651 if (preamble == 0x56) {
652 AbsoluteDate ccsds1 =
653 AbsoluteDate.parseCCSDSCalendarSegmentedTimeCode((byte) preamble, timeMonthDay);
654 Assertions.assertEquals(0, ccsds1.durationFrom(reference), lsb / 2);
655 } else {
656 try {
657 AbsoluteDate.parseCCSDSCalendarSegmentedTimeCode((byte) preamble, timeMonthDay);
658 Assertions.fail("an exception should have been thrown");
659 } catch (OrekitException iae) {
660
661 } catch (IllegalArgumentException iae) {
662
663
664 Assertions.assertEquals(preamble & 0x08, 0x08);
665 }
666
667 }
668 }
669
670
671 byte[] timeDay = new byte[] { 0x07, -0x2E, 0x00, -0x71, 0x0C, 0x22, 0x38, 0x4E, 0x5A, 0x0C, 0x22, 0x38, 0x4E };
672 for (int preamble = 0x00; preamble < 0x100; ++preamble) {
673 if (preamble == 0x5E) {
674 AbsoluteDate ccsds1 =
675 AbsoluteDate.parseCCSDSCalendarSegmentedTimeCode((byte) preamble, timeDay);
676 Assertions.assertEquals(0, ccsds1.durationFrom(reference), lsb / 2);
677 } else {
678 try {
679 AbsoluteDate.parseCCSDSCalendarSegmentedTimeCode((byte) preamble, timeDay);
680 Assertions.fail("an exception should have been thrown");
681 } catch (OrekitException iae) {
682
683 } catch (IllegalArgumentException iae) {
684
685
686 Assertions.assertEquals(preamble & 0x08, 0x00);
687 }
688
689 }
690 }
691
692
693 byte[] timeMicrosecond = new byte[] { 0x07, -0x2E, 0x00, -0x71, 0x0C, 0x22, 0x38, 0x4E, 0x5A, 0x0C };
694 AbsoluteDate ccsds4 =
695 AbsoluteDate.parseCCSDSCalendarSegmentedTimeCode((byte) 0x5B, timeMicrosecond);
696 Assertions.assertEquals(-0.345678e-6, ccsds4.durationFrom(reference), lsb / 2);
697
698 }
699
700 @Test
701 void testExpandedConstructors() {
702 Assertions.assertThrows(IllegalArgumentException.class, () -> {
703 Assertions.assertEquals(new AbsoluteDate(new DateComponents(2002, 5, 28),
704 new TimeComponents(15, 30, 0),
705 TimeScalesFactory.getUTC()),
706 new AbsoluteDate(2002, 5, 28, 15, 30, 0, TimeScalesFactory.getUTC()));
707 Assertions.assertEquals(new AbsoluteDate(new DateComponents(2002, 5, 28), TimeComponents.H00,
708 TimeScalesFactory.getUTC()),
709 new AbsoluteDate(2002, 5, 28, TimeScalesFactory.getUTC()));
710 new AbsoluteDate(2002, 5, 28, 25, 30, 0, TimeScalesFactory.getUTC());
711 });
712 }
713
714 @Test
715 void testHashcode() {
716 AbsoluteDate d1 =
717 new AbsoluteDate(new DateComponents(2006, 2, 25),
718 new TimeComponents(17, 10, 34),
719 utc);
720 AbsoluteDate d2 = new AbsoluteDate(new DateComponents(2006, 2, 25),
721 new TimeComponents(17, 10, 0),
722 utc).shiftedBy(34);
723 Assertions.assertEquals(d1.hashCode(), d2.hashCode());
724 Assertions.assertTrue(d1.hashCode() != d1.shiftedBy(1.0e-3).hashCode());
725 }
726
727 @Test
728 void testInfinity() {
729 Assertions.assertTrue(AbsoluteDate.JULIAN_EPOCH.compareTo(AbsoluteDate.PAST_INFINITY) > 0);
730 Assertions.assertTrue(AbsoluteDate.JULIAN_EPOCH.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0);
731 Assertions.assertTrue(AbsoluteDate.J2000_EPOCH.compareTo(AbsoluteDate.PAST_INFINITY) > 0);
732 Assertions.assertTrue(AbsoluteDate.J2000_EPOCH.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0);
733 Assertions.assertEquals(0, AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.PAST_INFINITY));
734 Assertions.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.JULIAN_EPOCH) < 0);
735 Assertions.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.J2000_EPOCH) < 0);
736 Assertions.assertTrue(AbsoluteDate.PAST_INFINITY.compareTo(AbsoluteDate.FUTURE_INFINITY) < 0);
737 Assertions.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.JULIAN_EPOCH) > 0);
738 Assertions.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.J2000_EPOCH) > 0);
739 Assertions.assertTrue(AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.PAST_INFINITY) > 0);
740 Assertions.assertEquals(0, AbsoluteDate.FUTURE_INFINITY.compareTo(AbsoluteDate.FUTURE_INFINITY));
741 Assertions.assertTrue(Double.isInfinite(AbsoluteDate.FUTURE_INFINITY.durationFrom(AbsoluteDate.J2000_EPOCH)));
742 Assertions.assertTrue(Double.isInfinite(AbsoluteDate.FUTURE_INFINITY.durationFrom(AbsoluteDate.PAST_INFINITY)));
743 Assertions.assertTrue(Double.isInfinite(AbsoluteDate.PAST_INFINITY.durationFrom(AbsoluteDate.J2000_EPOCH)));
744 Assertions.assertTrue(Double.isNaN(AbsoluteDate.FUTURE_INFINITY.durationFrom(AbsoluteDate.FUTURE_INFINITY)));
745 Assertions.assertTrue(Double.isNaN(AbsoluteDate.PAST_INFINITY.durationFrom(AbsoluteDate.PAST_INFINITY)));
746 Assertions.assertEquals("5881610-07-11T23:59:59.999Z", AbsoluteDate.FUTURE_INFINITY.toString());
747 Assertions.assertEquals("-5877490-03-03T00:00:00.000Z", AbsoluteDate.PAST_INFINITY.toString());
748 Assertions.assertTrue(AbsoluteDate.FUTURE_INFINITY.equals(AbsoluteDate.FUTURE_INFINITY));
749 Assertions.assertTrue(AbsoluteDate.PAST_INFINITY.equals(AbsoluteDate.PAST_INFINITY));
750 Assertions.assertFalse(AbsoluteDate.PAST_INFINITY.equals(AbsoluteDate.FUTURE_INFINITY));
751 Assertions.assertFalse(AbsoluteDate.FUTURE_INFINITY.equals(AbsoluteDate.PAST_INFINITY));
752
753 Assertions.assertEquals(Double.POSITIVE_INFINITY, AbsoluteDate.J2000_EPOCH.durationFrom(AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(Double.NEGATIVE_INFINITY)));
754 Assertions.assertEquals(Double.NEGATIVE_INFINITY, AbsoluteDate.J2000_EPOCH.durationFrom(AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(Double.POSITIVE_INFINITY)));
755
756 }
757
758 @Test
759 void testCompareTo() {
760
761 AbsoluteDate epoch =
762 new AbsoluteDate(2000, 1, 1, 12, 0, 0, TimeScalesFactory.getTAI());
763 Assertions.assertTrue(AbsoluteDate.JULIAN_EPOCH.compareTo(epoch) < 0);
764 Assertions.assertTrue(epoch.compareTo(AbsoluteDate.JULIAN_EPOCH) > 0);
765
766 AbsoluteDate d = epoch;
767 double epsilon = 1.0 - FastMath.nextDown(1.0);
768 Assertions.assertTrue(d.compareTo(d.shiftedBy(epsilon)) < 0);
769 Assertions.assertEquals(0, d.compareTo(d.shiftedBy(0)));
770 Assertions.assertTrue(d.compareTo(d.shiftedBy(-epsilon)) > 0);
771
772 d = epoch.shiftedBy(496891466)
773 .shiftedBy(0.7320114066633323)
774 .shiftedBy(-19730.732011406664);
775
776 AbsoluteDate d1 = epoch.shiftedBy(496891466 - 19730);
777 Assertions.assertTrue(d.compareTo(d1) < 0);
778
779 d1 = d1.shiftedBy(-1e-16);
780 Assertions.assertTrue(d.compareTo(d1) < 0,"" + d.durationFrom(d1));
781
782
783
784
785
786
787
788
789 }
790
791 @Test
792 void testIsEqualTo() {
793 Assertions.assertTrue(present.isEqualTo(present));
794 Assertions.assertTrue(present.isEqualTo(presentToo));
795 Assertions.assertFalse(present.isEqualTo(past));
796 Assertions.assertFalse(present.isEqualTo(future));
797 }
798
799 @Test
800 void testIsCloseTo() {
801 double tolerance = 10;
802 TimeStamped closeToPresent = new AnyTimeStamped(present.shiftedBy(5));
803 Assertions.assertTrue(present.isCloseTo(present, tolerance));
804 Assertions.assertTrue(present.isCloseTo(presentToo, tolerance));
805 Assertions.assertTrue(present.isCloseTo(closeToPresent, tolerance));
806 Assertions.assertFalse(present.isCloseTo(past, tolerance));
807 Assertions.assertFalse(present.isCloseTo(future, tolerance));
808 }
809
810 @Test
811 void testIsBefore() {
812 Assertions.assertFalse(present.isBefore(past));
813 Assertions.assertFalse(present.isBefore(present));
814 Assertions.assertFalse(present.isBefore(presentToo));
815 Assertions.assertTrue(present.isBefore(future));
816 }
817
818 @Test
819 void testIsAfter() {
820 Assertions.assertTrue(present.isAfter(past));
821 Assertions.assertFalse(present.isAfter(present));
822 Assertions.assertFalse(present.isAfter(presentToo));
823 Assertions.assertFalse(present.isAfter(future));
824 }
825
826 @Test
827 void testIsBeforeOrEqualTo() {
828 Assertions.assertFalse(present.isBeforeOrEqualTo(past));
829 Assertions.assertTrue(present.isBeforeOrEqualTo(present));
830 Assertions.assertTrue(present.isBeforeOrEqualTo(presentToo));
831 Assertions.assertTrue(present.isBeforeOrEqualTo(future));
832 }
833
834 @Test
835 void testIsAfterOrEqualTo() {
836 Assertions.assertTrue(present.isAfterOrEqualTo(past));
837 Assertions.assertTrue(present.isAfterOrEqualTo(present));
838 Assertions.assertTrue(present.isAfterOrEqualTo(presentToo));
839 Assertions.assertFalse(present.isAfterOrEqualTo(future));
840 }
841
842 @Test
843 void testIsBetween() {
844 Assertions.assertTrue(present.isBetween(past, future));
845 Assertions.assertTrue(present.isBetween(future, past));
846 Assertions.assertFalse(past.getDate().isBetween(present, future));
847 Assertions.assertFalse(past.getDate().isBetween(future, present));
848 Assertions.assertFalse(future.getDate().isBetween(past, present));
849 Assertions.assertFalse(future.getDate().isBetween(present, past));
850 Assertions.assertFalse(present.isBetween(present, future));
851 Assertions.assertFalse(present.isBetween(past, present));
852 Assertions.assertFalse(present.isBetween(past, past));
853 Assertions.assertFalse(present.isBetween(present, present));
854 Assertions.assertFalse(present.isBetween(present, presentToo));
855 }
856
857 @Test
858 void testIsBetweenOrEqualTo() {
859 Assertions.assertTrue(present.isBetweenOrEqualTo(past, future));
860 Assertions.assertTrue(present.isBetweenOrEqualTo(future, past));
861 Assertions.assertFalse(past.getDate().isBetweenOrEqualTo(present, future));
862 Assertions.assertFalse(past.getDate().isBetweenOrEqualTo(future, present));
863 Assertions.assertFalse(future.getDate().isBetweenOrEqualTo(past, present));
864 Assertions.assertFalse(future.getDate().isBetweenOrEqualTo(present, past));
865 Assertions.assertTrue(present.isBetweenOrEqualTo(present, future));
866 Assertions.assertTrue(present.isBetweenOrEqualTo(past, present));
867 Assertions.assertFalse(present.isBetweenOrEqualTo(past, past));
868 Assertions.assertTrue(present.isBetweenOrEqualTo(present, present));
869 Assertions.assertTrue(present.isBetweenOrEqualTo(present, presentToo));
870 }
871
872 @Test
873 void testAccuracy() {
874 TimeScale tai = TimeScalesFactory.getTAI();
875 double sec = 0.281;
876 AbsoluteDate t = new AbsoluteDate(2010, 6, 21, 18, 42, sec, tai);
877 double recomputedSec = t.getComponents(tai).getTime().getSecond();
878 Assertions.assertEquals(sec, recomputedSec, FastMath.ulp(sec));
879 }
880
881 @Test
882 void testShiftPastInfinity() {
883 AbsoluteDate shifted = AbsoluteDate.PAST_INFINITY.shiftedBy(Constants.JULIAN_DAY);
884 Assertions.assertEquals(AbsoluteDate.PAST_INFINITY.getSeconds(), shifted.getSeconds());
885 Assertions.assertEquals(AbsoluteDate.PAST_INFINITY.getAttoSeconds(), shifted.getAttoSeconds());
886 }
887
888 @Test
889 void testShiftFutureInfinity() {
890 AbsoluteDate shifted = AbsoluteDate.FUTURE_INFINITY.shiftedBy(Constants.JULIAN_DAY);
891 Assertions.assertEquals(AbsoluteDate.FUTURE_INFINITY.getSeconds(), shifted.getSeconds());
892 Assertions.assertEquals(AbsoluteDate.FUTURE_INFINITY.getAttoSeconds(), shifted.getAttoSeconds());
893 }
894
895 @Test
896 void testSubFemtoSecondPositiveShift() {
897 TimeScale tai = TimeScalesFactory.getTAI();
898 AbsoluteDate since = new AbsoluteDate(2008, 4, 7, 0, 53, 0.0078125, tai);
899 double deltaT = 1.0e-17;
900 AbsoluteDate shifted = since.shiftedBy(deltaT);
901 Assertions.assertEquals(deltaT, shifted.durationFrom(since), 1.0e-25);
902 }
903
904 @Test
905 void testSubFemtoSecondNegativeShift() {
906 TimeScale tai = TimeScalesFactory.getTAI();
907 AbsoluteDate since = new AbsoluteDate(2008, 4, 7, 0, 53, 0.0078125, tai);
908 double deltaT = -1.0e-17;
909 AbsoluteDate shifted = since.shiftedBy(deltaT);
910 Assertions.assertEquals(deltaT, shifted.durationFrom(since), 1.0e-25);
911 }
912
913 @Test
914 void testIterationAccuracy() {
915
916 final TimeScale tai = TimeScalesFactory.getTAI();
917 final AbsoluteDate t0 = new AbsoluteDate(2010, 6, 21, 18, 42, 0.281, tai);
918
919
920
921 checkIteration(0.1, t0, 10000, 3.0, -0.3874, 1.0e-4);
922
923
924
925 checkIteration(0.125, t0, 10000, 1.0e-15, 0.0, 1.0e-15);
926
927 }
928
929 private void checkIteration(final double step, final AbsoluteDate t0, final int nMax,
930 final double maxErrorFactor,
931 final double expectedMean, final double meanTolerance) {
932 final double epsilon = FastMath.ulp(step);
933 AbsoluteDate iteratedDate = t0;
934 double mean = 0;
935 for (int i = 1; i < nMax; ++i) {
936 iteratedDate = iteratedDate.shiftedBy(step);
937 AbsoluteDate directDate = t0.shiftedBy(i * step);
938 final double error = iteratedDate.durationFrom(directDate);
939 mean += error / (i * epsilon);
940 Assertions.assertEquals(0.0, iteratedDate.durationFrom(directDate), maxErrorFactor * i * epsilon);
941 }
942 mean /= nMax;
943 Assertions.assertEquals(expectedMean, mean, meanTolerance);
944 }
945
946 @Test
947 void testIssue142() {
948
949 final AbsoluteDate epoch = AbsoluteDate.JAVA_EPOCH;
950 final TimeScale utc = TimeScalesFactory.getUTC();
951
952 Assertions.assertEquals("1970-01-01T00:00:00.000", epoch.toString(utc));
953 Assertions.assertEquals(0.0, epoch.durationFrom(new AbsoluteDate(1970, 1, 1, utc)), 1.0e-15);
954 Assertions.assertEquals(8.000082,
955 epoch.durationFrom(new AbsoluteDate(DateComponents.JAVA_EPOCH, TimeScalesFactory.getTAI())),
956 1.0e-15);
957
958
959 final TimeOffset offset = new TimeOffset(1143849600L, 0L);
960 final AbsoluteDate ad = new AbsoluteDate(epoch, offset, TimeScalesFactory.getUTC());
961 Assertions.assertEquals("2006-04-01T00:00:00.000", ad.toString(utc));
962
963 }
964
965 @Test
966 void testIssue148() {
967 final TimeScale utc = TimeScalesFactory.getUTC();
968 AbsoluteDate t0 = new AbsoluteDate(2012, 6, 30, 23, 59, 50.0, utc);
969 DateTimeComponents components = t0.shiftedBy(11.0 - 200 * Precision.EPSILON).getComponents(utc);
970 Assertions.assertEquals(2012, components.getDate().getYear());
971 Assertions.assertEquals( 6, components.getDate().getMonth());
972 Assertions.assertEquals( 30, components.getDate().getDay());
973 Assertions.assertEquals( 23, components.getTime().getHour());
974 Assertions.assertEquals( 59, components.getTime().getMinute());
975 Assertions.assertEquals( 61 - 200 * Precision.EPSILON,
976 components.getTime().getSecond(), 1.0e-15);
977 }
978
979 @Test
980 void testIssue149() {
981 final TimeScale utc = TimeScalesFactory.getUTC();
982 AbsoluteDate t0 = new AbsoluteDate(2012, 6, 30, 23, 59, 59, utc);
983 DateTimeComponents components = t0.shiftedBy(1.0 - Precision.EPSILON).getComponents(utc);
984 Assertions.assertEquals(2012, components.getDate().getYear());
985 Assertions.assertEquals( 6, components.getDate().getMonth());
986 Assertions.assertEquals( 30, components.getDate().getDay());
987 Assertions.assertEquals( 23, components.getTime().getHour());
988 Assertions.assertEquals( 59, components.getTime().getMinute());
989 Assertions.assertEquals( 60 - Precision.EPSILON,
990 components.getTime().getSecond(), 1.0e-15);
991 }
992
993 @Test
994 void testWrapAtMinuteEnd() {
995 TimeScale tai = TimeScalesFactory.getTAI();
996 TimeScale utc = TimeScalesFactory.getUTC();
997 AbsoluteDate date0 = new AbsoluteDate(DateComponents.J2000_EPOCH, TimeComponents.H12, tai);
998 AbsoluteDate ref = date0.shiftedBy(new TimeOffset(496891466L, 732011406663332300L));
999 AbsoluteDate date = ref.shiftedBy(new TimeOffset(597L, 900970042626200000L).negate().multiply(33));
1000 DateTimeComponents dtc = date.getComponents(utc);
1001 Assertions.assertEquals( 2015, dtc.getDate().getYear());
1002 Assertions.assertEquals( 9, dtc.getDate().getMonth());
1003 Assertions.assertEquals( 30, dtc.getDate().getDay());
1004 Assertions.assertEquals( 7, dtc.getTime().getHour());
1005 Assertions.assertEquals( 54, dtc.getTime().getMinute());
1006 Assertions.assertEquals( 59L, dtc.getTime().getSplitSecond().getSeconds());
1007 Assertions.assertEquals( 999999999998732300L, dtc.getTime().getSplitSecond().getAttoSeconds());
1008 Assertions.assertEquals("2015-09-30T07:54:59.9999999999987323", date.toString(utc));
1009 AbsoluteDate beforeMidnight = new AbsoluteDate(2008, 2, 29, 23, 59, new TimeOffset(59L, 999400000000000000L), utc);
1010 AbsoluteDate stillBeforeMidnight = beforeMidnight.shiftedBy(new TimeOffset(0L, 200000000000000L));
1011 Assertions.assertEquals(59.9994, beforeMidnight.getComponents(utc).getTime().getSecond(), 1.0e-15);
1012 Assertions.assertEquals(59.9996, stillBeforeMidnight.getComponents(utc).getTime().getSecond(), 1.0e-15);
1013 Assertions.assertEquals("2008-02-29T23:59:59.9994", beforeMidnight.toString(utc));
1014 Assertions.assertEquals("2008-02-29T23:59:59.9996", stillBeforeMidnight.toString(utc));
1015 }
1016
1017
1018 @Test
1019 void testLastLeapOutput() {
1020 UTCScale utc = TimeScalesFactory.getUTC();
1021 AbsoluteDate t = utc.getLastKnownLeapSecond();
1022 Assertions.assertEquals("23:59:59.500", t.shiftedBy(-0.5).toString(utc).substring(11));
1023 Assertions.assertEquals("23:59:60.000", t.shiftedBy( 0.0).toString(utc).substring(11));
1024 Assertions.assertEquals("23:59:60.500", t.shiftedBy(+0.5).toString(utc).substring(11));
1025 }
1026
1027 @Test
1028 void testWrapBeforeLeap() {
1029 UTCScale utc = TimeScalesFactory.getUTC();
1030 AbsoluteDate t = new AbsoluteDate("2015-06-30T23:59:59.999999", utc);
1031 Assertions.assertEquals(2015, t.getComponents(utc).getDate().getYear());
1032 Assertions.assertEquals( 6, t.getComponents(utc).getDate().getMonth());
1033 Assertions.assertEquals( 30, t.getComponents(utc).getDate().getDay());
1034 Assertions.assertEquals( 23, t.getComponents(utc).getTime().getHour());
1035 Assertions.assertEquals( 59, t.getComponents(utc).getTime().getMinute());
1036 Assertions.assertEquals( 59.999999, t.getComponents(utc).getTime().getSecond(), 1.0e-6);
1037 Assertions.assertEquals("2015-06-30T23:59:59.999999", t.toStringWithoutUtcOffset(utc, 6));
1038 Assertions.assertEquals("2015-07-01T02:59:59.999999", t.toStringWithoutUtcOffset(TimeScalesFactory.getGLONASS(), 6));
1039 }
1040
1041 @Test
1042 void testMjdInLeap() {
1043
1044 AbsoluteDate date1 = new AbsoluteDate(2008, 12, 31, 23, 59, 60.5, utc);
1045
1046
1047 DateTimeComponents date1Components = date1.getComponents(utc);
1048 int mjd = date1Components.getDate().getMJD();
1049 double seconds = date1Components.getTime().getSecondsInUTCDay();
1050 Assertions.assertEquals(54831, mjd);
1051 Assertions.assertEquals(86400.5, seconds, 0);
1052
1053
1054 AbsoluteDate date2 = AbsoluteDate.createMJDDate(mjd, seconds, utc);
1055 Assertions.assertEquals(date1, date2);
1056
1057
1058 try {
1059 AbsoluteDate.createMJDDate(mjd, seconds + 1.0, utc);
1060 Assertions.fail("an exception should have been thrown");
1061 } catch (OrekitIllegalArgumentException oiae) {
1062 Assertions.assertEquals(OrekitMessages.OUT_OF_RANGE_SECONDS_NUMBER_DETAIL, oiae.getSpecifier());
1063 Assertions.assertEquals(86401.5, (Double) oiae.getParts()[0], 0);
1064 Assertions.assertEquals(0, ((Number) oiae.getParts()[1]).doubleValue(), 0);
1065 Assertions.assertEquals(86401, ((Number) oiae.getParts()[2]).doubleValue(), 0);
1066 }
1067
1068 }
1069
1070 @Test
1071 void testIssueTimesStampAccuracy() {
1072 String testString = "2019-02-01T13:06:03.115";
1073 TimeScale timeScale=TimeScalesFactory.getUTC();
1074
1075 DateTimeComponents expectedComponent = DateTimeComponents.parseDateTime(testString);
1076 AbsoluteDate expectedDate = new AbsoluteDate(expectedComponent, timeScale);
1077
1078 ZonedDateTime actualComponent = LocalDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(testString)).atZone(ZoneOffset.UTC);
1079 AbsoluteDate actualDate = new AbsoluteDate(Timestamp.from(actualComponent.toInstant()), timeScale);
1080 Assertions.assertEquals(0.0, expectedDate.durationFrom(actualDate), 1.0e-15);
1081
1082 }
1083
1084 @Test
1085 void testGetComponentsIssue681and676and694() {
1086
1087 AbsoluteDate date = new AbsoluteDate(2009, 1, 1, utc);
1088 double attoSecond = 1.0e-18;
1089 double zeroUlp = FastMath.nextUp(0.0);
1090 double oneUlp = FastMath.ulp(1.0);
1091 double sixtyUlp = FastMath.ulp(60.0);
1092 double one = FastMath.nextDown(1.0);
1093 double sixty = FastMath.nextDown(60.0);
1094 double sixtyOne = FastMath.nextDown(61.0);
1095
1096
1097
1098
1099 check(date, 2009, 1, 1, 0, 0, 0, 1, 0, 0);
1100 check(date.shiftedBy(attoSecond), 2009, 1, 1, 0, 0, attoSecond, 0.5, 0, 0);
1101 check(date.shiftedBy(one), 2009, 1, 1, 0, 0, one, 0.5, 0, 0);
1102
1103 check(date.shiftedBy(59).shiftedBy(one), 2009, 1, 1, 0, 0, sixty, 1, 1, 0);
1104 check(date.shiftedBy(86399).shiftedBy(one), 2009, 1, 1, 23, 59, sixty, 1, 1, 0);
1105 check(date.shiftedBy(-zeroUlp), 2009, 1, 1, 0, 0, 0, 0.5, 0, 0);
1106 check(date.shiftedBy(-oneUlp), 2008, 12, 31, 23, 59, sixtyOne, 1, 1, 0);
1107 check(date.shiftedBy(-1).shiftedBy(zeroUlp), 2008, 12, 31, 23, 59, 60.0, 0.5, 0, 0);
1108 check(date.shiftedBy(-1).shiftedBy(-zeroUlp), 2008, 12, 31, 23, 59, 60.0, 0.5, 0, 0);
1109 check(date.shiftedBy(-1).shiftedBy(-oneUlp), 2008, 12, 31, 23, 59, 60.0, 0.5, 0, 0);
1110 check(date.shiftedBy(-1).shiftedBy(-sixtyUlp), 2008, 12, 31, 23, 59, sixty, 0.5, 0, 0);
1111 check(date.shiftedBy(-61).shiftedBy(attoSecond), 2008, 12, 31, 23, 59, attoSecond, 0.5, 0, 0);
1112
1113
1114
1115
1116 AbsoluteDate d = new AbsoluteDate(1966, 1, 1, utc);
1117 double ratePost = 0.0025920 / Constants.JULIAN_DAY;
1118 double factorPost = ratePost / (1 + ratePost);
1119 double ratePre = 0.0012960 / Constants.JULIAN_DAY;
1120 double factorPre = ratePre / (1 + ratePre);
1121 check(d, 1966, 1, 1, 0, 0, 0, 1, 0, 0);
1122 check(d.shiftedBy(zeroUlp), 1966, 1, 1, 0, 0, 0, 0.5, 0, 0);
1123 check(d.shiftedBy(attoSecond), 1966, 1, 1, 0, 0, attoSecond, 0.5, 0, 0);
1124 check(d.shiftedBy(one), 1966, 1, 1, 0, 0, one * (1 - factorPost), 1, 3, 0);
1125 check(d.shiftedBy(59).shiftedBy(one), 1966, 1, 1, 0, 0, sixty * (1 - factorPost), 1, 2, 0);
1126 check(d.shiftedBy(86399).shiftedBy(one), 1966, 1, 1, 23, 59, sixty - 86400 * factorPost, 1, 1, 0);
1127 check(d.shiftedBy(-zeroUlp), 1966, 1, 1, 0, 0, 0, 0.5, 0, 0);
1128
1129 check(d.shiftedBy(-oneUlp), 1965, 12, 31, 23, 59, 60.0, 1, 0, 0);
1130 check(d.shiftedBy(-1).shiftedBy(zeroUlp), 1965, 12, 31, 23, 59, 59 + factorPre, 0.5, 0, 0);
1131 check(d.shiftedBy(-1).shiftedBy(-zeroUlp), 1965, 12, 31, 23, 59, 59 + factorPre, 0.5, 0, 0);
1132 check(d.shiftedBy(-1).shiftedBy(-oneUlp), 1965, 12, 31, 23, 59, 59 + factorPre, 0.5, 0, 0);
1133 check(d.shiftedBy(-1).shiftedBy(-sixtyUlp), 1965, 12, 31, 23, 59, 59 + (1 + sixtyUlp) * factorPre, 0.5, 1, 0);
1134
1135 check(d.shiftedBy(-60).shiftedBy(zeroUlp), 1965, 12, 31, 23, 59, 60 * factorPre, 0, 0, sixtyUlp);
1136 check(d.shiftedBy(-60).shiftedBy(oneUlp), 1965, 12, 31, 23, 59, (oneUlp - oneUlp * factorPre) + 60 * factorPre, 0.5, 0, sixtyUlp);
1137
1138
1139 AbsoluteDate d2 = new AbsoluteDate(1972, 7, 1, utc);
1140 check(d2, 1972, 7, 1, 0, 0, 0, 1, 0, 0);
1141 check(d2.shiftedBy(attoSecond), 1972, 7, 1, 0, 0, attoSecond, 0.5, 0, 0);
1142 check(d2.shiftedBy(one), 1972, 7, 1, 0, 0, one, 0.5, 0, 0);
1143 check(d2.shiftedBy(59).shiftedBy(one), 1972, 7, 1, 0, 0, sixty, 1, 1, 0);
1144 check(d2.shiftedBy(86399).shiftedBy(one), 1972, 7, 1, 23, 59, sixty, 1, 1, 0);
1145 check(d2.shiftedBy(-zeroUlp), 1972, 7, 1, 0, 0, 0, 0.5, 0, 0);
1146 check(d2.shiftedBy(-oneUlp), 1972, 6, 30, 23, 59, sixtyOne, 1, 1, 0);
1147 check(d2.shiftedBy(-1).shiftedBy(zeroUlp), 1972, 6, 30, 23, 59, 60.0, 0.5, 0, 0);
1148 check(d2.shiftedBy(-1).shiftedBy(-zeroUlp), 1972, 6, 30, 23, 59, 60.0, 0.5, 0, 0);
1149 check(d2.shiftedBy(-1).shiftedBy(-oneUlp), 1972, 6, 30, 23, 59, 60.0, 0.5, 0, 0);
1150 check(d2.shiftedBy(-1).shiftedBy(-sixtyUlp), 1972, 6, 30, 23, 59, sixty, 0.5, 0, 0);
1151 check(d2.shiftedBy(-61).shiftedBy(attoSecond), 1972, 6, 30, 23, 59, attoSecond, 0.5, 0, 0);
1152
1153
1154 AbsoluteDate d3 = AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(-1230724800);
1155 check(d3, 1960, 12, 31, 23, 59, 60, 0.5, 0, 0);
1156 AbsoluteDate d4 = new AbsoluteDate(1961, 1, 1, utc);
1157 check(d4, 1961, 1, 1, 0, 0, 0, 0.5, 0, 0);
1158
1159
1160
1161
1162 DateTimeComponents actual = date.shiftedBy(Double.NaN).getComponents(utc);
1163 DateComponents dc = actual.getDate();
1164 TimeComponents tc = actual.getTime();
1165 MatcherAssert.assertThat(dc.getYear(), CoreMatchers.is(2000));
1166 MatcherAssert.assertThat(dc.getMonth(), CoreMatchers.is(1));
1167 MatcherAssert.assertThat(dc.getDay(), CoreMatchers.is(1));
1168 MatcherAssert.assertThat(tc.getHour(), CoreMatchers.is(0));
1169 MatcherAssert.assertThat(tc.getMinute(), CoreMatchers.is(0));
1170 MatcherAssert.assertThat("second", tc.getSecond(), CoreMatchers.is(Double.NaN));
1171 MatcherAssert.assertThat(tc.getMinutesFromUTC(), CoreMatchers.is(0));
1172 final double difference = new AbsoluteDate(actual, utc).durationFrom(date);
1173 MatcherAssert.assertThat(difference, CoreMatchers.is(Double.NaN));
1174 }
1175
1176 private void check(AbsoluteDate date,
1177 int year, int month, int day, int hour, int minute, double second,
1178 double roundTripUlps, final int secondUlps, final double absTol) {
1179 DateTimeComponents actual = date.getComponents(utc);
1180 DateComponents d = actual.getDate();
1181 TimeComponents t = actual.getTime();
1182 MatcherAssert.assertThat(d.getYear(), CoreMatchers.is(year));
1183 MatcherAssert.assertThat(d.getMonth(), CoreMatchers.is(month));
1184 MatcherAssert.assertThat(d.getDay(), CoreMatchers.is(day));
1185 MatcherAssert.assertThat(t.getHour(), CoreMatchers.is(hour));
1186 MatcherAssert.assertThat(t.getMinute(), CoreMatchers.is(minute));
1187 MatcherAssert.assertThat("second", t.getSecond(),
1188 OrekitMatchers.numberCloseTo(second, absTol, secondUlps));
1189 MatcherAssert.assertThat(t.getMinutesFromUTC(), CoreMatchers.is(0));
1190 final double tol = FastMath.ulp(second) * roundTripUlps;
1191 final double difference = new AbsoluteDate(actual, utc).durationFrom(date);
1192 MatcherAssert.assertThat(difference,
1193 OrekitMatchers.closeTo(0, FastMath.max(absTol, tol)));
1194 }
1195
1196
1197 @Test
1198 void testToStringRfc3339() {
1199
1200 AbsoluteDate date = new AbsoluteDate(2009, 1, 1, utc);
1201 double one = FastMath.nextDown(1.0);
1202 double zeroUlp = FastMath.nextUp(0.0);
1203 double oneUlp = FastMath.ulp(1.0);
1204
1205 double sixtyUlp = FastMath.ulp(60.0);
1206
1207
1208
1209 check(date, "2009-01-01T00:00:00Z");
1210 check(date.shiftedBy(1), "2009-01-01T00:00:01Z");
1211
1212 check(date.shiftedBy(new TimeOffset(12L, 345678912345678900L)), "2009-01-01T00:00:12.3456789123456789Z");
1213 check(date.shiftedBy(new TimeOffset(0L, 12345678912345678L)), "2009-01-01T00:00:00.012345678912345678Z");
1214
1215 check(date.shiftedBy(zeroUlp), "2009-01-01T00:00:00Z");
1216 check(date.shiftedBy(59.0).shiftedBy(one), "2009-01-01T00:00:59.999999999999999889Z");
1217 check(date.shiftedBy(86399).shiftedBy(one), "2009-01-01T23:59:59.999999999999999889Z");
1218 check(date.shiftedBy(oneUlp), "2009-01-01T00:00:00.000000000000000222Z");
1219 check(date.shiftedBy(one), "2009-01-01T00:00:00.999999999999999889Z");
1220 check(date.shiftedBy(-zeroUlp), "2009-01-01T00:00:00Z");
1221
1222 check(date.shiftedBy(-oneUlp), "2008-12-31T23:59:60.999999999999999778Z");
1223 check(date.shiftedBy(-1).shiftedBy(one), "2008-12-31T23:59:60.999999999999999889Z");
1224 check(date.shiftedBy(-0.5), "2008-12-31T23:59:60.5Z");
1225 check(date.shiftedBy(-1).shiftedBy(zeroUlp), "2008-12-31T23:59:60Z");
1226 check(date.shiftedBy(-1), "2008-12-31T23:59:60Z");
1227 check(date.shiftedBy(-1).shiftedBy(-zeroUlp), "2008-12-31T23:59:60Z");
1228 check(date.shiftedBy(-1).shiftedBy(-oneUlp), "2008-12-31T23:59:59.999999999999999778Z");
1229 check(date.shiftedBy(-2), "2008-12-31T23:59:59Z");
1230 check(date.shiftedBy(-1).shiftedBy(-sixtyUlp), "2008-12-31T23:59:59.999999999999992895Z");
1231 check(date.shiftedBy(-61).shiftedBy(zeroUlp), "2008-12-31T23:59:00Z");
1232 check(date.shiftedBy(-61).shiftedBy(oneUlp), "2008-12-31T23:59:00.000000000000000222Z");
1233
1234 AbsoluteDate d = new AbsoluteDate(1966, 1, 1, utc);
1235 check(d, "1966-01-01T00:00:00Z");
1236 check(d.shiftedBy(zeroUlp), "1966-01-01T00:00:00Z");
1237 check(d.shiftedBy(oneUlp), "1966-01-01T00:00:00.000000000000000222Z");
1238
1239
1240
1241 check(d.shiftedBy(one), "1966-01-01T00:00:00.999999970000000789Z");
1242
1243
1244
1245 check(d.shiftedBy(59).shiftedBy(one), "1966-01-01T00:00:59.999998200000053889Z");
1246
1247
1248
1249 check(d.shiftedBy(86399).shiftedBy(one), "1966-01-01T23:59:59.997408000077759887Z");
1250 check(d.shiftedBy(-zeroUlp), "1966-01-01T00:00:00Z");
1251
1252 check(d.shiftedBy(-oneUlp), "1965-12-31T23:59:59.999999999999999779Z");
1253
1254
1255
1256 check(d.shiftedBy(-1).shiftedBy(zeroUlp), "1965-12-31T23:59:59.000000014999999776Z");
1257 check(d.shiftedBy(-1).shiftedBy(-zeroUlp), "1965-12-31T23:59:59.000000014999999776Z");
1258
1259
1260 check(d.shiftedBy(-1).shiftedBy(-oneUlp), "1965-12-31T23:59:59.000000014999999554Z");
1261
1262
1263 check(d.shiftedBy(-1).shiftedBy(-sixtyUlp), "1965-12-31T23:59:59.000000014999992671Z");
1264
1265
1266 check(d.shiftedBy(-60).shiftedBy(zeroUlp), "1965-12-31T23:59:00.000000899999986501Z");
1267 check(d.shiftedBy(-60).shiftedBy(oneUlp), "1965-12-31T23:59:00.000000899999986723Z");
1268
1269
1270 check(new AbsoluteDate(1961, 1, 1, utc), "1961-01-01T00:00:00Z");
1271 AbsoluteDate d3 = AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(-1230724800);
1272 check(d3, "1960-12-31T23:59:60Z");
1273
1274
1275
1276
1277 check(new AbsoluteDate(123, 4, 5, 6, 7, new TimeOffset(8, TimeOffset.SECOND, 900, TimeOffset.MILLISECOND), utc),
1278 "0123-04-05T06:07:08.9Z");
1279
1280
1281
1282
1283 check(new AbsoluteDate(-123, 4, 5, 6, 7, new TimeOffset(8, TimeOffset.SECOND, 900, TimeOffset.MILLISECOND), utc),
1284 "-123-04-05T06:07:08.9Z");
1285 check(new AbsoluteDate(-1230, 4, 5, 6, 7, new TimeOffset(8, TimeOffset.SECOND, 900, TimeOffset.MILLISECOND), utc),
1286 "-1230-04-05T06:07:08.9Z");
1287
1288 check(new AbsoluteDate(12300, 4, 5, 6, 7, new TimeOffset(8, TimeOffset.SECOND, 900, TimeOffset.MILLISECOND), utc),
1289 "12300-04-05T06:07:08.9Z");
1290
1291 check(AbsoluteDate.FUTURE_INFINITY, "5881610-07-11T23:59:59.999Z");
1292 check(AbsoluteDate.PAST_INFINITY, "-5877490-03-03T00:00:00Z");
1293
1294 check(date.shiftedBy(Double.NaN), "2000-01-01T00:00:NaNZ");
1295 }
1296
1297 private void check(final AbsoluteDate d, final String s) {
1298 MatcherAssert.assertThat(d.toStringRfc3339(utc),
1299 CoreMatchers.is(s));
1300 MatcherAssert.assertThat(d.getComponents(utc).toStringRfc3339(),
1301 CoreMatchers.is(s));
1302 }
1303
1304
1305
1306 @Test
1307 void testToString() {
1308
1309 AbsoluteDate date = new AbsoluteDate(2009, 1, 1, utc);
1310 double one = FastMath.nextDown(1.0);
1311 double zeroUlp = FastMath.nextUp(0.0);
1312 double oneUlp = FastMath.ulp(1.0);
1313
1314 double sixtyUlp = FastMath.ulp(60.0);
1315
1316
1317
1318 checkToString(date, "2009-01-01T00:00:00.000");
1319 checkToString(date.shiftedBy(1), "2009-01-01T00:00:01.000");
1320
1321 checkToString(date.shiftedBy(new TimeOffset(12L, 345678912345678900L)), "2009-01-01T00:00:12.3456789123456789");
1322 checkToString(date.shiftedBy(new TimeOffset(0L, 12345678912345678L)), "2009-01-01T00:00:00.012345678912345678");
1323
1324 checkToString(date.shiftedBy(zeroUlp), "2009-01-01T00:00:00.000");
1325
1326 checkToString(date.shiftedBy(59.0).shiftedBy(one), "2009-01-01T00:00:59.999999999999999889");
1327
1328 checkToString(date.shiftedBy(86399).shiftedBy(one), "2009-01-01T23:59:59.999999999999999889");
1329
1330 checkToString(date.shiftedBy(oneUlp), "2009-01-01T00:00:00.000000000000000222");
1331
1332 checkToString(date.shiftedBy(one), "2009-01-01T00:00:00.999999999999999889");
1333 checkToString(date.shiftedBy(-zeroUlp), "2009-01-01T00:00:00.000");
1334
1335
1336 checkToString(date.shiftedBy(-oneUlp), "2008-12-31T23:59:60.999999999999999778");
1337
1338 checkToString(date.shiftedBy(-1).shiftedBy(one), "2008-12-31T23:59:60.999999999999999889");
1339 checkToString(date.shiftedBy(-0.5), "2008-12-31T23:59:60.500");
1340 checkToString(date.shiftedBy(-1).shiftedBy(zeroUlp), "2008-12-31T23:59:60.000");
1341 checkToString(date.shiftedBy(-1), "2008-12-31T23:59:60.000");
1342 checkToString(date.shiftedBy(-1).shiftedBy(-zeroUlp), "2008-12-31T23:59:60.000");
1343
1344 checkToString(date.shiftedBy(-1).shiftedBy(-oneUlp), "2008-12-31T23:59:59.999999999999999778");
1345 checkToString(date.shiftedBy(-2), "2008-12-31T23:59:59.000");
1346
1347 checkToString(date.shiftedBy(-1).shiftedBy(-sixtyUlp), "2008-12-31T23:59:59.999999999999992895");
1348 checkToString(date.shiftedBy(-61).shiftedBy(zeroUlp), "2008-12-31T23:59:00.000");
1349
1350 checkToString(date.shiftedBy(-61).shiftedBy(oneUlp), "2008-12-31T23:59:00.000000000000000222");
1351
1352 AbsoluteDate d = new AbsoluteDate(1966, 1, 1, utc);
1353 checkToString(d, "1966-01-01T00:00:00.000");
1354 checkToString(d.shiftedBy(zeroUlp), "1966-01-01T00:00:00.000");
1355 checkToString(d.shiftedBy(oneUlp), "1966-01-01T00:00:00.000000000000000222");
1356
1357
1358
1359 checkToString(d.shiftedBy(one), "1966-01-01T00:00:00.999999970000000789");
1360
1361
1362
1363 checkToString(d.shiftedBy(59).shiftedBy(one), "1966-01-01T00:00:59.999998200000053889");
1364
1365
1366
1367 checkToString(d.shiftedBy(86399).shiftedBy(one), "1966-01-01T23:59:59.997408000077759887");
1368 checkToString(d.shiftedBy(-zeroUlp), "1966-01-01T00:00:00.000");
1369
1370 checkToString(d.shiftedBy(-oneUlp), "1965-12-31T23:59:59.999999999999999779");
1371
1372
1373
1374 checkToString(d.shiftedBy(-1).shiftedBy(zeroUlp), "1965-12-31T23:59:59.000000014999999776");
1375 checkToString(d.shiftedBy(-1).shiftedBy(-zeroUlp), "1965-12-31T23:59:59.000000014999999776");
1376
1377
1378 checkToString(d.shiftedBy(-1).shiftedBy(-oneUlp), "1965-12-31T23:59:59.000000014999999554");
1379
1380
1381 checkToString(d.shiftedBy(-1).shiftedBy(-sixtyUlp), "1965-12-31T23:59:59.000000014999992671");
1382
1383 checkToString(d.shiftedBy(-60).shiftedBy(zeroUlp), "1965-12-31T23:59:00.000000899999986501");
1384 checkToString(d.shiftedBy(-60).shiftedBy(oneUlp), "1965-12-31T23:59:00.000000899999986723");
1385
1386
1387 checkToString(new AbsoluteDate(1961, 1, 1, utc), "1961-01-01T00:00:00.000");
1388 AbsoluteDate d3 = AbsoluteDate.ARBITRARY_EPOCH.shiftedBy(-1230724800);
1389 checkToString(d3, "1960-12-31T23:59:60.000");
1390
1391
1392
1393
1394 checkToString(new AbsoluteDate(123, 4, 5, 6, 7, new TimeOffset(8, TimeOffset.SECOND, 900, TimeOffset.MILLISECOND), utc),
1395 "0123-04-05T06:07:08.900");
1396
1397
1398
1399
1400 checkToString(new AbsoluteDate(-123, 4, 5, 6, 7, new TimeOffset(8, TimeOffset.SECOND, 900, TimeOffset.MILLISECOND), utc),
1401 "-123-04-05T06:07:08.900");
1402 checkToString(new AbsoluteDate(-1230, 4, 5, 6, 7, new TimeOffset(8, TimeOffset.SECOND, 900, TimeOffset.MILLISECOND), utc),
1403 "-1230-04-05T06:07:08.900");
1404
1405 checkToString(new AbsoluteDate(12300, 4, 5, 6, 7, new TimeOffset(8, TimeOffset.SECOND, 900, TimeOffset.MILLISECOND), utc),
1406 "12300-04-05T06:07:08.900");
1407
1408 checkToString(AbsoluteDate.FUTURE_INFINITY, "5881610-07-11T23:59:59.999");
1409 checkToString(AbsoluteDate.PAST_INFINITY, "-5877490-03-03T00:00:00.000");
1410
1411 checkToString(date.shiftedBy(Double.NaN), "2000-01-01T00:00:NaN");
1412 }
1413
1414 private void checkToString(final AbsoluteDate d, final String s) {
1415 MatcherAssert.assertThat(d.toString(), CoreMatchers.is(s + "Z"));
1416 MatcherAssert.assertThat(d.getComponents(utc).toString(), CoreMatchers.is(s + "+00:00"));
1417 }
1418
1419 @Test
1420 void testToStringWithoutUtcOffset() {
1421
1422 AbsoluteDate date = new AbsoluteDate(2009, 1, 1, utc);
1423 double one = FastMath.nextDown(1.0);
1424 double zeroUlp = FastMath.nextUp(0.0);
1425 double oneUlp = FastMath.ulp(1.0);
1426
1427 double sixtyUlp = FastMath.ulp(60.0);
1428
1429
1430
1431 checkToStringNoOffset(date, "2009-01-01T00:00:00.000");
1432 checkToStringNoOffset(date.shiftedBy(1), "2009-01-01T00:00:01.000");
1433
1434 checkToStringNoOffset(date.shiftedBy(12.3456789123456789), "2009-01-01T00:00:12.346");
1435 checkToStringNoOffset(date.shiftedBy(0.0123456789123456789), "2009-01-01T00:00:00.012");
1436
1437 checkToStringNoOffset(date.shiftedBy(zeroUlp), "2009-01-01T00:00:00.000");
1438
1439 checkToStringNoOffset(date.shiftedBy(59.0).shiftedBy(one), "2009-01-01T00:01:00.000");
1440
1441 checkToStringNoOffset(date.shiftedBy(86399).shiftedBy(one), "2009-01-02T00:00:00.000");
1442 checkToStringNoOffset(date.shiftedBy(oneUlp), "2009-01-01T00:00:00.000");
1443 checkToStringNoOffset(date.shiftedBy(one), "2009-01-01T00:00:01.000");
1444 checkToStringNoOffset(date.shiftedBy(-zeroUlp), "2009-01-01T00:00:00.000");
1445
1446
1447 checkToStringNoOffset(date.shiftedBy(-oneUlp), "2009-01-01T00:00:00.000");
1448
1449 checkToStringNoOffset(date.shiftedBy(-1).shiftedBy(one), "2009-01-01T00:00:00.000");
1450 checkToStringNoOffset(date.shiftedBy(-0.5), "2008-12-31T23:59:60.500");
1451 checkToStringNoOffset(date.shiftedBy(-1).shiftedBy(zeroUlp), "2008-12-31T23:59:60.000");
1452 checkToStringNoOffset(date.shiftedBy(-1), "2008-12-31T23:59:60.000");
1453 checkToStringNoOffset(date.shiftedBy(-1).shiftedBy(-zeroUlp), "2008-12-31T23:59:60.000");
1454 checkToStringNoOffset(date.shiftedBy(-1).shiftedBy(-oneUlp), "2008-12-31T23:59:60.000");
1455 checkToStringNoOffset(date.shiftedBy(-2), "2008-12-31T23:59:59.000");
1456
1457 checkToStringNoOffset(date.shiftedBy(-1).shiftedBy(-sixtyUlp), "2008-12-31T23:59:60.000");
1458 checkToStringNoOffset(date.shiftedBy(-61).shiftedBy(zeroUlp), "2008-12-31T23:59:00.000");
1459 checkToStringNoOffset(date.shiftedBy(-61).shiftedBy(oneUlp), "2008-12-31T23:59:00.000");
1460 }
1461
1462
1463 private void checkToStringNoOffset(final AbsoluteDate d, final String s) {
1464 MatcherAssert.assertThat(d.toStringWithoutUtcOffset(utc, 3), CoreMatchers.is(s));
1465 MatcherAssert.assertThat(
1466 d.getComponents(utc).toStringWithoutUtcOffset(utc.minuteDuration(d), 3),
1467 CoreMatchers.is(s));
1468 }
1469
1470
1471
1472
1473
1474 @Test
1475 void testToStringException() {
1476 Utils.setDataRoot("no-data");
1477 try {
1478 DataContext.getDefault().getTimeScales().getUTC();
1479 Assertions.fail("Expected Exception");
1480 } catch (OrekitException e) {
1481
1482 Assertions.assertEquals(e.getSpecifier(), OrekitMessages.NO_IERS_UTC_TAI_HISTORY_DATA_LOADED);
1483 }
1484
1485 MatcherAssert.assertThat(present.toString(), CoreMatchers.is("2000-01-01T12:00:32.000 TAI"));
1486 MatcherAssert.assertThat(present.shiftedBy(Double.POSITIVE_INFINITY).toString(),
1487 CoreMatchers.is("5881610-07-11T23:59:59.999 TAI"));
1488 MatcherAssert.assertThat(present.shiftedBy(Double.NEGATIVE_INFINITY).toString(),
1489 CoreMatchers.is("-5877490-03-03T00:00:00.000 TAI"));
1490 MatcherAssert.assertThat(present.shiftedBy(Double.NaN).toString(),
1491 CoreMatchers.is("2000-01-01T00:00:NaN TAI"));
1492
1493
1494 Assertions.assertTrue(Double.isInfinite(present.shiftedBy(1e300).durationFrom(present)));
1495 }
1496
1497
1498 @Test
1499 void test_issue_943() {
1500
1501
1502 final AbsoluteDate date1 = new AbsoluteDate(AbsoluteDate.PAST_INFINITY, 0);
1503 final AbsoluteDate date2 = new AbsoluteDate(AbsoluteDate.PAST_INFINITY, 0);
1504 date1.durationFrom(date2);
1505 Assertions.assertEquals(date1, date2);
1506
1507
1508 final AbsoluteDate date3 = AbsoluteDate.PAST_INFINITY;
1509 final AbsoluteDate date4 = new AbsoluteDate(AbsoluteDate.PAST_INFINITY, 0);
1510 Assertions.assertEquals(date3, date4);
1511
1512
1513 final AbsoluteDate date5 = AbsoluteDate.FUTURE_INFINITY;
1514 final AbsoluteDate date6 = new AbsoluteDate(AbsoluteDate.FUTURE_INFINITY, 0);
1515 Assertions.assertEquals(date5, date6);
1516
1517
1518 final AbsoluteDate date7 = new AbsoluteDate(AbsoluteDate.PAST_INFINITY, 0);
1519 final AbsoluteDate date8 = new AbsoluteDate(AbsoluteDate.FUTURE_INFINITY, 0);
1520 Assertions.assertNotEquals(date7, date8);
1521
1522
1523 final AbsoluteDate date9 = new AbsoluteDate(new TimeOffset(Double.POSITIVE_INFINITY));
1524 final AbsoluteDate date10 = new AbsoluteDate(new TimeOffset(Double.POSITIVE_INFINITY));
1525 Assertions.assertEquals(date9, date10);
1526 }
1527
1528 @Test
1529 void testNegativeOffsetConstructor() {
1530 AbsoluteDate date = new AbsoluteDate(2019, 10, 11, 20, 40,
1531 FastMath.scalb(6629298651489277.0, -55),
1532 TimeScalesFactory.getTT());
1533 AbsoluteDate after = date.shiftedBy(Precision.EPSILON);
1534 Assertions.assertEquals(624098367L, date.getSeconds());
1535 Assertions.assertEquals(FastMath.nextAfter(1.0, Double.NEGATIVE_INFINITY), 1.0e-18 * date.getAttoSeconds(), 2.4e-15);
1536 Assertions.assertEquals(Precision.EPSILON, after.durationFrom(date), 1.0e-18);
1537 }
1538
1539 @Test
1540 void testNegativeOffsetShift() {
1541 AbsoluteDate reference = new AbsoluteDate(2019, 10, 11, 20, 40,
1542 1.6667019180022178E-7,
1543 TimeScalesFactory.getTAI());
1544 double dt = FastMath.scalb(6596520010750484.0, -39);
1545 AbsoluteDate shifted = reference.shiftedBy(dt);
1546 AbsoluteDate after = shifted.shiftedBy(Precision.EPSILON);
1547 Assertions.assertEquals(624110398L, shifted.getSeconds());
1548 Assertions.assertEquals((1.0 - 1.6922e-13) * 1.0e18, shifted.getAttoSeconds(), 1.0e-15);
1549 Assertions.assertEquals(Precision.EPSILON, after.durationFrom(shifted), 1.0e-18);
1550 }
1551
1552 @Test
1553 void testDurationFromWithTimeUnit() {
1554 AbsoluteDate reference = new AbsoluteDate(2023, 1, 1, 12, 13, 59.12334567, utc);
1555 for (TimeUnit timeUnit : TimeUnit.values()) {
1556 Assertions.assertEquals(0, reference.durationFrom(reference, timeUnit));
1557
1558 long dayInTimeUnit = timeUnit.convert((long) Constants.JULIAN_DAY, TimeUnit.SECONDS);
1559 for (int i = 1; i <= 365; i++) {
1560 AbsoluteDate minusDays = reference.shiftedBy(-i * Constants.JULIAN_DAY);
1561 AbsoluteDate plusDays = reference.shiftedBy(i* Constants.JULIAN_DAY);
1562
1563
1564 Assertions.assertEquals(i * dayInTimeUnit, reference.durationFrom(minusDays, timeUnit));
1565
1566 Assertions.assertEquals(-i * dayInTimeUnit, reference.durationFrom(plusDays, timeUnit));
1567 }
1568
1569 for (long ns = 1; ns <= 1_000_000_000; ns += 1_000_000) {
1570 AbsoluteDate minus = reference.shiftedBy(-1e-9 * ns);
1571 AbsoluteDate plus = reference.shiftedBy(1e-9 * ns);
1572
1573 double deltaInTimeUnit = ns / (double) timeUnit.toNanos(1);
1574 Assertions.assertEquals(FastMath.round(deltaInTimeUnit), reference.durationFrom(minus, timeUnit),
1575 String.format("TimeUnit: %s, ns: %d", timeUnit, ns));
1576
1577 Assertions.assertEquals(FastMath.round(-deltaInTimeUnit), reference.durationFrom(plus, timeUnit),
1578 String.format("TimeUnit: %s, ns: %d", timeUnit, ns));
1579 }
1580
1581
1582 }
1583 }
1584
1585 @Test
1586 void testConstructWithTimeUnitOffset() {
1587 AbsoluteDate reference = new AbsoluteDate(2023, 1, 1, 12, 13, 59.12334567, utc);
1588
1589 for (TimeUnit timeUnit : TimeUnit.values()) {
1590 Assertions.assertEquals(0,
1591 FastMath.abs(reference.durationFrom(new AbsoluteDate(reference, 0, timeUnit))), 1e-10);
1592
1593 long dayInTimeUnit = timeUnit.convert((long) Constants.JULIAN_DAY, TimeUnit.SECONDS);
1594 for (int i = 1; i <= 365; i++) {
1595 AbsoluteDate minusDays = reference.shiftedBy(-i * Constants.JULIAN_DAY);
1596 AbsoluteDate plusDays = reference.shiftedBy(i* Constants.JULIAN_DAY);
1597
1598 Assertions.assertEquals(0,
1599 FastMath.abs(reference.durationFrom(new AbsoluteDate(minusDays, i * dayInTimeUnit, timeUnit))),
1600 1e-10,
1601 String.format("TimeUnit: %s", timeUnit));
1602 Assertions.assertEquals(0,
1603 FastMath.abs(reference.durationFrom(new AbsoluteDate(plusDays, -i * dayInTimeUnit, timeUnit))),
1604 1e-10,
1605 String.format("TimeUnit: %s", timeUnit));
1606 }
1607
1608 for (long ns = 1; ns <= 1_000_000_000; ns += 1_000_000) {
1609 if (timeUnit.convert(1, TimeUnit.SECONDS) < 1) {
1610
1611 continue;
1612 }
1613 AbsoluteDate minus = reference.shiftedBy(-1e-9 * ns);
1614 AbsoluteDate plus = reference.shiftedBy(1e-9 * ns);
1615
1616 double deltaInTimeUnit = ns / (double) timeUnit.toNanos(1);
1617 Assertions.assertEquals(0,
1618 FastMath.abs(reference.durationFrom(new AbsoluteDate(minus, FastMath.round(deltaInTimeUnit), timeUnit))),
1619 1.0 / timeUnit.convert(1, TimeUnit.SECONDS),
1620 String.format("TimeUnit: %s, ns: %d", timeUnit, ns));
1621 Assertions.assertEquals(0,
1622 FastMath.abs(reference.durationFrom(new AbsoluteDate(plus, FastMath.round(-deltaInTimeUnit), timeUnit))),
1623 1.0 / timeUnit.convert(1, TimeUnit.SECONDS),
1624 String.format("TimeUnit: %s, ns: %d", timeUnit, ns));
1625 }
1626 }
1627 }
1628
1629 @Test
1630 void testShiftedByWithTimeUnit() {
1631 AbsoluteDate reference = new AbsoluteDate(2023, 1, 1, 12, 13, 59.12334567, utc);
1632
1633 for (TimeUnit timeUnit : TimeUnit.values()) {
1634 Assertions.assertEquals(0,
1635 FastMath.abs(reference.durationFrom(reference.shiftedBy( 0, timeUnit))), 1e-10);
1636
1637 long dayInTimeUnit = timeUnit.convert((long) Constants.JULIAN_DAY, TimeUnit.SECONDS);
1638 for (int i = 1; i <= 365; i++) {
1639 AbsoluteDate minusDays = reference.shiftedBy(-i * Constants.JULIAN_DAY);
1640 AbsoluteDate plusDays = reference.shiftedBy(i* Constants.JULIAN_DAY);
1641
1642 Assertions.assertEquals(0,
1643 FastMath.abs(reference.durationFrom(minusDays.shiftedBy(i * dayInTimeUnit, timeUnit))),
1644 1e-10,
1645 String.format("TimeUnit: %s", timeUnit));
1646 Assertions.assertEquals(0,
1647 FastMath.abs(reference.durationFrom(plusDays.shiftedBy(-i * dayInTimeUnit, timeUnit))),
1648 1e-10,
1649 String.format("TimeUnit: %s", timeUnit));
1650 }
1651
1652 for (long ns = 1; ns <= 1_000_000_000; ns += 1_000_000) {
1653 if (timeUnit.convert(1, TimeUnit.SECONDS) < 1) {
1654
1655 continue;
1656 }
1657 AbsoluteDate minus = reference.shiftedBy(-1e-9 * ns);
1658 AbsoluteDate plus = reference.shiftedBy(1e-9 * ns);
1659
1660 double deltaInTimeUnit = ns / (double) timeUnit.toNanos(1);
1661 Assertions.assertEquals(0,
1662 FastMath.abs(reference.durationFrom(minus.shiftedBy(FastMath.round(deltaInTimeUnit), timeUnit))),
1663 1.0 / timeUnit.convert(1, TimeUnit.SECONDS),
1664 String.format("TimeUnit: %s, ns: %d", timeUnit, ns));
1665 Assertions.assertEquals(0,
1666 FastMath.abs(reference.durationFrom(plus.shiftedBy(FastMath.round(-deltaInTimeUnit), timeUnit))),
1667 1.0 / timeUnit.convert(1, TimeUnit.SECONDS),
1668 String.format("TimeUnit: %s, ns: %d", timeUnit, ns));
1669 }
1670 }
1671 }
1672
1673 @Test
1674 void testGetJulianDates() {
1675
1676
1677 final TimeScale utc = TimeScalesFactory.getUTC();
1678
1679 AbsoluteDate reference = new AbsoluteDate(2024, 7, 4, 13, 0, 0, utc);
1680 AbsoluteDate referenceFromJDMethod = AbsoluteDate.createJDDate(2460496, .0416667 * Constants.JULIAN_DAY, utc);
1681 AbsoluteDate referenceFromMJDMethod = AbsoluteDate.createMJDDate(60495, 0.54166670 * Constants.JULIAN_DAY, utc);
1682
1683
1684 double mjdDateDefaultData = reference.getMJD();
1685 double jdDateDefaultData = reference.getJD();
1686 double mjdDate = reference.getMJD(utc);
1687 double jdDate = reference.getJD(utc);
1688
1689
1690
1691 Assertions.assertEquals(2460496.0416667, jdDateDefaultData, 1.0e-6);
1692 Assertions.assertEquals(60495.54166670, mjdDateDefaultData, 1.0e-6);
1693 Assertions.assertEquals(jdDate, jdDateDefaultData, 1.0e-6);
1694 Assertions.assertEquals(mjdDateDefaultData, mjdDate);
1695
1696
1697 Assertions.assertTrue(reference.isCloseTo(referenceFromJDMethod, 1e-2));
1698 Assertions.assertTrue(reference.isCloseTo(referenceFromMJDMethod, 1e-2));
1699 }
1700
1701 @Test
1702 void testLargeLeapSecond() {
1703
1704 Assertions.assertEquals(new AbsoluteDate(1961, 1, 1, utc).
1705 shiftedBy(new TimeOffset(22818, TimeOffset.MICROSECOND).negate()),
1706 new AbsoluteDate("1960-12-31T23:59:61.4", utc));
1707 }
1708
1709 @Test
1710 void testGetDayOfYear() {
1711 Assertions.assertEquals(0.501,
1712 new AbsoluteDate(2004, 1, 1, 0, 0, 0.001, utc).getDayOfYear(utc),
1713 1.0e-3);
1714 Assertions.assertEquals(1.000,
1715 new AbsoluteDate(2004, 1, 1, 12, 0, 0.000, utc).getDayOfYear(utc),
1716 1.0e-3);
1717 Assertions.assertEquals(366.0,
1718 new AbsoluteDate(2004, 12, 31, 12, 0, 0.000, utc).getDayOfYear(utc),
1719 1.0e-3);
1720 Assertions.assertEquals(366.499999988426,
1721 new AbsoluteDate(2004, 12, 31, 23, 59, 59.999, utc).getDayOfYear(utc),
1722 1.0e-12);
1723 Assertions.assertEquals(0.500000011574,
1724 new AbsoluteDate(2004, 12, 31, 23, 59, 59.999, utc).shiftedBy(0.002).getDayOfYear(utc),
1725 1.0e-12);
1726 }
1727
1728 @BeforeEach
1729 public void setUp() {
1730 Utils.setDataRoot("regular-data");
1731 utc = TimeScalesFactory.getUTC();
1732 present = new AbsoluteDate(new DateComponents(2000, 1, 1),
1733 new TimeComponents(12, 0, 0), utc);
1734 presentToo = new AnyTimeStamped(present.shiftedBy(0));
1735 past = new AnyTimeStamped(present.shiftedBy(-1000));
1736 future = new AnyTimeStamped(present.shiftedBy(1000));
1737 }
1738
1739 private TimeScale utc;
1740 private AbsoluteDate present;
1741 private AnyTimeStamped past;
1742 private AnyTimeStamped presentToo;
1743 private AnyTimeStamped future;
1744
1745 static class AnyTimeStamped implements TimeStamped {
1746 AbsoluteDate date;
1747 public AnyTimeStamped(AbsoluteDate date) {
1748 this.date = date;
1749 }
1750
1751 @Override
1752 public AbsoluteDate getDate() {
1753 return date;
1754 }
1755 }
1756 }