Search in sources :

Example 41 with ZoneRules

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

the class TCKZoneRules method test_London_getTransitionRules.

public void test_London_getTransitionRules() {
    ZoneRules test = europeLondon();
    List<ZoneOffsetTransitionRule> rules = test.getTransitionRules();
    assertEquals(rules.size(), 2);
    ZoneOffsetTransitionRule in = rules.get(0);
    assertEquals(in.getMonth(), Month.MARCH);
    // optimized from -1
    assertEquals(in.getDayOfMonthIndicator(), 25);
    assertEquals(in.getDayOfWeek(), DayOfWeek.SUNDAY);
    assertEquals(in.getLocalTime(), LocalTime.of(1, 0));
    assertEquals(in.getTimeDefinition(), TimeDefinition.UTC);
    assertEquals(in.getStandardOffset(), OFFSET_ZERO);
    assertEquals(in.getOffsetBefore(), OFFSET_ZERO);
    assertEquals(in.getOffsetAfter(), OFFSET_PONE);
    ZoneOffsetTransitionRule out = rules.get(1);
    assertEquals(out.getMonth(), Month.OCTOBER);
    // optimized from -1
    assertEquals(out.getDayOfMonthIndicator(), 25);
    assertEquals(out.getDayOfWeek(), DayOfWeek.SUNDAY);
    assertEquals(out.getLocalTime(), LocalTime.of(1, 0));
    assertEquals(out.getTimeDefinition(), TimeDefinition.UTC);
    assertEquals(out.getStandardOffset(), OFFSET_ZERO);
    assertEquals(out.getOffsetBefore(), OFFSET_PONE);
    assertEquals(out.getOffsetAfter(), OFFSET_ZERO);
}
Also used : ZoneOffsetTransitionRule(java.time.zone.ZoneOffsetTransitionRule) ZoneRules(java.time.zone.ZoneRules)

Example 42 with ZoneRules

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

the class TCKZoneRules method test_Paris_getOffsetInfo_fromDST.

public void test_Paris_getOffsetInfo_fromDST() {
    ZoneRules test = europeParis();
    checkOffset(test, createLDT(2008, 10, 24), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 10, 25), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 10, 26), OFFSET_PTWO, 1);
    checkOffset(test, createLDT(2008, 10, 27), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 28), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 29), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 30), OFFSET_PONE, 1);
    checkOffset(test, createLDT(2008, 10, 31), OFFSET_PONE, 1);
    // cutover at 01:00Z which is 02:00+01:00(local Paris time)
    checkOffset(test, LocalDateTime.of(2008, 10, 26, 1, 59, 59, 999999999), OFFSET_PTWO, 1);
    checkOffset(test, LocalDateTime.of(2008, 10, 26, 3, 0, 0, 0), OFFSET_PONE, 1);
}
Also used : ZoneRules(java.time.zone.ZoneRules)

Example 43 with ZoneRules

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

the class TCKZoneRules method test_equals.

//-----------------------------------------------------------------------
// equals() / hashCode()
//-----------------------------------------------------------------------
public void test_equals() {
    ZoneRules test1 = europeLondon();
    ZoneRules test2 = europeParis();
    ZoneRules test2b = europeParis();
    assertEquals(test1.equals(test2), false);
    assertEquals(test2.equals(test1), false);
    assertEquals(test1.equals(test1), true);
    assertEquals(test2.equals(test2), true);
    assertEquals(test2.equals(test2b), true);
    assertEquals(test1.hashCode() == test1.hashCode(), true);
    assertEquals(test2.hashCode() == test2.hashCode(), true);
    assertEquals(test2.hashCode() == test2b.hashCode(), true);
}
Also used : ZoneRules(java.time.zone.ZoneRules)

Example 44 with ZoneRules

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

the class TCKZoneRules method test_of.

//-----------------------------------------------------------------------
// of()
//-----------------------------------------------------------------------
public void test_of() {
    //used for standard offset
    ZoneOffset stdOffset1 = ZoneOffset.UTC;
    ZoneOffset stdOffset2 = ZoneOffset.ofHours(1);
    LocalDateTime time_of_stdOffsetTransition1 = LocalDateTime.of(2013, 1, 5, 1, 0);
    ZoneOffsetTransition stdOffsetTransition1 = ZoneOffsetTransition.of(time_of_stdOffsetTransition1, stdOffset1, stdOffset2);
    List<ZoneOffsetTransition> stdOffsetTransition_list = new ArrayList<ZoneOffsetTransition>();
    stdOffsetTransition_list.add(stdOffsetTransition1);
    //used for wall offset
    ZoneOffset wallOffset1 = ZoneOffset.ofHours(2);
    ZoneOffset wallOffset2 = ZoneOffset.ofHours(4);
    ZoneOffset wallOffset3 = ZoneOffset.ofHours(7);
    LocalDateTime time_of_wallOffsetTransition1 = LocalDateTime.of(2013, 2, 5, 1, 0);
    LocalDateTime time_of_wallOffsetTransition2 = LocalDateTime.of(2013, 3, 5, 1, 0);
    LocalDateTime time_of_wallOffsetTransition3 = LocalDateTime.of(2013, 10, 5, 1, 0);
    ZoneOffsetTransition wallOffsetTransition1 = ZoneOffsetTransition.of(time_of_wallOffsetTransition1, wallOffset1, wallOffset2);
    ZoneOffsetTransition wallOffsetTransition2 = ZoneOffsetTransition.of(time_of_wallOffsetTransition2, wallOffset2, wallOffset3);
    ZoneOffsetTransition wallOffsetTransition3 = ZoneOffsetTransition.of(time_of_wallOffsetTransition3, wallOffset3, wallOffset1);
    List<ZoneOffsetTransition> wallOffsetTransition_list = new ArrayList<ZoneOffsetTransition>();
    wallOffsetTransition_list.add(wallOffsetTransition1);
    wallOffsetTransition_list.add(wallOffsetTransition2);
    wallOffsetTransition_list.add(wallOffsetTransition3);
    //used for ZoneOffsetTransitionRule
    ZoneOffset ruleOffset = ZoneOffset.ofHours(3);
    ZoneOffsetTransitionRule.TimeDefinition timeDefinition = ZoneOffsetTransitionRule.TimeDefinition.valueOf("WALL");
    ZoneOffsetTransitionRule rule1 = ZoneOffsetTransitionRule.of(Month.FEBRUARY, 2, DayOfWeek.MONDAY, LocalTime.of(1, 0), false, timeDefinition, ZoneOffset.UTC, ZoneOffset.UTC, ruleOffset);
    List<ZoneOffsetTransitionRule> rule_list = new ArrayList<ZoneOffsetTransitionRule>();
    rule_list.add(rule1);
    //Begin verification
    ZoneRules zoneRule = ZoneRules.of(stdOffset1, wallOffset1, stdOffsetTransition_list, wallOffsetTransition_list, rule_list);
    OffsetDateTime before_time_of_stdOffsetTransition1 = OffsetDateTime.of(time_of_stdOffsetTransition1, stdOffset1).minusSeconds(1);
    OffsetDateTime after_time_of_stdOffsetTransition1 = OffsetDateTime.of(time_of_stdOffsetTransition1, stdOffset1).plusSeconds(1);
    ;
    assertEquals(zoneRule.getStandardOffset(before_time_of_stdOffsetTransition1.toInstant()), stdOffset1);
    assertEquals(zoneRule.getStandardOffset(after_time_of_stdOffsetTransition1.toInstant()), stdOffset2);
    OffsetDateTime before_time_of_wallOffsetTransition1 = OffsetDateTime.of(time_of_wallOffsetTransition1, wallOffset1).minusSeconds(1);
    OffsetDateTime after_time_of_wallOffsetTransition1 = OffsetDateTime.of(time_of_wallOffsetTransition1, wallOffset1).plusSeconds(1);
    assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition1.toInstant()), wallOffsetTransition1);
    assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition1.toInstant()), wallOffsetTransition2);
    OffsetDateTime before_time_of_wallOffsetTransition2 = OffsetDateTime.of(time_of_wallOffsetTransition2, wallOffset2).minusSeconds(1);
    OffsetDateTime after_time_of_wallOffsetTransition2 = OffsetDateTime.of(time_of_wallOffsetTransition2, wallOffset2).plusSeconds(1);
    assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition2.toInstant()), wallOffsetTransition2);
    assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition2.toInstant()), wallOffsetTransition3);
    OffsetDateTime before_time_of_wallOffsetTransition3 = OffsetDateTime.of(time_of_wallOffsetTransition3, wallOffset3).minusSeconds(1);
    OffsetDateTime after_time_of_wallOffsetTransition3 = OffsetDateTime.of(time_of_wallOffsetTransition3, wallOffset3).plusSeconds(1);
    assertEquals(zoneRule.nextTransition(before_time_of_wallOffsetTransition3.toInstant()), wallOffsetTransition3);
    assertEquals(zoneRule.nextTransition(after_time_of_wallOffsetTransition3.toInstant()), rule1.createTransition(2014));
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneOffsetTransitionRule(java.time.zone.ZoneOffsetTransitionRule) OffsetDateTime(java.time.OffsetDateTime) ArrayList(java.util.ArrayList) ZoneRules(java.time.zone.ZoneRules) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition) TimeDefinition(java.time.zone.ZoneOffsetTransitionRule.TimeDefinition) ZoneOffset(java.time.ZoneOffset)

Example 45 with ZoneRules

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

the class TCKZoneRules method test_NewYork_getStandardOffset.

public void test_NewYork_getStandardOffset() {
    ZoneRules test = americaNewYork();
    ZonedDateTime dateTime = createZDT(1860, 1, 1, ZoneOffset.UTC);
    while (dateTime.getYear() < 2010) {
        Instant instant = dateTime.toInstant();
        if (dateTime.toLocalDate().isBefore(LocalDate.of(1883, 11, 18))) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.of("-04:56:02"));
        } else {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHours(-5));
        }
        dateTime = dateTime.plusMonths(6);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules)

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