Search in sources :

Example 1 with ZoneRules

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

the class TCKZoneRulesSerialization method assertSerialization.

private void assertSerialization(ZoneRules test) throws Exception {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream out = new ObjectOutputStream(baos);
    out.writeObject(test);
    baos.close();
    byte[] bytes = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream in = new ObjectInputStream(bais);
    ZoneRules result = (ZoneRules) in.readObject();
    assertEquals(result, test);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ZoneRules(java.time.zone.ZoneRules) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with ZoneRules

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

the class TCKZoneRules method test_London_previousTransition_rulesBased.

public void test_London_previousTransition_rulesBased() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    List<ZoneOffsetTransition> trans = test.getTransitions();
    ZoneOffsetTransition last = trans.get(trans.size() - 1);
    assertEquals(test.previousTransition(last.getInstant().plusSeconds(1)), last);
    assertEquals(test.previousTransition(last.getInstant().plusNanos(1)), last);
    // Jan 1st of year between transitions and rules
    ZonedDateTime odt = ZonedDateTime.ofInstant(last.getInstant(), last.getOffsetAfter());
    odt = odt.withDayOfYear(1).plusYears(1).with(LocalTime.MIDNIGHT);
    assertEquals(test.previousTransition(odt.toInstant()), last);
    // later years
    for (int year = 1998; year < 2010; year++) {
        ZoneOffsetTransition a = rules.get(0).createTransition(year);
        ZoneOffsetTransition b = rules.get(1).createTransition(year);
        ZoneOffsetTransition c = rules.get(0).createTransition(year + 1);
        assertEquals(test.previousTransition(c.getInstant()), b);
        assertEquals(test.previousTransition(b.getInstant().plusSeconds(1)), b);
        assertEquals(test.previousTransition(b.getInstant().plusNanos(1)), b);
        assertEquals(test.previousTransition(b.getInstant()), a);
        assertEquals(test.previousTransition(a.getInstant().plusSeconds(1)), a);
        assertEquals(test.previousTransition(a.getInstant().plusNanos(1)), a);
    }
}
Also used : ZoneOffsetTransitionRule(java.time.zone.ZoneOffsetTransitionRule) ZonedDateTime(java.time.ZonedDateTime) ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 3 with ZoneRules

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

the class TCKZoneRules method test_London_getOffsetInfo_toDST.

public void test_London_getOffsetInfo_toDST() {
    ZoneRules test = europeLondon();
    checkOffset(test, createLDT(2008, 3, 24), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 3, 25), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 3, 26), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 3, 27), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 3, 28), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 3, 29), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 3, 30), OFFSET_ZERO, 1);
    checkOffset(test, createLDT(2008, 3, 31), OFFSET_PONE, 1);
    // cutover at 01:00Z
    checkOffset(test, LocalDateTime.of(2008, 3, 30, 0, 59, 59, 999999999), OFFSET_ZERO, 1);
    checkOffset(test, LocalDateTime.of(2008, 3, 30, 2, 0, 0, 0), OFFSET_PONE, 1);
}
Also used : ZoneRules(java.time.zone.ZoneRules)

Example 4 with ZoneRules

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

the class TCKZoneRules method test_London_nextTransition_rulesBased.

public void test_London_nextTransition_rulesBased() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    List<ZoneOffsetTransition> trans = test.getTransitions();
    ZoneOffsetTransition last = trans.get(trans.size() - 1);
    assertEquals(test.nextTransition(last.getInstant()), rules.get(0).createTransition(1998));
    for (int year = 1998; year < 2010; year++) {
        ZoneOffsetTransition a = rules.get(0).createTransition(year);
        ZoneOffsetTransition b = rules.get(1).createTransition(year);
        ZoneOffsetTransition c = rules.get(0).createTransition(year + 1);
        assertEquals(test.nextTransition(a.getInstant()), b);
        assertEquals(test.nextTransition(b.getInstant().minusNanos(1)), b);
        assertEquals(test.nextTransition(b.getInstant()), c);
        assertEquals(test.nextTransition(c.getInstant().minusNanos(1)), c);
    }
}
Also used : ZoneOffsetTransitionRule(java.time.zone.ZoneOffsetTransitionRule) ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition)

Example 5 with ZoneRules

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

the class TCKZoneRules method test_Paris_getOffsetInfo_gap.

public void test_Paris_getOffsetInfo_gap() {
    ZoneRules test = europeParis();
    final LocalDateTime dateTime = LocalDateTime.of(2008, 3, 30, 2, 0, 0, 0);
    ZoneOffsetTransition trans = checkOffset(test, dateTime, OFFSET_PONE, GAP);
    assertEquals(trans.isGap(), true);
    assertEquals(trans.isOverlap(), false);
    assertEquals(trans.getOffsetBefore(), OFFSET_PONE);
    assertEquals(trans.getOffsetAfter(), OFFSET_PTWO);
    assertEquals(trans.getInstant(), createInstant(2008, 3, 30, 1, 0, ZoneOffset.UTC));
    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-30T02:00+01:00 to +02:00]");
    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)

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