use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZoneIdSerialization method test_deserialization_lenient_characters.
@Test
public void test_deserialization_lenient_characters() throws Exception {
// an ID can be loaded without validation during deserialization
String id = "QWERTYUIOPASDFGHJKLZXCVBNM~/._+-";
ZoneId deser = deserialize(id);
// getId, equals, hashCode, toString and normalized are OK
assertEquals(deser.getId(), id);
assertEquals(deser.toString(), id);
assertEquals(deser, deser);
assertEquals(deser.hashCode(), deser.hashCode());
assertEquals(deser.normalized(), deser);
// getting the rules is not
try {
deser.getRules();
fail();
} catch (ZoneRulesException ex) {
// expected
}
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZoneIdSerialization method deserialize.
private ZoneId deserialize(String id) throws Exception {
String serClass = ZoneId.class.getPackage().getName() + ".Ser";
Class<?> serCls = Class.forName(serClass);
Field field = serCls.getDeclaredField("serialVersionUID");
field.setAccessible(true);
long serVer = (Long) field.get(null);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DataOutputStream dos = new DataOutputStream(baos)) {
dos.writeShort(ObjectStreamConstants.STREAM_MAGIC);
dos.writeShort(ObjectStreamConstants.STREAM_VERSION);
dos.writeByte(ObjectStreamConstants.TC_OBJECT);
dos.writeByte(ObjectStreamConstants.TC_CLASSDESC);
dos.writeUTF(serClass);
dos.writeLong(serVer);
dos.writeByte(ObjectStreamConstants.SC_EXTERNALIZABLE | ObjectStreamConstants.SC_BLOCK_DATA);
// number of fields
dos.writeShort(0);
// end of classdesc
dos.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
// no superclasses
dos.writeByte(ObjectStreamConstants.TC_NULL);
dos.writeByte(ObjectStreamConstants.TC_BLOCKDATA);
// length of data (1 byte + 2 bytes UTF length + 32 bytes UTF)
dos.writeByte(1 + 2 + id.length());
// ZoneId
dos.writeByte(7);
dos.writeUTF(id);
// end of blockdata
dos.writeByte(ObjectStreamConstants.TC_ENDBLOCKDATA);
}
ZoneId deser = null;
try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()))) {
deser = (ZoneId) ois.readObject();
}
return deser;
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TCKZoneIdPrinterParser method test_parseSuccess_caseInsensitive.
@Test(dataProvider = "parseSuccess")
public void test_parseSuccess_caseInsensitive(String text, int expectedIndex, int expectedErrorIndex, ZoneId expected) {
builder.parseCaseInsensitive().appendZoneId();
String lcText = text.toLowerCase(Locale.ENGLISH);
TemporalAccessor parsed = builder.toFormatter().parseUnresolved(lcText, pos);
assertEquals(pos.getErrorIndex(), expectedErrorIndex, "Incorrect error index parsing: " + lcText);
assertEquals(pos.getIndex(), expectedIndex, "Incorrect index parsing: " + lcText);
if (expected != null) {
ZoneId zid = parsed.query(TemporalQueries.zoneId());
assertEquals(parsed.query(TemporalQueries.zoneId()), expected, "Incorrect zoneId parsing: " + lcText);
assertEquals(parsed.query(TemporalQueries.offset()), null, "Incorrect offset parsing: " + lcText);
assertEquals(parsed.query(TemporalQueries.zone()), expected, "Incorrect zone parsing: " + lcText);
} else {
assertEquals(parsed, null);
}
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TestZoneId method test_NewYork.
//-----------------------------------------------------------------------
// America/New_York
//-----------------------------------------------------------------------
public void test_NewYork() {
ZoneId test = ZoneId.of("America/New_York");
assertEquals(test.getId(), "America/New_York");
assertEquals(test.getRules().isFixedOffset(), false);
}
use of java.time.ZoneId in project jdk8u_jdk by JetBrains.
the class TestZoneId method test_London_getOffset_toDST.
public void test_London_getOffset_toDST() {
ZoneId test = ZoneId.of("Europe/London");
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 24, ZoneOffset.UTC)), ZoneOffset.ofHours(0));
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 25, ZoneOffset.UTC)), ZoneOffset.ofHours(0));
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 26, ZoneOffset.UTC)), ZoneOffset.ofHours(0));
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 27, ZoneOffset.UTC)), ZoneOffset.ofHours(0));
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 28, ZoneOffset.UTC)), ZoneOffset.ofHours(0));
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 29, ZoneOffset.UTC)), ZoneOffset.ofHours(0));
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 30, ZoneOffset.UTC)), ZoneOffset.ofHours(0));
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 31, ZoneOffset.UTC)), ZoneOffset.ofHours(1));
// cutover at 01:00Z
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 30, 0, 59, 59, 999999999, ZoneOffset.UTC)), ZoneOffset.ofHours(0));
assertEquals(test.getRules().getOffset(createInstant(2008, 3, 30, 1, 0, 0, 0, ZoneOffset.UTC)), ZoneOffset.ofHours(1));
}
Aggregations