use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method now_Clock_allSecsInDay_zone.
@Test
public void now_Clock_allSecsInDay_zone() {
ZoneId zone = ZoneId.of("Europe/London");
for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
ZonedDateTime expected = ZonedDateTime.ofInstant(instant, zone);
Clock clock = Clock.fixed(expected.toInstant(), zone);
ZonedDateTime test = ZonedDateTime.now(clock);
assertEquals(test, expected);
}
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method now_ZoneId.
@Test
public void now_ZoneId() {
ZoneId zone = ZoneId.of("UTC+01:02:03");
ZonedDateTime expected = ZonedDateTime.now(Clock.system(zone));
ZonedDateTime test = ZonedDateTime.now(zone);
for (int i = 0; i < 100; i++) {
if (expected.equals(test)) {
return;
}
expected = ZonedDateTime.now(Clock.system(zone));
test = ZonedDateTime.now(zone);
}
assertEquals(test, expected);
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZoneId method test_invalidPrefixOfOffset.
@Test(dataProvider = "prefixInvalid", expectedExceptions = java.lang.IllegalArgumentException.class)
public void test_invalidPrefixOfOffset(String prefix, String offset) {
ZoneOffset zoff = ZoneOffset.of(offset);
ZoneId zoneId = ZoneId.ofOffset(prefix, zoff);
fail("should have thrown an exception for prefix: " + prefix);
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZoneId method test_of_string_Map.
//-----------------------------------------------------------------------
// mapped factory
//-----------------------------------------------------------------------
@Test
public void test_of_string_Map() {
Map<String, String> map = new HashMap<>();
map.put("LONDON", "Europe/London");
map.put("PARIS", "Europe/Paris");
ZoneId test = ZoneId.of("LONDON", map);
assertEquals(test.getId(), "Europe/London");
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZoneId method factory_of_String_offsetBasedValid_prefixUTC.
@Test(dataProvider = "offsetBasedValidPrefix")
public void factory_of_String_offsetBasedValid_prefixUTC(String input, String id, String offsetId) {
ZoneId test = ZoneId.of("UTC" + input);
assertEquals(test.getId(), "UTC" + id);
assertEquals(test.getRules(), ZoneOffset.of(offsetId).getRules());
assertEquals(test.normalized(), ZoneOffset.of(offsetId));
assertEquals(test.getDisplayName(TextStyle.FULL, Locale.UK), displayName("UTC" + id));
assertEquals(test.getRules().isFixedOffset(), true);
assertEquals(test.getRules().getOffset(Instant.EPOCH), ZoneOffset.of(offsetId));
}
Aggregations