Search in sources :

Example 11 with ZoneOffsetTransition

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

the class TCKZoneOffsetTransitionRule method test_createTransition_floatingWeek_overlap_endOfDay.

@Test
public void test_createTransition_floatingWeek_overlap_endOfDay() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(Month.MARCH, 20, DayOfWeek.SUNDAY, LocalTime.MIDNIGHT, true, TimeDefinition.WALL, OFFSET_0200, OFFSET_0300, OFFSET_0200);
    ZoneOffsetTransition trans = ZoneOffsetTransition.of(LocalDateTime.of(2000, Month.MARCH, 27, 0, 0), OFFSET_0300, OFFSET_0200);
    assertEquals(test.createTransition(2000), trans);
}
Also used : ZoneOffsetTransitionRule(java.time.zone.ZoneOffsetTransitionRule) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 12 with ZoneOffsetTransition

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

the class TCKZoneOffsetTransitionRule method test_createTransition_floatingWeekBackwards_secondLast.

@Test
public void test_createTransition_floatingWeekBackwards_secondLast() {
    ZoneOffsetTransitionRule test = ZoneOffsetTransitionRule.of(Month.MARCH, -2, DayOfWeek.SUNDAY, TIME_0100, false, TimeDefinition.WALL, OFFSET_0200, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransition trans = ZoneOffsetTransition.of(LocalDateTime.of(2000, Month.MARCH, 26, 1, 0), OFFSET_0200, OFFSET_0300);
    assertEquals(test.createTransition(2000), trans);
}
Also used : ZoneOffsetTransitionRule(java.time.zone.ZoneOffsetTransitionRule) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 13 with ZoneOffsetTransition

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

the class TCKZoneRules method test_Kathmandu_nextTransition_historic.

public void test_Kathmandu_nextTransition_historic() {
    ZoneRules test = asiaKathmandu();
    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 14 with ZoneOffsetTransition

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

the class TCKZoneOffsetTransition method test_hashCode_floatingWeek_gap_notEndOfDay.

//-----------------------------------------------------------------------
// hashCode()
//-----------------------------------------------------------------------
@Test
public void test_hashCode_floatingWeek_gap_notEndOfDay() {
    LocalDateTime ldtA = LocalDateTime.of(2010, 3, 31, 1, 0);
    ZoneOffsetTransition a1 = ZoneOffsetTransition.of(ldtA, OFFSET_0200, OFFSET_0300);
    ZoneOffsetTransition a2 = ZoneOffsetTransition.of(ldtA, OFFSET_0200, OFFSET_0300);
    LocalDateTime ldtB = LocalDateTime.of(2010, 10, 31, 1, 0);
    ZoneOffsetTransition b = ZoneOffsetTransition.of(ldtB, OFFSET_0300, OFFSET_0200);
    assertEquals(a1.hashCode(), a1.hashCode());
    assertEquals(a1.hashCode(), a2.hashCode());
    assertEquals(b.hashCode(), b.hashCode());
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneOffsetTransition(java.time.zone.ZoneOffsetTransition) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 15 with ZoneOffsetTransition

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

the class ZonedDateTime method ofStrict.

//-----------------------------------------------------------------------
/**
     * Obtains an instance of {@code ZonedDateTime} strictly validating the
     * combination of local date-time, offset and zone ID.
     * <p>
     * This creates a zoned date-time ensuring that the offset is valid for the
     * local date-time according to the rules of the specified zone.
     * If the offset is invalid, an exception is thrown.
     *
     * @param localDateTime  the local date-time, not null
     * @param offset  the zone offset, not null
     * @param zone  the time-zone, not null
     * @return the zoned date-time, not null
     */
public static ZonedDateTime ofStrict(LocalDateTime localDateTime, ZoneOffset offset, ZoneId zone) {
    Objects.requireNonNull(localDateTime, "localDateTime");
    Objects.requireNonNull(offset, "offset");
    Objects.requireNonNull(zone, "zone");
    ZoneRules rules = zone.getRules();
    if (rules.isValidOffset(localDateTime, offset) == false) {
        ZoneOffsetTransition trans = rules.getTransition(localDateTime);
        if (trans != null && trans.isGap()) {
            // even though there are other kinds of gaps
            throw new DateTimeException("LocalDateTime '" + localDateTime + "' does not exist in zone '" + zone + "' due to a gap in the local time-line, typically caused by daylight savings");
        }
        throw new DateTimeException("ZoneOffset '" + offset + "' is not valid for LocalDateTime '" + localDateTime + "' in zone '" + zone + "'");
    }
    return new ZonedDateTime(localDateTime, offset, zone);
}
Also used : ChronoZonedDateTime(java.time.chrono.ChronoZonedDateTime) 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