Search in sources :

Example 1 with JapaneseDate

use of java.time.chrono.JapaneseDate in project jdk8u_jdk by JetBrains.

the class TCKJapaneseChronology method test_adjust2.

@Test
public void test_adjust2() {
    JapaneseDate base = JapaneseChronology.INSTANCE.date(1928, 12, 2);
    JapaneseDate test = base.with(TemporalAdjusters.lastDayOfMonth());
    assertEquals(test, JapaneseChronology.INSTANCE.date(1928, 12, 31));
}
Also used : JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 2 with JapaneseDate

use of java.time.chrono.JapaneseDate in project jdk8u_jdk by JetBrains.

the class TCKJapaneseChronology method test_resolve_ymd_smart.

@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_smart(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 (Boolean.TRUE.equals(smart)) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, expected);
        assertEquals(fieldValues.size(), 0);
    } else if (smart instanceof JapaneseDate) {
        JapaneseDate date = JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
        assertEquals(date, smart);
    } else {
        try {
            JapaneseChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.SMART);
            fail("Should have failed");
        } catch (DateTimeException ex) {
        // expected
        }
    }
}
Also used : TemporalField(java.time.temporal.TemporalField) DateTimeException(java.time.DateTimeException) HashMap(java.util.HashMap) JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 3 with JapaneseDate

use of java.time.chrono.JapaneseDate in project jdk8u_jdk by JetBrains.

the class TCKJapaneseChronology method test_createByProleptic_dateFrom.

@Test(dataProvider = "createByProleptic")
public void test_createByProleptic_dateFrom(int y, int moy, int dom, int doy, LocalDate iso) {
    JapaneseDate test = JapaneseDate.of(y, moy, dom);
    assertEquals(LocalDate.from(test), iso);
    assertEquals(JapaneseDate.from(iso), test);
}
Also used : JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 4 with JapaneseDate

use of java.time.chrono.JapaneseDate in project jdk8u_jdk by JetBrains.

the class TCKJapaneseChronology method test_withDayOfYear.

@Test
public void test_withDayOfYear() {
    JapaneseDate hd = JapaneseChronology.INSTANCE.dateYearDay(1990, 1);
    for (int i = 1; i <= hd.lengthOfYear(); i++) {
        JapaneseDate hd2 = hd.with(DAY_OF_YEAR, i);
        int doy = hd2.get(DAY_OF_YEAR);
        assertEquals(doy, i, "with(DAY_OF_YEAR) incorrect for " + i + " " + hd2);
    }
}
Also used : JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 5 with JapaneseDate

use of java.time.chrono.JapaneseDate in project jdk8u_jdk by JetBrains.

the class TCKJapaneseChronology method test_getDayOfYear.

//-----------------------------------------------------------------------
// JapaneseChronology.dateYearDay, getDayOfYear
//-----------------------------------------------------------------------
@Test
public void test_getDayOfYear() {
    // Test all the Eras
    for (JapaneseEra era : JapaneseEra.values()) {
        // Until Era supports range(YEAR_OF_ERA)
        int firstYear = (era == JapaneseEra.MEIJI) ? 6 : 1;
        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);
        }
    }
}
Also used : ValueRange(java.time.temporal.ValueRange) JapaneseDate(java.time.chrono.JapaneseDate) JapaneseEra(java.time.chrono.JapaneseEra) Test(org.testng.annotations.Test)

Aggregations

JapaneseDate (java.time.chrono.JapaneseDate)43 Test (org.testng.annotations.Test)42 TemporalField (java.time.temporal.TemporalField)12 HashMap (java.util.HashMap)12 DateTimeException (java.time.DateTimeException)5 LocalDateTime (java.time.LocalDateTime)2 OffsetDateTime (java.time.OffsetDateTime)2 ChronoPeriod (java.time.chrono.ChronoPeriod)2 JapaneseEra (java.time.chrono.JapaneseEra)2 MinguoDate (java.time.chrono.MinguoDate)2 Calendar (java.util.Calendar)2 GregorianCalendar (java.util.GregorianCalendar)2 Locale (java.util.Locale)2 Clock (java.time.Clock)1 LocalDate (java.time.LocalDate)1 ChronoLocalDate (java.time.chrono.ChronoLocalDate)1 HijrahDate (java.time.chrono.HijrahDate)1 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)1 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)1 ValueRange (java.time.temporal.ValueRange)1