Search in sources :

Example 6 with JapaneseEra

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);
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JapaneseEra(java.time.chrono.JapaneseEra) Test(org.testng.annotations.Test) AbstractTCKTest(tck.java.time.AbstractTCKTest)

Example 7 with JapaneseEra

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);
        }
    }
}
Also used : Locale(java.util.Locale) OffsetDateTime(java.time.OffsetDateTime) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) JapaneseDate(java.time.chrono.JapaneseDate) JapaneseEra(java.time.chrono.JapaneseEra) Test(org.testng.annotations.Test)

Aggregations

JapaneseEra (java.time.chrono.JapaneseEra)7 Test (org.testng.annotations.Test)6 JapaneseDate (java.time.chrono.JapaneseDate)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 OffsetDateTime (java.time.OffsetDateTime)1 Era (java.time.chrono.Era)1 ResolverStyle (java.time.format.ResolverStyle)1 ValueRange (java.time.temporal.ValueRange)1 Calendar (java.util.Calendar)1 GregorianCalendar (java.util.GregorianCalendar)1 Locale (java.util.Locale)1 DataProvider (org.testng.annotations.DataProvider)1 AbstractTCKTest (tck.java.time.AbstractTCKTest)1