Java Code Examples for java.time.chrono.JapaneseEra#values()

The following examples show how to use java.time.chrono.JapaneseEra#values() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TCKJapaneseChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_getDayOfYear() {
    // Test all the Eras
    for (JapaneseEra era : JapaneseEra.values()) {
        int firstYear = (era == JapaneseEra.MEIJI) ? 6 : 1;  // Until Era supports range(YEAR_OF_ERA)
        JapaneseDate hd1 = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, 1);
        ValueRange range = hd1.range(DAY_OF_YEAR);
        assertEquals(range.getMaximum(), hd1.lengthOfYear(), "lengthOfYear should match range.getMaximum()");

        for (int i = 1; i <= hd1.lengthOfYear(); i++) {
            JapaneseDate hd = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, i);
            int doy = hd.get(DAY_OF_YEAR);
            assertEquals(doy, i, "get(DAY_OF_YEAR) incorrect for " + i + ", of date: " + hd);
        }
    }
}
 
Example 2
Source File: TCKJapaneseChronology.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void test_getDayOfYear() {
    // Test all the Eras
    for (JapaneseEra era : JapaneseEra.values()) {
        int firstYear = (era == JapaneseEra.MEIJI) ? 6 : 1;  // Until Era supports range(YEAR_OF_ERA)
        JapaneseDate hd1 = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, 1);
        ValueRange range = hd1.range(DAY_OF_YEAR);
        assertEquals(range.getMaximum(), hd1.lengthOfYear(), "lengthOfYear should match range.getMaximum()");

        for (int i = 1; i <= hd1.lengthOfYear(); i++) {
            JapaneseDate hd = JapaneseChronology.INSTANCE.dateYearDay(era, firstYear, i);
            int doy = hd.get(DAY_OF_YEAR);
            assertEquals(doy, i, "get(DAY_OF_YEAR) incorrect for " + i + ", of date: " + hd);
        }
    }
}
 
Example 3
Source File: TestJapaneseChronoImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
@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);
        }
    }

}
 
Example 4
Source File: TestJapaneseChronoImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@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);
        }
    }

}
 
Example 5
Source File: TestJapaneseChronoImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@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);
        }
    }

}
 
Example 6
Source File: TCKEraSerialization.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 7
Source File: TCKJapaneseChronology.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_JapaneseEra_values() {
    JapaneseEra[] actualEras = JapaneseEra.values();
    Object[][] erasInfo = data_japanseseEras();
    assertEquals(actualEras.length, erasInfo.length, "Wrong number of Eras");

    for (int i = 0; i < erasInfo.length; i++) {
        Object[] eraInfo = erasInfo[i];
        assertEquals(actualEras[i], eraInfo[0], "Singleton mismatch");
    }
}
 
Example 8
Source File: TCKJapaneseEra.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_range() {
    // eras may be added after release
    for (JapaneseEra era : JapaneseEra.values()) {
        assertEquals(era.range(ERA).getMinimum(), -1);
        assertEquals(era.range(ERA).getLargestMinimum(), -1);
        assertEquals(era.range(ERA).getSmallestMaximum(), era.range(ERA).getMaximum());
        assertEquals(era.range(ERA).getMaximum() >= 2, true);
    }
}
 
Example 9
Source File: TCKJapaneseChronology.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_JapaneseEra_values() {
    JapaneseEra[] actualEras = JapaneseEra.values();
    Object[][] erasInfo = data_japanseseEras();
    assertEquals(actualEras.length, erasInfo.length, "Wrong number of Eras");

    for (int i = 0; i < erasInfo.length; i++) {
        Object[] eraInfo = erasInfo[i];
        assertEquals(actualEras[i], eraInfo[0], "Singleton mismatch");
    }
}
 
Example 10
Source File: TCKJapaneseEra.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_range() {
    // eras may be added after release
    for (JapaneseEra era : JapaneseEra.values()) {
        assertEquals(era.range(ERA).getMinimum(), -1);
        assertEquals(era.range(ERA).getLargestMinimum(), -1);
        assertEquals(era.range(ERA).getSmallestMaximum(), era.range(ERA).getMaximum());
        assertEquals(era.range(ERA).getMaximum() >= 2, true);
    }
}
 
Example 11
Source File: TCKJapaneseEra.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_range() {
    // eras may be added after release
    for (JapaneseEra era : JapaneseEra.values()) {
        assertEquals(era.range(ERA).getMinimum(), -1);
        assertEquals(era.range(ERA).getLargestMinimum(), -1);
        assertEquals(era.range(ERA).getSmallestMaximum(), era.range(ERA).getMaximum());
        assertEquals(era.range(ERA).getMaximum() >= 2, true);
    }
}
 
Example 12
Source File: TCKEraSerialization.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 13
Source File: TCKJapaneseChronology.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_JapaneseEra_values() {
    JapaneseEra[] actualEras = JapaneseEra.values();
    Object[][] erasInfo = data_japanseseEras();
    assertEquals(actualEras.length, erasInfo.length, "Wrong number of Eras");

    for (int i = 0; i < erasInfo.length; i++) {
        Object[] eraInfo = erasInfo[i];
        assertEquals(actualEras[i], eraInfo[0], "Singleton mismatch");
    }
}
 
Example 14
Source File: TCKEraSerialization.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 15
Source File: TCKJapaneseChronology.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "resolve_styleByEra")
Object[][] data_resolve_styleByEra() {
    Object[][] result = new Object[ResolverStyle.values().length * JapaneseEra.values().length][];
    int i = 0;
    for (ResolverStyle style : ResolverStyle.values()) {
        for (JapaneseEra era : JapaneseEra.values()) {
            result[i++] = new Object[] {style, era};
        }
    }
    return result;
}
 
Example 16
Source File: TCKJapaneseChronology.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@DataProvider(name = "resolve_styleByEra")
Object[][] data_resolve_styleByEra() {
    Object[][] result = new Object[ResolverStyle.values().length * JapaneseEra.values().length][];
    int i = 0;
    for (ResolverStyle style : ResolverStyle.values()) {
        for (JapaneseEra era : JapaneseEra.values()) {
            result[i++] = new Object[] {style, era};
        }
    }
    return result;
}
 
Example 17
Source File: TCKEraSerialization.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@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);
    }
}
 
Example 18
Source File: TCKJapaneseEra.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_range() {
    // eras may be added after release
    for (JapaneseEra era : JapaneseEra.values()) {
        assertEquals(era.range(ERA).getMinimum(), -1);
        assertEquals(era.range(ERA).getLargestMinimum(), -1);
        assertEquals(era.range(ERA).getSmallestMaximum(), era.range(ERA).getMaximum());
        assertEquals(era.range(ERA).getMaximum() >= 2, true);
    }
}
 
Example 19
Source File: TCKJapaneseEra.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_range() {
    // eras may be added after release
    for (JapaneseEra era : JapaneseEra.values()) {
        assertEquals(era.range(ERA).getMinimum(), -1);
        assertEquals(era.range(ERA).getLargestMinimum(), -1);
        assertEquals(era.range(ERA).getSmallestMaximum(), era.range(ERA).getMaximum());
        assertEquals(era.range(ERA).getMaximum() >= 2, true);
    }
}
 
Example 20
Source File: TCKJapaneseChronology.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void test_JapaneseEra_values() {
    JapaneseEra[] actualEras = JapaneseEra.values();
    Object[][] erasInfo = data_japanseseEras();
    assertEquals(actualEras.length, erasInfo.length, "Wrong number of Eras");

    for (int i = 0; i < erasInfo.length; i++) {
        Object[] eraInfo = erasInfo[i];
        assertEquals(actualEras[i], eraInfo[0], "Singleton mismatch");
    }
}