Java 类java.time.chrono.JapaneseChronology 实例源码

项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@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);
        }
    }
}
项目:openjdk-jdk10    文件:TestReducedParser.java   
@DataProvider(name="ReducedWithChrono")
Object[][] provider_reducedWithChrono() {
    LocalDate baseYear = LocalDate.of(2000, 1, 1);
    return new Object[][] {
        {IsoChronology.INSTANCE.date(baseYear)},
        {IsoChronology.INSTANCE.date(baseYear).plus(1, YEARS)},
        {IsoChronology.INSTANCE.date(baseYear).plus(99, YEARS)},
        {HijrahChronology.INSTANCE.date(baseYear)},
        {HijrahChronology.INSTANCE.date(baseYear).plus(1, YEARS)},
        {HijrahChronology.INSTANCE.date(baseYear).plus(99, YEARS)},
        {JapaneseChronology.INSTANCE.date(baseYear)},
        {JapaneseChronology.INSTANCE.date(baseYear).plus(1, YEARS)},
        {JapaneseChronology.INSTANCE.date(baseYear).plus(99, YEARS)},
        {MinguoChronology.INSTANCE.date(baseYear)},
        {MinguoChronology.INSTANCE.date(baseYear).plus(1, YEARS)},
        {MinguoChronology.INSTANCE.date(baseYear).plus(99, YEARS)},
        {ThaiBuddhistChronology.INSTANCE.date(baseYear)},
        {ThaiBuddhistChronology.INSTANCE.date(baseYear).plus(1, YEARS)},
        {ThaiBuddhistChronology.INSTANCE.date(baseYear).plus(99, YEARS)},
    };
}
项目:jdk8u-jdk    文件:TestJapaneseChronoImpl.java   
@Test(dataProvider="RangeVersusCalendar")
public void test_JapaneseChrono_vsCalendar(LocalDate isoStartDate, LocalDate isoEndDate) {
    Locale locale = Locale.forLanguageTag("ja-JP-u-ca-japanese");
    assertEquals(locale.toString(), "ja_JP_#u-ca-japanese", "Unexpected locale");

    Calendar cal = java.util.Calendar.getInstance(locale);
    assertEquals(cal.getCalendarType(), "japanese", "Unexpected calendar type");

    JapaneseDate jDate = JapaneseChronology.INSTANCE.date(isoStartDate);

    // Convert to millis and set Japanese Calendar to that start date (at GMT)
    OffsetDateTime jodt = OffsetDateTime.of(isoStartDate, LocalTime.MIN, ZoneOffset.UTC);
    long millis = jodt.toInstant().toEpochMilli();
    cal.setTimeZone(TimeZone.getTimeZone("GMT+00"));
    cal.setTimeInMillis(millis);

    while (jDate.isBefore(isoEndDate)) {
        assertEquals(jDate.get(ChronoField.DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH), "Day mismatch in " + jDate + ";  cal: " + cal);
        assertEquals(jDate.get(ChronoField.MONTH_OF_YEAR), cal.get(Calendar.MONTH) + 1, "Month mismatch in " + jDate);
        assertEquals(jDate.get(ChronoField.YEAR_OF_ERA), cal.get(Calendar.YEAR), "Year mismatch in " + jDate);

        jDate = jDate.plus(1, ChronoUnit.DAYS);
        cal.add(Calendar.DAY_OF_MONTH, 1);
    }
}
项目:OpenJSharp    文件:DateTimeTextProvider.java   
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
项目:jdk8u-jdk    文件:DateTimeTextProvider.java   
/**
 * Gets the text for the specified chrono, field, locale and style
 * for the purpose of formatting.
 * <p>
 * The text associated with the value is returned.
 * The null return value should be used if there is no applicable text, or
 * if the text would be a numeric representation of the value.
 *
 * @param chrono  the Chronology to get text for, not null
 * @param field  the field to get text for, not null
 * @param value  the field value to get text for, not null
 * @param style  the style to get text for, not null
 * @param locale  the locale to get text for, not null
 * @return the text for the field value, null if no text found
 */
public String getText(Chronology chrono, TemporalField field, long value,
                                TextStyle style, Locale locale) {
    if (chrono == IsoChronology.INSTANCE
            || !(field instanceof ChronoField)) {
        return getText(field, value, style, locale);
    }

    int fieldIndex;
    int fieldValue;
    if (field == ERA) {
        fieldIndex = Calendar.ERA;
        if (chrono == JapaneseChronology.INSTANCE) {
            if (value == -999) {
                fieldValue = 0;
            } else {
                fieldValue = (int) value + 2;
            }
        } else {
            fieldValue = (int) value;
        }
    } else if (field == MONTH_OF_YEAR) {
        fieldIndex = Calendar.MONTH;
        fieldValue = (int) value - 1;
    } else if (field == DAY_OF_WEEK) {
        fieldIndex = Calendar.DAY_OF_WEEK;
        fieldValue = (int) value + 1;
        if (fieldValue > 7) {
            fieldValue = Calendar.SUNDAY;
        }
    } else if (field == AMPM_OF_DAY) {
        fieldIndex = Calendar.AM_PM;
        fieldValue = (int) value;
    } else {
        return null;
    }
    return CalendarDataUtility.retrieveJavaTimeFieldValueName(
            chrono.getCalendarType(), fieldIndex, fieldValue, style.toCalendarStyle(), locale);
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@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);
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test
public void test_dateNow(){
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now()) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(ZoneId.systemDefault())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone().getZone())) ;

    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;

    ZoneId zoneId = ZoneId.of("Europe/Paris");
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId))) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId).getZone())) ;

    assertEquals(JapaneseChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), JapaneseChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test
public void test_with_TemporalField_long() {
    JapaneseDate base = JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 63, 6, 30);
    JapaneseDate test = base.with(YEAR, 1987);
    assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 62, 6, 30));

    test = test.with(YEAR_OF_ERA, 2);
    assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 2, 6, 30));

    test = test.with(ERA, JapaneseEra.HEISEI.getValue());
    assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 6, 30));

    test = test.with(MONTH_OF_YEAR, 3);
    assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 30));

    test = test.with(DAY_OF_MONTH, 4);
    assertEquals(test, JapaneseChronology.INSTANCE.date(JapaneseEra.HEISEI, 2, 3, 4));
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_strict(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (strict) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_yd")
public void test_resolve_yd_smart(int y, int d, JapaneseDate expected, boolean smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.DAY_OF_YEAR, (long) d);
    if (smart) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_eymd")
public void test_resolve_eymd(ResolverStyle style, JapaneseEra era, int yoe, int m, int d, JapaneseDate expected) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.ERA, (long) era.getValue());
    fieldValues.put(ChronoField.YEAR_OF_ERA, (long) yoe);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (expected != null) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TestJapaneseChronoImpl.java   
@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);
        }
    }

}
项目:jdk8u-jdk    文件:TestJapaneseChronoImpl.java   
@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);
        }
    }

}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_strict(int y, int m, int d, JapaneseDate expected, Object smart, boolean strict) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR, (long) y);
    fieldValues.put(ChronoField.MONTH_OF_YEAR, (long) m);
    fieldValues.put(ChronoField.DAY_OF_MONTH, (long) d);
    if (strict) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.STRICT);
            fail("Should have failed");
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:openjdk-jdk10    文件:TCKChronology.java   
@DataProvider(name = "epochSecond_dataProvider")
Object[][]  data_epochSecond() {
    return new Object[][] {
            {JapaneseChronology.INSTANCE, 1873, 9, 7, 1, 2, 2, OFFSET_P0100},
            {JapaneseChronology.INSTANCE, 1928, 2, 28, 1, 2, 2, OFFSET_M0100},
            {JapaneseChronology.INSTANCE, 1989, 1, 8, 1, 2, 2, OFFSET_P0100},
            {HijrahChronology.INSTANCE, 1434, 9, 7, 1, 2, 2, OFFSET_P0100},
            {MinguoChronology.INSTANCE, 1873, 9, 7, 1, 2, 2, OFFSET_P0100},
            {MinguoChronology.INSTANCE, 1928, 2, 28, 1, 2, 2, OFFSET_M0100},
            {MinguoChronology.INSTANCE, 1989, 1, 8, 1, 2, 2, OFFSET_P0100},
            {ThaiBuddhistChronology.INSTANCE, 1873, 9, 7, 1, 2, 2, OFFSET_P0100},
            {ThaiBuddhistChronology.INSTANCE, 1928, 2, 28, 1, 2, 2, OFFSET_M0100},
            {ThaiBuddhistChronology.INSTANCE, 1989, 1, 8, 1, 2, 2, OFFSET_P0100},
            {IsoChronology.INSTANCE, 1873, 9, 7, 1, 2, 2, OFFSET_P0100},
            {IsoChronology.INSTANCE, 1928, 2, 28, 1, 2, 2, OFFSET_M0100},
            {IsoChronology.INSTANCE, 1989, 1, 8, 1, 2, 2, OFFSET_P0100},

    };
}
项目:openjdk-jdk10    文件:TCKChronology.java   
@DataProvider(name = "era_epochSecond_dataProvider")
Object[][]  data_era_epochSecond() {
    return new Object[][] {
            {JapaneseChronology.INSTANCE, JapaneseEra.MEIJI, 1873 - YDIFF_MEIJI, 9, 7, 1, 2, 2, OFFSET_P0100},
            {JapaneseChronology.INSTANCE, JapaneseEra.SHOWA, 1928 - YDIFF_SHOWA, 2, 28, 1, 2, 2, OFFSET_M0100},
            {JapaneseChronology.INSTANCE, JapaneseEra.HEISEI, 1989 - YDIFF_HEISEI, 1, 8, 1, 2, 2, OFFSET_P0100},
            {HijrahChronology.INSTANCE, HijrahEra.AH, 1434, 9, 7, 1, 2, 2, OFFSET_P0100},
            {MinguoChronology.INSTANCE, MinguoEra.BEFORE_ROC, 1873 - YDIFF_MINGUO, 9, 7, 1, 2, 2, OFFSET_P0100},
            {MinguoChronology.INSTANCE, MinguoEra.ROC, 1928 - YDIFF_MINGUO, 2, 28, 1, 2, 2, OFFSET_M0100},
            {MinguoChronology.INSTANCE, MinguoEra.ROC, 1989 - YDIFF_MINGUO, 1, 8, 1, 2, 2, OFFSET_P0100},
            {ThaiBuddhistChronology.INSTANCE, ThaiBuddhistEra.BE, 1873 + YDIFF_THAIBUDDHIST, 9, 7, 1, 2, 2, OFFSET_P0100},
            {ThaiBuddhistChronology.INSTANCE, ThaiBuddhistEra.BE, 1928 + YDIFF_THAIBUDDHIST, 2, 28, 1, 2, 2, OFFSET_M0100},
            {ThaiBuddhistChronology.INSTANCE, ThaiBuddhistEra.BE, 1989 + YDIFF_THAIBUDDHIST, 1, 8, 1, 2, 2, OFFSET_P0100},
            {IsoChronology.INSTANCE, IsoEra.CE, 1873, 9, 7, 1, 2, 2, OFFSET_P0100},
            {IsoChronology.INSTANCE, IsoEra.CE, 1928, 2, 28, 1, 2, 2, OFFSET_M0100},
            {IsoChronology.INSTANCE, IsoEra.CE, 1989, 1, 8, 1, 2, 2, OFFSET_P0100},

    };
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test
public void test_dateNow(){
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now()) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(ZoneId.systemDefault())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseDate.now(Clock.systemDefaultZone().getZone())) ;

    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(ZoneId.systemDefault())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(), JapaneseChronology.INSTANCE.dateNow(Clock.systemDefaultZone().getZone())) ;

    ZoneId zoneId = ZoneId.of("Europe/Paris");
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId))) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseChronology.INSTANCE.dateNow(Clock.system(zoneId).getZone())) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId))) ;
    assertEquals(JapaneseChronology.INSTANCE.dateNow(zoneId), JapaneseDate.now(Clock.system(zoneId).getZone())) ;

    assertEquals(JapaneseChronology.INSTANCE.dateNow(ZoneId.of(ZoneOffset.UTC.getId())), JapaneseChronology.INSTANCE.dateNow(Clock.systemUTC())) ;
}
项目:jdk8u-jdk    文件:TCKChronoPrinterParser.java   
@DataProvider(name="parseValid")
Object[][] data_parseValid() {
    return new Object[][] {
            {"ISO", IsoChronology.INSTANCE},
            {"ThaiBuddhist", ThaiBuddhistChronology.INSTANCE},
            {"Japanese", JapaneseChronology.INSTANCE},

            {"ISO2012", IsoChronology.INSTANCE},
            {"ThaiBuddhistXXX", ThaiBuddhistChronology.INSTANCE},
            {"JapaneseXXX", JapaneseChronology.INSTANCE},
    };
}
项目:jdk8u-jdk    文件:TCKChronology.java   
@DataProvider(name = "calendarsystemtype")
Object[][] data_CalendarType() {
    return new Object[][] {
        {HijrahChronology.INSTANCE, "islamic-umalqura"},
        {IsoChronology.INSTANCE, "iso8601"},
        {JapaneseChronology.INSTANCE, "japanese"},
        {MinguoChronology.INSTANCE, "roc"},
        {ThaiBuddhistChronology.INSTANCE, "buddhist"},
    };
}
项目:jdk8u-jdk    文件:TCKChronology.java   
@Test
public void test_JapaneseChronology_dateYearDay() {
    Chronology chrono = Chronology.of("Japanese");
    ChronoLocalDate date1 = chrono.dateYearDay(JapaneseEra.HEISEI, 8, 60);
    ChronoLocalDate date2 = chrono.date(JapaneseEra.HEISEI, 8, 2, 29);
    assertEquals(date1, JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60));
    assertEquals(date2, JapaneseChronology.INSTANCE.dateYearDay(JapaneseEra.HEISEI, 8, 60));
}
项目:jdk8u-jdk    文件:TCKChronoPeriod.java   
@DataProvider(name = "calendars")
Chronology[][] data_of_calendars() {
    return new Chronology[][]{
                {HijrahChronology.INSTANCE},
                {IsoChronology.INSTANCE},
                {JapaneseChronology.INSTANCE},
                {MinguoChronology.INSTANCE},
                {ThaiBuddhistChronology.INSTANCE}};
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test
public void test_chrono_byName() {
    Chronology c = JapaneseChronology.INSTANCE;
    Chronology test = Chronology.of("Japanese");
    Assert.assertNotNull(test, "The Japanese calendar could not be found byName");
    Assert.assertEquals(test.getId(), "Japanese", "ID mismatch");
    Assert.assertEquals(test.getCalendarType(), "japanese", "Type mismatch");
    Assert.assertEquals(test, c);
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test
public void test_Japanese_badEras() {
    int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000};
    for (int badEra : badEras) {
        try {
            Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
            fail("JapaneseChronology.eraOf returned " + era + " + for invalid eraValue " + badEra);
        } catch (DateTimeException ex) {
            // ignore expected exception
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider="createByEra")
public void test_createEymd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
    JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.date(era, yoe, moy, dom);
    JapaneseDate dateByDateFactory = JapaneseDate.of(era, yoe, moy, dom);
    assertEquals(dateByChronoFactory, dateByDateFactory);
    assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider="createByEra")
public void test_createEyd(JapaneseEra era, int yoe, int moy, int dom, int doy, LocalDate iso) {
    JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.dateYearDay(era, yoe, doy);
    JapaneseDate dateByDateFactory = JapaneseDate.of(era, yoe, moy, dom);
    assertEquals(dateByChronoFactory, dateByDateFactory);
    assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
}
项目:openjdk-jdk10    文件:TCKChronoLocalDateTime.java   
@DataProvider(name = "calendars")
Chronology[][] data_of_calendars() {
    return new Chronology[][]{
                {HijrahChronology.INSTANCE},
                {IsoChronology.INSTANCE},
                {JapaneseChronology.INSTANCE},
                {MinguoChronology.INSTANCE},
                {ThaiBuddhistChronology.INSTANCE}};
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
public void test_resolve_yearOfEra_eraOnly_invalidTooLarge() {
    for (ResolverStyle style : ResolverStyle.values()) {
        Map<TemporalField, Long> fieldValues = new HashMap<>();
        fieldValues.put(ChronoField.ERA, JapaneseEra.values()[JapaneseEra.values().length - 1].getValue() + 1L);
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed: " + style);
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider="createByProleptic")
public void test_createYd(int y, int moy, int dom, int doy, LocalDate iso) {
    JapaneseDate dateByChronoFactory = JapaneseChronology.INSTANCE.dateYearDay(y, doy);
    JapaneseDate dateByDateFactory = JapaneseDate.of(y, moy, dom);
    assertEquals(dateByChronoFactory, dateByDateFactory);
    assertEquals(dateByChronoFactory.hashCode(), dateByDateFactory.hashCode());
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
public void test_resolve_yearOfEra_eraOnly_invalidTooSmall() {
    for (ResolverStyle style : ResolverStyle.values()) {
        Map<TemporalField, Long> fieldValues = new HashMap<>();
        fieldValues.put(ChronoField.ERA, JapaneseEra.MEIJI.getValue() - 1L);
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
            fail("Should have failed: " + style);
        } catch (DateTimeException ex) {
            // expected
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider="prolepticYear")
public void test_prolepticYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    Era eraObj = JapaneseChronology.INSTANCE.eraOf(eraValue);
    assertTrue(JapaneseChronology.INSTANCE.eras().contains(eraObj));
    assertEquals(eraObj, era);
    assertEquals(JapaneseChronology.INSTANCE.prolepticYear(era, yearOfEra), expectedProlepticYear);
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test(dataProvider="prolepticYear")
public void test_isLeapYear(int eraValue, Era  era, int yearOfEra, int expectedProlepticYear, boolean isLeapYear) {
    assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), isLeapYear);
    assertEquals(JapaneseChronology.INSTANCE.isLeapYear(expectedProlepticYear), Year.of(expectedProlepticYear).isLeap());

    JapaneseDate jdate = JapaneseDate.now();
    jdate = jdate.with(ChronoField.YEAR, expectedProlepticYear).with(ChronoField.MONTH_OF_YEAR, 2);
    if (isLeapYear) {
        assertEquals(jdate.lengthOfMonth(), 29);
    } else {
        assertEquals(jdate.lengthOfMonth(), 28);
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test
public void test_getLong() {
    JapaneseDate base = JapaneseChronology.INSTANCE.date(JapaneseEra.SHOWA, 63, 6, 30);
    assertEquals(base.getLong(ERA), JapaneseEra.SHOWA.getValue());
    assertEquals(base.getLong(YEAR), 1988L);
    assertEquals(base.getLong(YEAR_OF_ERA), 63L);
    assertEquals(base.getLong(MONTH_OF_YEAR), 6L);
    assertEquals(base.getLong(DAY_OF_MONTH), 30L);
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_styleByEra")
public void test_resolve_yearOfEra_eraAndYearOnly_valid(ResolverStyle style, JapaneseEra era) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.ERA, (long) era.getValue());
    fieldValues.put(ChronoField.YEAR, 1L);
    JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
    assertEquals(date, null);
    assertEquals(fieldValues.get(ChronoField.ERA), (Long) (long) era.getValue());
    assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 1L);
    assertEquals(fieldValues.size(), 2);
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test
public void test_Japanese_badEras() {
    int badEras[] = {-1000, -998, -997, -2, 3, 4, 1000};
    for (int badEra : badEras) {
        try {
            Era era = JapaneseChronology.INSTANCE.eraOf(badEra);
            fail("JapaneseChronology.eraOf returned " + era + " + for invalid eraValue " + badEra);
        } catch (DateTimeException ex) {
            // ignore expected exception
        }
    }
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test
public void test_JapaneseChronology_eras() {
    List<Era> actualEras = JapaneseChronology.INSTANCE.eras();
    Object[][] erasInfo = data_japanseseEras();
    assertEquals(actualEras.size(), erasInfo.length, "Wrong number of Eras");

    for (int i = 0; i < erasInfo.length; i++) {
        Object[] eraInfo = erasInfo[i];
        assertEquals(actualEras.get(i), eraInfo[0], "Singleton mismatch");
    }
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_styles")
public void test_resolve_yearOfEra_yearOfEraAndYearOnly_valid(ResolverStyle style) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
    fieldValues.put(ChronoField.YEAR, 2012L);
    JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
    assertEquals(date, null);
    assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
    assertEquals(fieldValues.get(ChronoField.YEAR), (Long) 2012L);
    assertEquals(fieldValues.size(), 2);
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@Test
public void test_periodUntilDiffChrono() {
    JapaneseDate mdate1 = JapaneseDate.of(1970, 1, 1);
    JapaneseDate mdate2 = JapaneseDate.of(1971, 2, 2);
    MinguoDate ldate2 = MinguoChronology.INSTANCE.date(mdate2);
    ChronoPeriod period = mdate1.until(ldate2);
    assertEquals(period, JapaneseChronology.INSTANCE.period(1, 1, 1));
}
项目:jdk8u-jdk    文件:TCKJapaneseChronology.java   
@DataProvider(name="toString")
Object[][] data_toString() {
    return new Object[][] {
        {JapaneseChronology.INSTANCE.date(1873, 12,  5), "Japanese Meiji 6-12-05"},
        {JapaneseChronology.INSTANCE.date(1873, 12,  6), "Japanese Meiji 6-12-06"},
        {JapaneseChronology.INSTANCE.date(1873,  9,  8), "Japanese Meiji 6-09-08"},
        {JapaneseChronology.INSTANCE.date(1912,  7, 29), "Japanese Meiji 45-07-29"},
        {JapaneseChronology.INSTANCE.date(1912,  7, 30), "Japanese Taisho 1-07-30"},
        {JapaneseChronology.INSTANCE.date(1926, 12, 24), "Japanese Taisho 15-12-24"},
        {JapaneseChronology.INSTANCE.date(1926, 12, 25), "Japanese Showa 1-12-25"},
        {JapaneseChronology.INSTANCE.date(1989,  1,  7), "Japanese Showa 64-01-07"},
        {JapaneseChronology.INSTANCE.date(1989,  1,  8), "Japanese Heisei 1-01-08"},
        {JapaneseChronology.INSTANCE.date(2012, 12,  6), "Japanese Heisei 24-12-06"},
    };
}
项目:openjdk-jdk10    文件:TCKJapaneseChronology.java   
@Test(dataProvider = "resolve_styles")
public void test_resolve_yearOfEra_yearOfEraOnly_valid(ResolverStyle style) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.YEAR_OF_ERA, 1L);
    JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, style);
    assertEquals(date, null);
    assertEquals(fieldValues.get(ChronoField.YEAR_OF_ERA), (Long) 1L);
    assertEquals(fieldValues.size(), 1);
}