Incorrect Leap Second Handling in AbsoluteDate.createMJDDate(...)
One second is added to the created date when it occurs within a leap second, apparently due to applying the new leap second offset before it is actually valid. Below is a failing test case.
```java
@Test
public void testMJD() {
// inside a leap second
AbsoluteDate date1 = new AbsoluteDate(2008, 12, 31, 23, 59, 60.5, utc);
// check date to MJD conversion
DateTimeComponents date1Components = date1.getComponents(utc);
int mjd = date1Components.getDate().getMJD();
double seconds = date1Components.getTime().getSecondsInUTCDay();
Assert.assertEquals(54831, mjd);
Assert.assertEquals(86400.5, seconds, 0);
// check MJD to date conversion
AbsoluteDate date2 = AbsoluteDate.createMJDDate(mjd, seconds, utc);
Assert.assertEquals(date1, date2); // fails here
}
```
Appears to be due to the fact that new TimeComponents(86400).getHour() returns 24 which is not right during a leap second. Then UTCScale.offsetToTAI(...) sees that getHour() is 24 and treats the date as being in the next day.
I can fix createMJDDate(...) by replacing new TimeComponents(s) with shiftedBy(s). The only change in behavior will be that when the user provides a seconds number >= 86401 an exception will no longer be thrown.
Luc, would you mind taking a look at new TimeComponents(s) and UTCScale.offsetToTAI(...) to see if anything needs to be changed there?
(from redmine: issue id 247, created on 2016-07-01, closed on 2017-07-27)
- Changesets:
- Revision 9ad994c3 by Evan Ward on 2016-07-01T14:39:15Z:
Fix leap seconds in AbsoluteDate.createMJDDate()
Previously dates inside a leap second had one second added to the result, which
made it impossible to create dates inside of leap seconds. Now createMJDDate()
uses the shiftedBy() method which correctly handles leap seconds.
Fixes #247
- Revision 9ad994c3 by Evan Ward on 2016-07-01T14:39:15Z:
Fix leap seconds in AbsoluteDate.createMJDDate()
Previously dates inside a leap second had one second added to the result, which
made it impossible to create dates inside of leap seconds. Now createMJDDate()
uses the shiftedBy() method which correctly handles leap seconds.
Fixes #247
- Revision 9ad994c3 by Evan Ward on 2016-07-01T14:39:15Z:
Fix leap seconds in AbsoluteDate.createMJDDate()
Previously dates inside a leap second had one second added to the result, which
made it impossible to create dates inside of leap seconds. Now createMJDDate()
uses the shiftedBy() method which correctly handles leap seconds.
Fixes #247
- Revision 9ad994c3 by Evan Ward on 2016-07-01T14:39:15Z:
Fix leap seconds in AbsoluteDate.createMJDDate()
Previously dates inside a leap second had one second added to the result, which
made it impossible to create dates inside of leap seconds. Now createMJDDate()
uses the shiftedBy() method which correctly handles leap seconds.
Fixes #247