Search in sources :

Example 31 with ZoneOffset

use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_London_preTimeZones.

public void test_London_preTimeZones() {
    ZoneRules test = europeLondon();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, -1, -15);
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules) ZoneOffset(java.time.ZoneOffset)

Example 32 with ZoneOffset

use of java.time.ZoneOffset 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 33 with ZoneOffset

use of java.time.ZoneOffset 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 34 with ZoneOffset

use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_Paris_preTimeZones.

public void test_Paris_preTimeZones() {
    ZoneRules test = europeParis();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(0, 9, 21);
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules) ZoneOffset(java.time.ZoneOffset)

Example 35 with ZoneOffset

use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.

the class TCKZoneRules method test_NewYork_preTimeZones.

public void test_NewYork_preTimeZones() {
    ZoneRules test = americaNewYork();
    ZonedDateTime old = createZDT(1800, 1, 1, ZoneOffset.UTC);
    Instant instant = old.toInstant();
    ZoneOffset offset = ZoneOffset.of("-04:56:02");
    assertEquals(test.getOffset(instant), offset);
    checkOffset(test, old.toLocalDateTime(), offset, 1);
    assertEquals(test.getStandardOffset(instant), offset);
    assertEquals(test.getDaylightSavings(instant), Duration.ZERO);
    assertEquals(test.isDaylightSavings(instant), false);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules) ZoneOffset(java.time.ZoneOffset)

Aggregations

ZoneOffset (java.time.ZoneOffset)64 Test (org.testng.annotations.Test)35 LocalDateTime (java.time.LocalDateTime)10 ZoneId (java.time.ZoneId)10 ZoneRules (java.time.zone.ZoneRules)9 ZonedDateTime (java.time.ZonedDateTime)8 Instant (java.time.Instant)6 OffsetDateTime (java.time.OffsetDateTime)5 DateTimeFormatter (java.time.format.DateTimeFormatter)5 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)4 Clock (java.time.Clock)3 LocalTime (java.time.LocalTime)3 Duration (java.time.Duration)2 LocalDate (java.time.LocalDate)2 OffsetTime (java.time.OffsetTime)2 ChronoField (java.time.temporal.ChronoField)2 TemporalAccessor (java.time.temporal.TemporalAccessor)2 List (java.util.List)2 Cache (com.github.benmanes.caffeine.cache.Cache)1 Caffeine (com.github.benmanes.caffeine.cache.Caffeine)1