Commit eda45005 authored by Luc Maisonobe's avatar Luc Maisonobe

Fixed accuracy of dates conversions from java dates.

parent 818a4461
......@@ -33,6 +33,9 @@
as updates to AbstractDetector, AbstractGNSSAttitudeProvider, DragSensitive,
RadiationSensitive, and ZipJarCrawler. See the list below for a full
description of the changes.">
<action dev="luc" type="fix" >
Fixed accuracy of dates conversions from java dates.
</action>
<action dev="evan" type="fix" issue="566">
Make ITRFVersionLoader public.
</action>
......
......@@ -322,7 +322,7 @@ public class AbsoluteDate
public AbsoluteDate(final Date location, final TimeScale timeScale) {
this(new DateComponents(DateComponents.JAVA_EPOCH,
(int) (location.getTime() / 86400000l)),
new TimeComponents(0.001 * (location.getTime() % 86400000l)),
millisToTimeComponents((int) (location.getTime() % 86400000l)),
timeScale);
}
......@@ -403,6 +403,14 @@ public class AbsoluteDate
this.offset = offset;
}
/** Extract time components from a number of milliseconds within the day.
* @param millisInDay number of milliseconds within the day
* @return time components
*/
private static TimeComponents millisToTimeComponents(final int millisInDay) {
return new TimeComponents(millisInDay / 1000, 0.001 * (millisInDay % 1000));
}
/** Get the reference epoch in seconds from 2000-01-01T12:00:00 TAI.
* <p>
* This method is reserved for internal used (for example by {@link FieldAbsoluteDate}).
......
......@@ -18,6 +18,11 @@ package org.orekit.time;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Date;
import java.util.TimeZone;
......@@ -799,6 +804,20 @@ public class AbsoluteDateTest {
}
@Test
public void testIssueTimesStampAccuracy() {
String testString = "2019-02-01T13:06:03.115";
TimeScale timeScale=TimeScalesFactory.getUTC();
DateTimeComponents expectedComponent = DateTimeComponents.parseDateTime(testString);
AbsoluteDate expectedDate = new AbsoluteDate(expectedComponent, timeScale);
ZonedDateTime actualComponent = LocalDateTime.from(DateTimeFormatter.ISO_DATE_TIME.parse(testString)).atZone(ZoneOffset.UTC);
AbsoluteDate actualDate = new AbsoluteDate(Timestamp.from(actualComponent.toInstant()), timeScale);
Assert.assertEquals(0.0, expectedDate.durationFrom(actualDate), 1.0e-15);
}
@Before
public void setUp() {
Utils.setDataRoot("regular-data");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment