Ejemplo n.º 1
0
 public void test_negativeLeap_justAfterLeap() {
   rules.register(MJD_2100 - 1, -1);
   TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC2100_EXTRA_NEGATIVE_LEAP, 0); // 2100-01-01
   UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_2100, 0);
   assertEquals(rules.convertToUtc(tai), expected);
   assertEquals(rules.convertToTai(expected), tai); // check reverse
 }
Ejemplo n.º 2
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void test_registerLeapSecond_equalEarlierDate_differentLeap() {
   long[] dates = rules.getLeapSecondDates();
   long mjd = dates[dates.length - 2];
   int adj = rules.getLeapSecondAdjustment(mjd);
   rules.register(mjd, -adj);
 }
Ejemplo n.º 3
0
 public void test_convertToUtc_TaiInstant_justAfterLeap() {
   TaiInstant tai =
       TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980, 0); // 1980-01-01 (19 leap secs added)
   UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980, 0);
   assertEquals(rules.convertToUtc(tai), expected);
   assertEquals(rules.convertToTai(expected), tai); // check reverse
 }
Ejemplo n.º 4
0
 public void test_convertToInstant_furtherAfterLeap() {
   OffsetDateTime odt = OffsetDateTime.of(1980, 1, 1, 0, 0, 1, 0, ZoneOffset.UTC);
   Instant instant = odt.toInstant();
   UtcInstant utc = UtcInstant.ofModifiedJulianDay(MJD_1980, NANOS_PER_SEC);
   assertEquals(rules.convertToInstant(utc), instant);
   assertEquals(rules.convertToUtc(instant), utc);
 }
Ejemplo n.º 5
0
 // -----------------------------------------------------------------------
 // convertToUtc(Instant)/convertToInstant(UtcInstant)
 // -----------------------------------------------------------------------
 public void test_convertToInstant_justBeforeLeap() {
   OffsetDateTime odt = OffsetDateTime.of(1979, 12, 31, 23, 43, 21, 0, ZoneOffset.UTC);
   Instant instant = odt.toInstant();
   UtcInstant utc =
       UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC);
   assertEquals(rules.convertToInstant(utc), instant);
   assertEquals(rules.convertToUtc(instant), utc);
 }
Ejemplo n.º 6
0
 public void test_convertToUtc_TaiInstant_justBeforeLeap() {
   TaiInstant tai =
       TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980 - 2, 0); // 1980-01-01 (2 seconds before 1980)
   UtcInstant expected =
       UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, (SECS_PER_DAY - 1) * NANOS_PER_SEC);
   assertEquals(rules.convertToUtc(tai), expected);
   assertEquals(rules.convertToTai(expected), tai); // check reverse
 }
Ejemplo n.º 7
0
 public void test_registerLeapSecond_justAfterLastDate_minusOne() {
   long[] dates = rules.getLeapSecondDates();
   long mjd = dates[dates.length - 1] + 1;
   rules.register(mjd, -1);
   long[] test = rules.getLeapSecondDates();
   assertEquals(test.length, dates.length + 1);
   assertEquals(test[test.length - 1], mjd);
   assertEquals(rules.getLeapSecondAdjustment(mjd), -1);
 }
Ejemplo n.º 8
0
 public void test_registerLeapSecond_equalEarlierDate_sameLeap() {
   long[] dates = rules.getLeapSecondDates();
   long mjd = dates[dates.length - 2];
   int adj = rules.getLeapSecondAdjustment(mjd);
   rules.register(mjd, adj);
   long[] test = rules.getLeapSecondDates();
   assertEquals(Arrays.equals(test, dates), true);
   assertEquals(rules.getLeapSecondAdjustment(mjd), adj);
 }
Ejemplo n.º 9
0
 // -------------------------------------------------------------------------
 public void test_negativeLeap_justBeforeLeap() {
   rules.register(MJD_2100 - 1, -1);
   TaiInstant tai =
       TaiInstant.ofTaiSeconds(
           TAI_SECS_UTC2100_EXTRA_NEGATIVE_LEAP - 1, 0); // 2100-01-01 (1 second before 2100)
   UtcInstant expected =
       UtcInstant.ofModifiedJulianDay(MJD_2100 - 1, (SECS_PER_DAY - 2) * NANOS_PER_SEC);
   assertEquals(rules.convertToUtc(tai), expected);
   assertEquals(rules.convertToTai(expected), tai); // check reverse
 }
Ejemplo n.º 10
0
  @Test(dataProvider = "LeapSeconds")
  public void test_leapSeconds(long mjd, int adjust, int offset, String checkDate) {
    assertEquals(
        mjd, LocalDate.parse(checkDate).getLong(JulianFields.MODIFIED_JULIAN_DAY), "Invalid test");

    assertEquals(rules.getLeapSecondAdjustment(mjd), adjust);
    assertEquals(rules.getTaiOffset(mjd), offset);
    if (adjust != 0) {
      long[] leaps = rules.getLeapSecondDates();
      Arrays.sort(leaps);
      assertEquals(Arrays.binarySearch(leaps, mjd) >= 0, true);
    }
  }
Ejemplo n.º 11
0
 public void test_convertToInstant_slsMicros() {
   for (int i = 1; i < 1000; i++) {
     long utcNanos = (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000;
     long startSls = (86401 - 1000) * NANOS_PER_SEC;
     long slsNanos = (utcNanos - (utcNanos - startSls) / 1000);
     OffsetDateTime odt =
         OffsetDateTime.of(
             1979, 12, 31, 23, 43, 21, (int) (slsNanos % NANOS_PER_SEC), ZoneOffset.UTC);
     Instant instant = odt.toInstant();
     UtcInstant utc =
         UtcInstant.ofModifiedJulianDay(
             MJD_1980 - 1, (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i * 1000);
     assertEquals(rules.convertToInstant(utc), instant);
     assertEquals(rules.convertToUtc(instant), utc);
   }
 }
Ejemplo n.º 12
0
 public void test_convertToUtc_TaiInstant_startUtcPeriod() {
   TaiInstant tai =
       TaiInstant.ofTaiSeconds(TAI_SECS_UTC1980, 0); // 1980-01-01 (19 leap secs added)
   UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_1980, 0);
   for (int i = -10; i < 10; i++) {
     Duration duration = Duration.ofNanos(i);
     assertEquals(rules.convertToUtc(tai.plus(duration)), expected.plus(duration));
     assertEquals(
         rules.convertToTai(expected.plus(duration)), tai.plus(duration)); // check reverse
   }
   for (int i = -10; i < 10; i++) {
     Duration duration = Duration.ofSeconds(i);
     assertEquals(rules.convertToUtc(tai.plus(duration)), expected.plus(duration));
     assertEquals(
         rules.convertToTai(expected.plus(duration)), tai.plus(duration)); // check reverse
   }
 }
Ejemplo n.º 13
0
 public void test_convertToInstant_slsNanos() {
   for (int i = 1; i < 5005; i++) {
     long utcNanos = (SECS_PER_DAY + 1 - 1000) * NANOS_PER_SEC + i;
     long startSls = (86401 - 1000) * NANOS_PER_SEC;
     long slsNanos = (utcNanos - (utcNanos - startSls) / 1000);
     OffsetDateTime odt =
         OffsetDateTime.of(
             1979, 12, 31, 23, 43, 21, (int) (slsNanos % NANOS_PER_SEC), ZoneOffset.UTC);
     Instant instant = odt.toInstant();
     UtcInstant utc = UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, utcNanos);
     assertEquals(rules.convertToInstant(utc), instant);
     // not all instants can map back to the correct UTC value
     long reverseUtcNanos = startSls + ((slsNanos - startSls) * 1000L) / (1000L - 1);
     assertEquals(
         rules.convertToUtc(instant),
         UtcInstant.ofModifiedJulianDay(MJD_1980 - 1, reverseUtcNanos));
   }
 }
Ejemplo n.º 14
0
 // -----------------------------------------------------------------------
 // getName()
 // -----------------------------------------------------------------------
 public void test_getName() {
   assertEquals(rules.getName(), "System");
 }
Ejemplo n.º 15
0
 // -----------------------------------------------------------------------
 // toString()
 // -----------------------------------------------------------------------
 public void test_toString() {
   assertEquals(rules.toString(), "UtcRules[System]");
 }
Ejemplo n.º 16
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void test_registerLeapSecond_invalidAdjustment_three() {
   rules.register(MJD_2100, 3);
 }
Ejemplo n.º 17
0
 @Test(expectedExceptions = IllegalArgumentException.class)
 public void test_registerLeapSecond_beforeLastDate() {
   long[] dates = rules.getLeapSecondDates();
   long mjd = dates[dates.length - 1] - 1;
   rules.register(mjd, 1);
 }
Ejemplo n.º 18
0
 public void test_convertToUtc_TaiInstant_2100() {
   TaiInstant tai = TaiInstant.ofTaiSeconds(TAI_SECS_UTC2100, 0); // 2100-01-01
   UtcInstant expected = UtcInstant.ofModifiedJulianDay(MJD_2100, 0);
   assertEquals(rules.convertToUtc(tai), expected);
   assertEquals(rules.convertToTai(expected), tai); // check reverse
 }
Ejemplo n.º 19
0
 @Test(expectedExceptions = NullPointerException.class)
 public void test_convertToTai_UtcInstant_null() {
   rules.convertToTai((UtcInstant) null);
 }