예제 #1
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);
 }
예제 #2
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);
 }
예제 #3
0
 @DataProvider(name = "parseWithOffsetWithoutZone")
 Object[][] data_parse_WithOffset_WithoutZone() {
   return new Object[][] {
     {
       "2015-12-14T00:45:00-11:30",
       OffsetDateTime.of(2015, 12, 14, 0, 45, 0, 0, ZoneOffset.of("-11:30"))
     },
     {
       "2015-12-14T01:45:00-05:00",
       OffsetDateTime.of(2015, 12, 14, 1, 45, 0, 0, ZoneOffset.of("-05:00"))
     },
     {
       "2015-12-14T02:45:00-00:00",
       OffsetDateTime.of(2015, 12, 14, 2, 45, 0, 0, ZoneOffset.of("-00:00"))
     },
     {
       "2015-12-14T03:45:00+00:00",
       OffsetDateTime.of(2015, 12, 14, 3, 45, 0, 0, ZoneOffset.of("+00:00"))
     },
     {
       "2015-12-14T04:45:00+03:30",
       OffsetDateTime.of(2015, 12, 14, 4, 45, 0, 0, ZoneOffset.of("+03:30"))
     },
     {
       "2015-12-14T05:45:00+10:00",
       OffsetDateTime.of(2015, 12, 14, 5, 45, 0, 0, ZoneOffset.of("+10:00"))
     }
   };
 }
예제 #4
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);
   }
 }
예제 #5
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));
   }
 }