Search in sources :

Example 26 with ZoneOffsetTransition

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

the class TCKZoneRules method test_London_getOffsetInfo_overlap.

public void test_London_getOffsetInfo_overlap() {
    ZoneRules test = europeLondon();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 10, 26, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_PONE, OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), OFFSET_PONE);
    assertEquals(trans.getOffsetAfter(), OFFSET_ZERO);
    assertEquals(trans.getInstant(), createInstant(2008, 10, 26, 1, 0, ZoneOffset.UTC));
    assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2008, 10, 26, 2, 0));
    assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2008, 10, 26, 1, 0));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(OFFSET_ZERO), true);
    assertEquals(trans.isValidOffset(OFFSET_PONE), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-10-26T02:00+01:00 to Z]");
    assertFalse(trans.equals(null));
    assertFalse(trans.equals(OFFSET_PONE));
    assertTrue(trans.equals(trans));
    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 27 with ZoneOffsetTransition

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

the class TCKZoneRules method test_NewYork_getOffsetInfo_gap.

public void test_NewYork_getOffsetInfo_gap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 9, 2, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-5), GAP);
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getInstant(), createInstant(2008, 3, 9, 2, 0, ZoneOffset.ofHours(-5)));
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), false);
    assertEquals(trans.toString(), "Transition[Gap at 2008-03-09T02:00-05:00 to -04:00]");
    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-5)));
    assertTrue(trans.equals(trans));
    final ZoneOffsetTransition otherTrans = test.getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 28 with ZoneOffsetTransition

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

the class TCKZoneRules method test_London_previousTransition_historic.

//-----------------------------------------------------------------------
public void test_London_previousTransition_historic() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransition> trans = test.getTransitions();
    ZoneOffsetTransition first = trans.get(0);
    assertEquals(test.previousTransition(first.getInstant()), null);
    assertEquals(test.previousTransition(first.getInstant().minusNanos(1)), null);
    for (int i = 0; i < trans.size() - 1; i++) {
        ZoneOffsetTransition prev = trans.get(i);
        ZoneOffsetTransition cur = trans.get(i + 1);
        assertEquals(test.previousTransition(cur.getInstant()), prev);
        assertEquals(test.previousTransition(prev.getInstant().plusSeconds(1)), prev);
        assertEquals(test.previousTransition(prev.getInstant().plusNanos(1)), prev);
    }
}
Also used : ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 29 with ZoneOffsetTransition

use of java.time.zone.ZoneOffsetTransition 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 30 with ZoneOffsetTransition

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

the class TestZoneId method test_London_getOffsetInfo_gap.

public void test_London_getOffsetInfo_gap() {
    ZoneId test = ZoneId.of("Europe/London");
    final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(0), GAP);
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(0));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(1));
    assertEquals(trans.getInstant(), dateTime.toInstant(ZoneOffset.UTC));
    assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2008, 3, 30, 1, 0));
    assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2008, 3, 30, 2, 0));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(0)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(2)), false);
    assertEquals(trans.toString(), "Transition[Gap at 2008-03-30T01:00Z to +01:00]");
    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(0)));
    assertTrue(trans.equals(trans));
    final ZoneOffsetTransition otherTrans = test.getRules().getTransition(dateTime);
    assertTrue(trans.equals(otherTrans));
    assertEquals(trans.hashCode(), otherTrans.hashCode());
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneId(java.time.ZoneId) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Aggregations

ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)50 LocalDateTime (java.time.LocalDateTime)26 ZoneRules (java.time.zone.ZoneRules)22 Test (org.testng.annotations.Test)20 AbstractTCKTest (tck.java.time.AbstractTCKTest)20 ZoneOffsetTransitionRule (java.time.zone.ZoneOffsetTransitionRule)10 ZoneId (java.time.ZoneId)6 ZoneOffset (java.time.ZoneOffset)4 ZonedDateTime (java.time.ZonedDateTime)3 Instant (java.time.Instant)2 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)2 OffsetDateTime (java.time.OffsetDateTime)1 TimeDefinition (java.time.zone.ZoneOffsetTransitionRule.TimeDefinition)1 ArrayList (java.util.ArrayList)1