Search in sources :

Example 21 with MinguoDate

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

the class TCKMinguoChronology method test_resolve_ymd_smart.

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

Example 22 with MinguoDate

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

the class TCKMinguoChronology method test_resolve_ymd_lenient.

@Test(dataProvider = "resolve_ymd")
public void test_resolve_ymd_lenient(int y, int m, int d, MinguoDate 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);
    MinguoDate date = MinguoChronology.INSTANCE.resolveDate(fieldValues, ResolverStyle.LENIENT);
    assertEquals(date, expected);
    assertEquals(fieldValues.size(), 0);
}
Also used : MinguoDate(java.time.chrono.MinguoDate) TemporalField(java.time.temporal.TemporalField) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 23 with MinguoDate

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

the class TCKMinguoChronology method test_MinguoDate.

@SuppressWarnings("unused")
@Test(dataProvider = "samples")
public void test_MinguoDate(MinguoDate minguoDate, LocalDate iso) {
    MinguoDate hd = minguoDate;
    ChronoLocalDateTime<MinguoDate> hdt = hd.atTime(LocalTime.NOON);
    ZoneOffset zo = ZoneOffset.ofHours(1);
    ChronoZonedDateTime<MinguoDate> hzdt = hdt.atZone(zo);
    hdt = hdt.plus(1, ChronoUnit.YEARS);
    hdt = hdt.plus(1, ChronoUnit.MONTHS);
    hdt = hdt.plus(1, ChronoUnit.DAYS);
    hdt = hdt.plus(1, ChronoUnit.HOURS);
    hdt = hdt.plus(1, ChronoUnit.MINUTES);
    hdt = hdt.plus(1, ChronoUnit.SECONDS);
    hdt = hdt.plus(1, ChronoUnit.NANOS);
    ChronoLocalDateTime<MinguoDate> a2 = hzdt.toLocalDateTime();
    MinguoDate a3 = a2.toLocalDate();
    MinguoDate a5 = hzdt.toLocalDate();
//System.out.printf(" d: %s, dt: %s; odt: %s; zodt: %s; a4: %s%n", date, hdt, hodt, hzdt, a5);
}
Also used : MinguoDate(java.time.chrono.MinguoDate) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 24 with MinguoDate

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

the class TCKMinguoChronology method test_LocalDateTime_adjustToMinguoDate.

@Test
public void test_LocalDateTime_adjustToMinguoDate() {
    MinguoDate minguo = MinguoChronology.INSTANCE.date(101, 10, 29);
    LocalDateTime test = LocalDateTime.MIN.with(minguo);
    assertEquals(test, LocalDateTime.of(2012, 10, 29, 0, 0));
}
Also used : LocalDateTime(java.time.LocalDateTime) ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) MinguoDate(java.time.chrono.MinguoDate) Test(org.testng.annotations.Test)

Example 25 with MinguoDate

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

the class TCKMinguoChronology method test_periodUntilDiffChrono.

@Test
public void test_periodUntilDiffChrono() {
    MinguoDate mdate1 = MinguoDate.of(1970, 1, 1);
    MinguoDate mdate2 = MinguoDate.of(1971, 2, 2);
    ThaiBuddhistDate ldate2 = ThaiBuddhistChronology.INSTANCE.date(mdate2);
    ChronoPeriod period = mdate1.until(ldate2);
    assertEquals(period, MinguoChronology.INSTANCE.period(1, 1, 1));
}
Also used : ChronoPeriod(java.time.chrono.ChronoPeriod) MinguoDate(java.time.chrono.MinguoDate) ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) Test(org.testng.annotations.Test)

Aggregations

MinguoDate (java.time.chrono.MinguoDate)31 Test (org.testng.annotations.Test)29 TemporalField (java.time.temporal.TemporalField)10 HashMap (java.util.HashMap)10 DateTimeException (java.time.DateTimeException)7 ChronoPeriod (java.time.chrono.ChronoPeriod)5 DateTimeFormatter (java.time.format.DateTimeFormatter)5 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)3 TemporalAccessor (java.time.temporal.TemporalAccessor)3 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)2 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 OffsetDateTime (java.time.OffsetDateTime)1 ZoneOffset (java.time.ZoneOffset)1 ZonedDateTime (java.time.ZonedDateTime)1 ChronoLocalDate (java.time.chrono.ChronoLocalDate)1 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)1 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)1 JapaneseDate (java.time.chrono.JapaneseDate)1