Search in sources :

Example 36 with ChronoLocalDate

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

the class TCKMinguoChronology method test_InvalidEras.

//-----------------------------------------------------------------------
// Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...)
//-----------------------------------------------------------------------
@Test
public void test_InvalidEras() {
    // Verify that the eras from every other Chronology are invalid
    for (Chronology chrono : Chronology.getAvailableChronologies()) {
        if (chrono instanceof MinguoChronology) {
            continue;
        }
        List<Era> eras = chrono.eras();
        for (Era era : eras) {
            try {
                ChronoLocalDate date = MinguoChronology.INSTANCE.date(era, 1, 1, 1);
                fail("MinguoChronology.date did not throw ClassCastException for Era: " + era);
            } catch (ClassCastException cex) {
                // ignore expected exception
                ;
            }
            try {
                @SuppressWarnings("unused") int year = MinguoChronology.INSTANCE.prolepticYear(era, 1);
                fail("MinguoChronology.prolepticYear did not throw ClassCastException for Era: " + era);
            } catch (ClassCastException cex) {
                // ignore expected exception
                ;
            }
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) MinguoEra(java.time.chrono.MinguoEra) Era(java.time.chrono.Era) MinguoChronology(java.time.chrono.MinguoChronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) Test(org.testng.annotations.Test)

Example 37 with ChronoLocalDate

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

the class TCKJapaneseChronology method test_InvalidEras.

//-----------------------------------------------------------------------
// Bad Era for Chronology.date(era,...) and Chronology.prolepticYear(Era,...)
//-----------------------------------------------------------------------
@Test
public void test_InvalidEras() {
    // Verify that the eras from every other Chronology are invalid
    for (Chronology chrono : Chronology.getAvailableChronologies()) {
        if (chrono instanceof JapaneseChronology) {
            continue;
        }
        List<Era> eras = chrono.eras();
        for (Era era : eras) {
            try {
                ChronoLocalDate date = JapaneseChronology.INSTANCE.date(era, 1, 1, 1);
                fail("JapaneseChronology.date did not throw ClassCastException for Era: " + era);
            } catch (ClassCastException cex) {
                // ignore expected exception
                ;
            }
            try {
                @SuppressWarnings("unused") int year = JapaneseChronology.INSTANCE.prolepticYear(era, 1);
                fail("JapaneseChronology.prolepticYear did not throw ClassCastException for Era: " + era);
            } catch (ClassCastException cex) {
                // ignore expected exception
                ;
            }
        }
    }
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) JapaneseEra(java.time.chrono.JapaneseEra) Era(java.time.chrono.Era) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology) IsoChronology(java.time.chrono.IsoChronology) Chronology(java.time.chrono.Chronology) MinguoChronology(java.time.chrono.MinguoChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) JapaneseChronology(java.time.chrono.JapaneseChronology) Test(org.testng.annotations.Test)

Example 38 with ChronoLocalDate

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

the class TCKTestServiceLoader method test_TestServiceLoader.

@Test
public void test_TestServiceLoader() {
    Chronology chrono = Chronology.of("Coptic");
    ChronoLocalDate copticDate = chrono.date(1729, 4, 27);
    LocalDate ld = LocalDate.from(copticDate);
    assertEquals(ld, LocalDate.of(2013, 1, 5), "CopticDate does not match LocalDate");
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) Chronology(java.time.chrono.Chronology) ChronoLocalDate(java.time.chrono.ChronoLocalDate) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Example 39 with ChronoLocalDate

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

the class TestExampleCode method test_unknownChronologyWithDateTime.

void test_unknownChronologyWithDateTime() {
    ChronoLocalDate date = LocalDate.now();
    ChronoLocalDateTime<?> cldt = date.atTime(LocalTime.NOON);
    ChronoLocalDate ld = cldt.toLocalDate();
    ChronoLocalDateTime<?> noonTomorrow = tomorrowNoon(ld);
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate)

Example 40 with ChronoLocalDate

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

the class TestExampleCode method test_chronoPackageExample.

@Test
public void test_chronoPackageExample() {
    // Print the Thai Buddhist date
    ChronoLocalDate now1 = Chronology.of("ThaiBuddhist").dateNow();
    int day = now1.get(ChronoField.DAY_OF_MONTH);
    int dow = now1.get(ChronoField.DAY_OF_WEEK);
    int month = now1.get(ChronoField.MONTH_OF_YEAR);
    int year = now1.get(ChronoField.YEAR);
    System.out.printf("  Today is %s %s %d-%s-%d%n", now1.getChronology().getId(), dow, day, month, year);
    // Enumerate the list of available calendars and print today for each
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    for (Chronology chrono : chronos) {
        ChronoLocalDate date = chrono.dateNow();
        System.out.printf("   %20s: %s%n", chrono.getId(), date.toString());
    }
    // Print today's date and the last day of the year for the Thai Buddhist Calendar.
    ChronoLocalDate first = now1.with(ChronoField.DAY_OF_MONTH, 1).with(ChronoField.MONTH_OF_YEAR, 1);
    ChronoLocalDate last = first.plus(1, ChronoUnit.YEARS).minus(1, ChronoUnit.DAYS);
    System.out.printf("  %s: 1st of year: %s; end of year: %s%n", last.getChronology().getId(), first, last);
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) HijrahChronology(java.time.chrono.HijrahChronology) Chronology(java.time.chrono.Chronology) Test(org.testng.annotations.Test)

Aggregations

ChronoLocalDate (java.time.chrono.ChronoLocalDate)43 Test (org.testng.annotations.Test)34 Chronology (java.time.chrono.Chronology)28 IsoChronology (java.time.chrono.IsoChronology)19 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)18 HijrahChronology (java.time.chrono.HijrahChronology)17 MinguoChronology (java.time.chrono.MinguoChronology)17 JapaneseChronology (java.time.chrono.JapaneseChronology)15 LocalDate (java.time.LocalDate)10 DateTimeException (java.time.DateTimeException)5 ChronoPeriod (java.time.chrono.ChronoPeriod)4 Era (java.time.chrono.Era)4 DateTimeFormatter (java.time.format.DateTimeFormatter)3 TemporalAccessor (java.time.temporal.TemporalAccessor)3 TemporalField (java.time.temporal.TemporalField)3 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)2 ThaiBuddhistDate (java.time.chrono.ThaiBuddhistDate)2 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)2 Temporal (java.time.temporal.Temporal)2 TemporalAmount (java.time.temporal.TemporalAmount)2