Search in sources :

Example 1 with Chronology

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

the class TCKJapaneseChronology method test_chrono_byName.

//-----------------------------------------------------------------------
// Chronology.of(String)
//-----------------------------------------------------------------------
@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);
}
Also used : 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) Test(org.testng.annotations.Test)

Example 2 with Chronology

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

the class TestExampleCode method test_calendarPackageExample.

@Test
public void test_calendarPackageExample() {
    // 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 the Thai Buddhist date
    ThaiBuddhistDate now1 = ThaiBuddhistDate.now();
    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);
    // Print today's date and the last day of the year for the Thai Buddhist Calendar.
    ThaiBuddhistDate first = now1.with(ChronoField.DAY_OF_MONTH, 1).with(ChronoField.MONTH_OF_YEAR, 1);
    ThaiBuddhistDate 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) ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) HijrahChronology(java.time.chrono.HijrahChronology) Chronology(java.time.chrono.Chronology) Test(org.testng.annotations.Test)

Example 3 with Chronology

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

the class TestChronoLocalDate method test_date_checkGenerics_genericsMethod_withType.

public <D extends ChronoLocalDate> void test_date_checkGenerics_genericsMethod_withType() {
    Chronology chrono = ThaiBuddhistChronology.INSTANCE;
    @SuppressWarnings("unchecked") D date = (D) chrono.dateNow();
    date = processOK(date);
    // date = processClassOK(ThaiBuddhistDate.class);  // does not compile (correct)
    date = dateSupplier();
// date = processWeird(date);  // does not compile (correct)
// date = processClassWeird(ThaiBuddhistDate.class);  // does not compile (correct)
}
Also used : Chronology(java.time.chrono.Chronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology)

Example 4 with Chronology

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

the class TestChronoLocalDate method test_date_checkGenerics_chronoLocalDateTime1.

public void test_date_checkGenerics_chronoLocalDateTime1() {
    LocalDateTime now = LocalDateTime.now();
    Chronology chrono = ThaiBuddhistChronology.INSTANCE;
    ChronoLocalDateTime<?> ldt = chrono.localDateTime(now);
    ldt = processCLDT(ldt);
}
Also used : ChronoLocalDateTime(java.time.chrono.ChronoLocalDateTime) LocalDateTime(java.time.LocalDateTime) Chronology(java.time.chrono.Chronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology)

Example 5 with Chronology

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

the class TestServiceLoader method test_copticServiceLoader.

@Test
public void test_copticServiceLoader() {
    Map<String, Chronology> chronos = new HashMap<>();
    ServiceLoader<Chronology> loader = ServiceLoader.load(Chronology.class, null);
    for (Chronology chrono : loader) {
        chronos.put(chrono.getId(), chrono);
    }
    assertNotNull(chronos.get("Coptic"), "CopticChronology not found");
}
Also used : HashMap(java.util.HashMap) Chronology(java.time.chrono.Chronology) Test(org.testng.annotations.Test)

Aggregations

Chronology (java.time.chrono.Chronology)114 IsoChronology (java.time.chrono.IsoChronology)95 Test (org.testng.annotations.Test)66 ThaiBuddhistChronology (java.time.chrono.ThaiBuddhistChronology)58 MinguoChronology (java.time.chrono.MinguoChronology)54 HijrahChronology (java.time.chrono.HijrahChronology)47 JapaneseChronology (java.time.chrono.JapaneseChronology)46 ChronoLocalDate (java.time.chrono.ChronoLocalDate)42 LocalDate (java.time.LocalDate)39 Test (org.junit.Test)32 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)27 TemporalAmount (java.time.temporal.TemporalAmount)12 TemporalUnit (java.time.temporal.TemporalUnit)12 TemporalAccessor (java.time.temporal.TemporalAccessor)10 TemporalField (java.time.temporal.TemporalField)9 ZoneId (java.time.ZoneId)8 Locale (java.util.Locale)8 DateTimeException (java.time.DateTimeException)6 TemporalAdjuster (java.time.temporal.TemporalAdjuster)6 ArrayList (java.util.ArrayList)6