use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZoneId method factory_of_String_offsetBasedValid_noPrefix.
@Test(dataProvider = "offsetBasedValid")
public void factory_of_String_offsetBasedValid_noPrefix(String input, String id) {
ZoneId test = ZoneId.of(input);
assertEquals(test.getId(), id);
assertEquals(test, ZoneOffset.of(id));
assertEquals(test.normalized(), ZoneOffset.of(id));
assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), id);
assertEquals(test.getRules().isFixedOffset(), true);
assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(id));
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZoneId method test_equals.
//-----------------------------------------------------------------------
// equals() / hashCode()
//-----------------------------------------------------------------------
@Test
public void test_equals() {
ZoneId test1 = ZoneId.of("Europe/London");
ZoneId test2 = ZoneId.of("Europe/Paris");
ZoneId test2b = ZoneId.of("Europe/Paris");
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);
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method test_with_adjuster_LocalDate_retainOffset1.
@Test
public void test_with_adjuster_LocalDate_retainOffset1() {
ZoneId newYork = ZoneId.of("America/New_York");
LocalDateTime ldt = LocalDateTime.of(2008, 11, 1, 1, 30);
ZonedDateTime base = ZonedDateTime.of(ldt, newYork);
assertEquals(base.getOffset(), ZoneOffset.ofHours(-4));
ZonedDateTime test = base.with(LocalDate.of(2008, 11, 2));
assertEquals(test.getOffset(), ZoneOffset.ofHours(-4));
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TestZoneId method test_NewYork_getOffset_fromDST.
public void test_NewYork_getOffset_fromDST() {
ZoneId test = ZoneId.of("America/New_York");
ZoneOffset offset = ZoneOffset.ofHours(-4);
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 1, offset)), ZoneOffset.ofHours(-4));
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 2, offset)), ZoneOffset.ofHours(-4));
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 3, offset)), ZoneOffset.ofHours(-5));
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 4, offset)), ZoneOffset.ofHours(-5));
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 5, offset)), ZoneOffset.ofHours(-5));
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 6, offset)), ZoneOffset.ofHours(-5));
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 7, offset)), ZoneOffset.ofHours(-5));
// cutover at 02:00 local
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 2, 1, 59, 59, 999999999, offset)), ZoneOffset.ofHours(-4));
assertEquals(test.getRules().getOffset(createInstant(2008, 11, 2, 2, 0, 0, 0, offset)), ZoneOffset.ofHours(-5));
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TestZoneId method test_London_getOffsetInfo_overlap.
public void test_London_getOffsetInfo_overlap() {
ZoneId test = ZoneId.of("Europe/London");
final LocalDateTime dateTime = LocalDateTime.of(2008, 10, 26, 1, 0, 0, 0);
ZoneOffsetTransition trans = checkOffset(test.getRules(), dateTime, ZoneOffset.ofHours(1), OVERLAP);
assertEquals(trans.isGap(), false);
assertEquals(trans.isOverlap(), true);
assertEquals(trans.getOffsetBefore(), ZoneOffset.ofHours(1));
assertEquals(trans.getOffsetAfter(), ZoneOffset.ofHours(0));
assertEquals(trans.getInstant(), dateTime.toInstant(ZoneOffset.UTC));
assertEquals(trans.getDateTimeBefore(), LocalDateTime.of(2008, 10, 26, 2, 0));
assertEquals(trans.getDateTimeAfter(), LocalDateTime.of(2008, 10, 26, 1, 0));
assertEquals(trans.isValidOffset(ZoneOffset.ofHours(-1)), false);
assertEquals(trans.isValidOffset(ZoneOffset.ofHours(0)), true);
assertEquals(trans.isValidOffset(ZoneOffset.ofHours(1)), true);
assertEquals(trans.isValidOffset(ZoneOffset.ofHours(2)), false);
assertEquals(trans.toString(), "Transition[Overlap at 2008-10-26T02:00+01:00 to Z]");
assertFalse(trans.equals(null));
assertFalse(trans.equals(ZoneOffset.ofHours(1)));
assertTrue(trans.equals(trans));
final ZoneOffsetTransition otherTrans = test.getRules().getTransition(dateTime);
assertTrue(trans.equals(otherTrans));
assertEquals(trans.hashCode(), otherTrans.hashCode());
}
Aggregations