Search in sources :

Example 66 with ZoneRules

use of java.time.zone.ZoneRules in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_Apia_jumpOverInternationalDateLine_M10_to_P14.

public void test_Apia_jumpOverInternationalDateLine_M10_to_P14() {
    // transition occurred at 2011-12-30T00:00-10:00
    ZoneRules test = pacificApia();
    Instant instantBefore = LocalDate.of(2011, 12, 27).atStartOfDay(ZoneOffset.UTC).toInstant();
    ZoneOffsetTransition trans = test.nextTransition(instantBefore);
    assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2011, 12, 30, 0, 0));
    assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2011, 12, 31, 0, 0));
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-10)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(+14)), false);
    assertEquals(trans.getDuration(), Duration.ofHours(24));
    assertEquals(trans.getInstant(), LocalDateTime.of(2011, 12, 31, 0, 0).toInstant(ZoneOffset.ofHours(+14)));
    ZonedDateTime zdt = ZonedDateTime.of(2011, 12, 29, 23, 0, 0, 0, ZoneId.of("Pacific/Apia"));
    assertEquals(zdt.plusHours(2).toLocalDateTime(), LocalDateTime.of(2011, 12, 31, 1, 0));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 67 with ZoneRules

use of java.time.zone.ZoneRules in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_London_getStandardOffset.

public void test_London_getStandardOffset() {
    ZoneRules test = europeLondon();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.getYear() < 1848) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15));
        } else if (zdt.getYear() >= 1969 && zdt.getYear() < 1972) {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        }
        zdt = zdt.plusMonths(6);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules)

Example 68 with ZoneRules

use of java.time.zone.ZoneRules in project jdk8u_jdk by JetBrains.

the class TestFixedZoneRules method test_data_nullInput.

//-----------------------------------------------------------------------
@Test
public void test_data_nullInput() {
    ZoneRules test = make(OFFSET_PONE);
    assertEquals(test.getOffset((Instant) null), OFFSET_PONE);
    assertEquals(test.getOffset((LocalDateTime) null), OFFSET_PONE);
    assertEquals(test.getValidOffsets(null).size(), 1);
    assertEquals(test.getValidOffsets(null).get(0), OFFSET_PONE);
    assertEquals(test.getTransition(null), null);
    assertEquals(test.getStandardOffset(null), OFFSET_PONE);
    assertEquals(test.getDaylightSavings(null), Duration.ZERO);
    assertEquals(test.isDaylightSavings(null), false);
    assertEquals(test.nextTransition(null), null);
    assertEquals(test.previousTransition(null), null);
}
Also used : LocalDateTime(java.time.LocalDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules) Test(org.testng.annotations.Test)

Aggregations

ZoneRules (java.time.zone.ZoneRules)68 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)22 LocalDateTime (java.time.LocalDateTime)10 Test (org.testng.annotations.Test)10 Instant (java.time.Instant)9 ZoneOffset (java.time.ZoneOffset)9 ZonedDateTime (java.time.ZonedDateTime)9 ZoneOffsetTransitionRule (java.time.zone.ZoneOffsetTransitionRule)5 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 ObjectInputStream (java.io.ObjectInputStream)2 ObjectOutputStream (java.io.ObjectOutputStream)2 OffsetDateTime (java.time.OffsetDateTime)1 TimeDefinition (java.time.zone.ZoneOffsetTransitionRule.TimeDefinition)1 ZoneRulesException (java.time.zone.ZoneRulesException)1 ArrayList (java.util.ArrayList)1 TreeMap (java.util.TreeMap)1