use of java.time.chrono.JapaneseEra in project jdk8u_jdk by JetBrains.
the class TCKEraSerialization method test_JapaneseErasSerialization.
//-----------------------------------------------------------------------
// Test JapaneseEra serialization produces exact sequence of bytes
//-----------------------------------------------------------------------
@Test
private void test_JapaneseErasSerialization() throws Exception {
for (JapaneseEra era : JapaneseEra.values()) {
assertSerializableSame(era);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try (DataOutputStream dos = new DataOutputStream(baos)) {
dos.writeByte(JAPANESE_ERA_TYPE);
dos.writeByte(era.getValue());
}
byte[] bytes = baos.toByteArray();
assertSerializedBySer(era, bytes);
}
}
use of java.time.chrono.JapaneseEra in project jdk8u_jdk by JetBrains.
the class TestJapaneseChronoImpl method test_dayOfYearVsCalendar.
//-----------------------------------------------------------------------
// Verify Japanese Calendar matches java.util.Calendar for number of days
// in years 1 and 2.
//-----------------------------------------------------------------------
@Test
public void test_dayOfYearVsCalendar() {
Locale locale = Locale.forLanguageTag("ja-JP-u-ca-japanese");
Calendar cal = java.util.Calendar.getInstance(locale);
for (JapaneseEra era : JapaneseEra.values()) {
for (int year : new int[] { 6, 7 }) {
JapaneseDate jd = JapaneseChronology.INSTANCE.dateYearDay(era, year, 1);
OffsetDateTime jodt = OffsetDateTime.of(LocalDate.from(jd), LocalTime.MIN, ZoneOffset.UTC);
long millis = jodt.toInstant().toEpochMilli();
cal.setTimeZone(TimeZone.getTimeZone("GMT+00"));
cal.setTimeInMillis(millis);
assertEquals(jd.get(ChronoField.DAY_OF_YEAR), cal.get(Calendar.DAY_OF_YEAR), "different DAY_OF_YEAR values in " + era + ", year: " + year);
assertEquals(jd.range(ChronoField.DAY_OF_YEAR).getMaximum(), cal.getActualMaximum(Calendar.DAY_OF_YEAR), "different maximum for DAY_OF_YEAR in " + era + ", year: " + year);
assertEquals(jd.range(ChronoField.DAY_OF_YEAR).getMinimum(), cal.getActualMinimum(Calendar.DAY_OF_YEAR), "different minimum for DAY_OF_YEAR in " + era + ", year: " + year);
}
}
}
Aggregations