Search in sources :

Example 21 with ZoneOffsetTransition

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

the class TCKZoneRules method checkOffset.

private ZoneOffsetTransition checkOffset(ZoneRules rules, LocalDateTime dateTime, ZoneOffset offset, int type) {
    List<ZoneOffset> validOffsets = rules.getValidOffsets(dateTime);
    assertEquals(validOffsets.size(), type);
    assertEquals(rules.getOffset(dateTime), offset);
    if (type == 1) {
        assertEquals(validOffsets.get(0), offset);
        return null;
    } else {
        ZoneOffsetTransition zot = rules.getTransition(dateTime);
        assertNotNull(zot);
        assertEquals(zot.isOverlap(), type == 2);
        assertEquals(zot.isGap(), type == 0);
        assertEquals(zot.isValidOffset(offset), type == 2);
        return zot;
    }
}
Also used : ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition) ZoneOffset(java.time.ZoneOffset)

Example 22 with ZoneOffsetTransition

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

the class TCKZoneRules method test_Paris_getOffsetInfo_overlap.

public void test_Paris_getOffsetInfo_overlap() {
    ZoneRules test = europeParis();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 10, 26, 2, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_PTWO, OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), OFFSET_PTWO);
    assertEquals(trans.getOffsetAfter(), OFFSET_PONE);
    assertEquals(trans.getInstant(), createInstant(2008, 10, 26, 1, 0, ZoneOffset.UTC));
    assertEquals(trans.isValidOffset(OFFSET_ZERO), false);
    assertEquals(trans.isValidOffset(OFFSET_PONE), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(3)), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-10-26T03:00+02:00 to +01:00]");
    assertFalse(trans.equals(null));
    assertFalse(trans.equals(OFFSET_PTWO));
    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 23 with ZoneOffsetTransition

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

the class TCKZoneRules method test_NewYork_getOffsetInfo_overlap.

public void test_NewYork_getOffsetInfo_overlap() {
    ZoneRules test = americaNewYork();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 11, 2, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, ZoneOffset.ofHours(-4), OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(-4));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(-5));
    assertEquals(trans.getInstant(), createInstant(2008, 11, 2, 2, 0, ZoneOffset.ofHours(-4)));
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-5)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-4)), true);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-11-02T02:00-04:00 to -05:00]");
    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(-4)));
    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 24 with ZoneOffsetTransition

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

the class TCKZoneRules method test_London_getOffsetInfo_gap.

public void test_London_getOffsetInfo_gap() {
    ZoneRules test = europeLondon();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_ZERO, GAP);
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.getOffsetBefore(), OFFSET_ZERO);
    assertEquals(trans.getOffsetAfter(), OFFSET_PONE);
    assertEquals(trans.getInstant(), createInstant(2008, 3, 30, 1, 0, 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(OFFSET_ZERO), false);
    assertEquals(trans.isValidOffset(OFFSET_PONE), false);
    assertEquals(trans.isValidOffset(OFFSET_PTWO), false);
    assertEquals(trans.toString(), "Transition[Gap at 2008-03-30T01:00Z to +01:00]");
    assertFalse(trans.equals(null));
    assertFalse(trans.equals(OFFSET_ZERO));
    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 25 with ZoneOffsetTransition

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

the class TCKZoneRules method test_Apia_nextTransition_historic.

public void test_Apia_nextTransition_historic() {
    ZoneRules test = pacificApia();
    List<ZoneOffsetTransition> trans = test.getTransitions();
    ZoneOffsetTransition first = trans.get(0);
    assertEquals(test.nextTransition(first.getInstant().minusNanos(1)), first);
    for (int i = 0; i < trans.size() - 1; i++) {
        ZoneOffsetTransition cur = trans.get(i);
        ZoneOffsetTransition next = trans.get(i + 1);
        assertEquals(test.nextTransition(cur.getInstant()), next);
        assertEquals(test.nextTransition(next.getInstant().minusNanos(1)), next);
    }
}
Also used : ZoneRules(java.time.zone.ZoneRules) 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