Search in sources :

Example 71 with Chronology

use of java.time.chrono.Chronology 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 72 with Chronology

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

the class TCKThaiBuddhistChronology method test_chrono_byLocale_fullTag_thaiCalendarFromElsewhere.

@Test
public void test_chrono_byLocale_fullTag_thaiCalendarFromElsewhere() {
    Chronology test = Chronology.ofLocale(Locale.forLanguageTag("en-US-u-ca-buddhist"));
    Assert.assertEquals(test.getId(), "ThaiBuddhist");
    Assert.assertEquals(test, ThaiBuddhistChronology.INSTANCE);
}
Also used : 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 73 with Chronology

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

the class TestChronologyPerf method test_chronologyGetAvailablePerf.

@Test
public void test_chronologyGetAvailablePerf() {
    long start = System.nanoTime();
    Set<Chronology> chronos = Chronology.getAvailableChronologies();
    long end = System.nanoTime();
    Duration d = Duration.of(end - start, ChronoUnit.NANOS);
    System.out.printf(" Cold Duration of Chronology.getAvailableChronologies(): %s%n", d);
    start = System.nanoTime();
    chronos = Chronology.getAvailableChronologies();
    end = System.nanoTime();
    d = Duration.of(end - start, ChronoUnit.NANOS);
    System.out.printf(" Warm Duration of Chronology.getAvailableChronologies(): %s%n", d);
    start = System.nanoTime();
    HijrahChronology.INSTANCE.date(1434, 1, 1);
    end = System.nanoTime();
    d = Duration.of(end - start, ChronoUnit.NANOS);
    System.out.printf(" Warm Duration of HijrahDate.date(1434, 1, 1): %s%n", d);
}
Also used : Duration(java.time.Duration) Chronology(java.time.chrono.Chronology) HijrahChronology(java.time.chrono.HijrahChronology) Test(org.testng.annotations.Test)

Example 74 with Chronology

use of java.time.chrono.Chronology 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)

Example 75 with Chronology

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

the class TestChronoLocalDate method test_date_checkGenerics_genericsMethod.

//-----------------------------------------------------------------------
public void test_date_checkGenerics_genericsMethod() {
    Chronology chrono = ThaiBuddhistChronology.INSTANCE;
    ChronoLocalDate date = chrono.dateNow();
    date = processOK(date);
    date = processClassOK(ThaiBuddhistDate.class);
    date = dateSupplier();
    date = processClassWeird(ThaiBuddhistDate.class);
}
Also used : ChronoLocalDate(java.time.chrono.ChronoLocalDate) ThaiBuddhistDate(java.time.chrono.ThaiBuddhistDate) Chronology(java.time.chrono.Chronology) ThaiBuddhistChronology(java.time.chrono.ThaiBuddhistChronology)

Aggregations

Chronology (java.time.chrono.Chronology)76 Test (org.testng.annotations.Test)65 IsoChronology (java.time.chrono.IsoChronology)59 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)29 LocalDate (java.time.LocalDate)21 Locale (java.util.Locale)7 TemporalAmount (java.time.temporal.TemporalAmount)6 TemporalUnit (java.time.temporal.TemporalUnit)6 ZoneId (java.time.ZoneId)5 TemporalAccessor (java.time.temporal.TemporalAccessor)5 Clock (java.time.Clock)4 DateTimeException (java.time.DateTimeException)4 Era (java.time.chrono.Era)4 TemporalField (java.time.temporal.TemporalField)4 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)3 DateTimeFormatter (java.time.format.DateTimeFormatter)3