Search in sources :

Example 6 with ZoneOffsetTransition

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

the class TCKZoneRules method test_London_nextTransition_lastYear.

public void test_London_nextTransition_lastYear() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    ZoneOffsetTransition zot = rules.get(1).createTransition(Year.MAX_VALUE);
    assertEquals(test.nextTransition(zot.getInstant()), null);
}
Also used : ZoneOffsetTransitionRule(java.time.zone.ZoneOffsetTransitionRule) ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 7 with ZoneOffsetTransition

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

the class TCKZoneRules method test_London_getTransitions.

public void test_London_getTransitions() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransition> trans = test.getTransitions();
    ZoneOffsetTransition first = trans.get(0);
    assertEquals(first.getDateTimeBefore(), LocalDateTime.of(1847, 12, 1, 0, 0));
    assertEquals(first.getOffsetBefore(), ZoneOffset.ofHoursMinutesSeconds(0, -1, -15));
    assertEquals(first.getOffsetAfter(), OFFSET_ZERO);
    ZoneOffsetTransition spring1916 = trans.get(1);
    assertEquals(spring1916.getDateTimeBefore(), LocalDateTime.of(1916, 5, 21, 2, 0));
    assertEquals(spring1916.getOffsetBefore(), OFFSET_ZERO);
    assertEquals(spring1916.getOffsetAfter(), OFFSET_PONE);
    ZoneOffsetTransition autumn1916 = trans.get(2);
    assertEquals(autumn1916.getDateTimeBefore(), LocalDateTime.of(1916, 10, 1, 3, 0));
    assertEquals(autumn1916.getOffsetBefore(), OFFSET_PONE);
    assertEquals(autumn1916.getOffsetAfter(), OFFSET_ZERO);
    ZoneOffsetTransition zot = null;
    Iterator<ZoneOffsetTransition> it = trans.iterator();
    while (it.hasNext()) {
        zot = it.next();
        if (zot.getDateTimeBefore().getYear() == 1990) {
            break;
        }
    }
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1990, 3, 25, 1, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_ZERO);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1990, 10, 28, 2, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_PONE);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1991, 3, 31, 1, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_ZERO);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1991, 10, 27, 2, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_PONE);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1992, 3, 29, 1, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_ZERO);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1992, 10, 25, 2, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_PONE);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1993, 3, 28, 1, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_ZERO);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1993, 10, 24, 2, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_PONE);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1994, 3, 27, 1, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_ZERO);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1994, 10, 23, 2, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_PONE);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1995, 3, 26, 1, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_ZERO);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1995, 10, 22, 2, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_PONE);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1996, 3, 31, 1, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_ZERO);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1996, 10, 27, 2, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_PONE);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1997, 3, 30, 1, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_ZERO);
    zot = it.next();
    assertEquals(zot.getDateTimeBefore(), LocalDateTime.of(1997, 10, 26, 2, 0));
    assertEquals(zot.getOffsetBefore(), OFFSET_PONE);
    assertEquals(it.hasNext(), false);
}
Also used : ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 8 with ZoneOffsetTransition

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

the class TCKZoneRules method test_Kathmandu_nextTransition_noRules.

public void test_Kathmandu_nextTransition_noRules() {
    ZoneRules test = asiaKathmandu();
    List<ZoneOffsetTransition> trans = test.getTransitions();
    ZoneOffsetTransition last = trans.get(trans.size() - 1);
    assertEquals(test.nextTransition(last.getInstant()), null);
}
Also used : ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 9 with ZoneOffsetTransition

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

the class TCKZoneRules method test_London_nextTransition_historic.

//-----------------------------------------------------------------------
public void test_London_nextTransition_historic() {
    ZoneRules test = europeLondon();
    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)

Example 10 with ZoneOffsetTransition

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

the class TestZoneId method test_London_getOffsetInfo_overlap.

public void test_London_getOffsetInfo_overlap() {
    ZoneId test = ZoneId.of("Europe/London");
    final LocalDateTime dateTime = LocalDateTime.of(2008, 10, 26, 1, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(1), OVERLAP);
    assertEquals(trans.isGap(), false);
    assertEquals(trans.isOverlap(), true);
    assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(1));
    assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(0));
    assertEquals(trans.getInstant(), dateTime.toInstant(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(ZoneOffset.ofHours(0)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(1)), true);
    assertEquals(trans.isValidOffset(ZoneOffset.ofHours(2)), false);
    assertEquals(trans.toString(), "Transition[Overlap at 2008-10-26T02:00+01:00 to Z]");
    assertFalse(trans.equals(null));
    assertFalse(trans.equals(ZoneOffset.ofHours(1)));
    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