Search in sources :

Example 11 with JapaneseDate

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

the class TestJapaneseChronoImpl method test_JapaneseChrono_vsCalendar.

//-----------------------------------------------------------------------
// Verify  Japanese Calendar matches java.util.Calendar for range
//-----------------------------------------------------------------------
@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);
    }
}
Also used : Locale(java.util.Locale) OffsetDateTime(java.time.OffsetDateTime) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 12 with JapaneseDate

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

the class TCKJapaneseChronology method test_resolve_yearOfEra_eraAndYearOfEraOnly_valid.

@Test(dataProvider = "resolve_styleByEra")
public void test_resolve_yearOfEra_eraAndYearOfEraOnly_valid(ResolverStyle style, JapaneseEra era) {
    Map<TemporalField, Long> fieldValues = new HashMap<>();
    fieldValues.put(ChronoField.ERA, (long) era.getValue());
    fieldValues.put(ChronoField.YEAR_OF_ERA, 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_OF_ERA), (Long) 1L);
    assertEquals(fieldValues.size(), 2);
}
Also used : TemporalField(java.time.temporal.TemporalField) HashMap(java.util.HashMap) JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 13 with JapaneseDate

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

the class TCKJapaneseChronology method test_adjust_toLocalDate.

//-----------------------------------------------------------------------
// JapaneseDate.with(Local*)
//-----------------------------------------------------------------------
@Test
public void test_adjust_toLocalDate() {
    JapaneseDate jdate = JapaneseChronology.INSTANCE.date(1926, 1, 4);
    JapaneseDate test = jdate.with(LocalDate.of(2012, 7, 6));
    assertEquals(test, JapaneseChronology.INSTANCE.date(2012, 7, 6));
}
Also used : JapaneseDate(java.time.chrono.JapaneseDate) Test(org.testng.annotations.Test)

Example 14 with JapaneseDate

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

the class TCKJapaneseChronology method test_createByProleptic_epochDay.

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

Example 15 with JapaneseDate

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

the class TCKJapaneseChronology method test_createByProleptic_chronologyTemporalFactory.

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

Aggregations

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