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);
}
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);
}
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);
}
}
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());
}
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);
}
Aggregations