/** * Tests that adding small values to a UTC Julian date does not result in getting stuck when crossing a leap second. */ @Test public final void testUtcAddNotStuckAtLeapSecond() { LeapSeconds leapSeconds = new LeapSeconds(); LeapSeconds.setInstance(leapSeconds); JulianDate date = new JulianDate(2453736, 43198.0, TimeStandard.COORDINATED_UNIVERSAL_TIME); JulianDate after = new JulianDate(2453736, 43202.0, TimeStandard.COORDINATED_UNIVERSAL_TIME); int i; for (i = 0; i < 100; ++i) { date = JulianDate.add(date, Duration.fromSeconds(0.1)); if (JulianDate.greaterThan(date, after)) { break; } } //5 second difference, so 50 additions of a tenth of a second each Assert.assertEquals((int) 50, (int) i); }
/** * Converts two Julian dates in TAI to UTC: one just before a leap second, and one after a leap second. Verifies that they convert to different UTC Julian dates. */ @Test public final void testTaiToUtcNearLeapSecond() { LeapSeconds leapSeconds = new LeapSeconds(); LeapSeconds.setInstance(leapSeconds); JulianDate momentOfLeapSecond = new JulianDate(2453736, 43232.0, TimeStandard.INTERNATIONAL_ATOMIC_TIME); JulianDate before = JulianDate.subtract(momentOfLeapSecond, Duration.fromSeconds(1.0)); JulianDate after = JulianDate.add(momentOfLeapSecond, Duration.fromSeconds(1.0)); JulianDate beforeUtc = before.toTimeStandard(TimeStandard.COORDINATED_UNIVERSAL_TIME); JulianDate afterUtc = after.toTimeStandard(TimeStandard.COORDINATED_UNIVERSAL_TIME); AssertHelper.assertNotEqual(beforeUtc, afterUtc); }