コード例 #1
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
 }
コード例 #2
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);
 }
コード例 #3
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
 }
コード例 #4
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);
 }
コード例 #5
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
 }
コード例 #6
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
   }
 }
コード例 #7
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
 }
コード例 #8
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);
   }
 }
コード例 #9
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));
   }
 }
コード例 #10
0
 @Test(expectedExceptions = NullPointerException.class)
 public void test_convertToUtc_TaiInstant_null() {
   rules.convertToUtc((TaiInstant) null);
 }
コード例 #11
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
 }