Java Code Examples for java.time.chrono.Chronology#dateNow()

The following examples show how to use java.time.chrono.Chronology#dateNow() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestChronoLocalDate.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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)
}
 
Example 2
Source File: TCKChronology.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
 
Example 3
Source File: TCKChronoPeriod.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_addTo(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.addTo(date);
    assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}
 
Example 4
Source File: TCKChronoPeriod.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_addTo(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.addTo(date);
    assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}
 
Example 5
Source File: TCKChronoPeriod.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_addTo(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.addTo(date);
    assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}
 
Example 6
Source File: TestChronoLocalDate.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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)
}
 
Example 7
Source File: TestExampleCode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 8
Source File: TestExampleCode.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 9
Source File: TestExampleCode.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 10
Source File: TCKChronoPeriod.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_subtractFrom(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.subtractFrom(date);
    assertEquals(result, date.minus(14, MONTHS).minus(3, DAYS));
}
 
Example 11
Source File: TestChronoLocalDate.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 12
Source File: TCKChronology.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
 
Example 13
Source File: TCKChronology.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "calendarNameAndType")
public void test_dateEpochDay(String name, String alias) {
    Chronology chrono = Chronology.of(name);
    ChronoLocalDate date = chrono.dateNow();
    long epochDay = date.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate test = chrono.dateEpochDay(epochDay);
    assertEquals(test, date);
}
 
Example 14
Source File: TCKChronology.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Compute the number of days from the Epoch and compute the date from the number of days.
 */
@Test(dataProvider = "calendarNameAndType")
public void test_epoch(String name, String alias) {
    Chronology chrono = Chronology.of(name); // a chronology. In practice this is rarely hardcoded
    ChronoLocalDate date1 = chrono.dateNow();
    long epoch1 = date1.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate date2 = date1.with(ChronoField.EPOCH_DAY, epoch1);
    assertEquals(date1, date2, "Date from epoch day is not same date: " + date1 + " != " + date2);
    long epoch2 = date1.getLong(ChronoField.EPOCH_DAY);
    assertEquals(epoch1, epoch2, "Epoch day not the same: " + epoch1 + " != " + epoch2);
}
 
Example 15
Source File: TCKChronology.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider = "calendarNameAndType")
public void test_dateEpochDay(String name, String alias) {
    Chronology chrono = Chronology.of(name);
    ChronoLocalDate date = chrono.dateNow();
    long epochDay = date.getLong(ChronoField.EPOCH_DAY);
    ChronoLocalDate test = chrono.dateEpochDay(epochDay);
    assertEquals(test, date);
}
 
Example 16
Source File: TestChronoLocalDate.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 17
Source File: TestExampleCode.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
@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);
}
 
Example 18
Source File: TCKChronoPeriod.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
@Test(dataProvider="calendars")
public void test_subtractFrom(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.subtractFrom(date);
    assertEquals(result, date.minus(14, MONTHS).minus(3, DAYS));
}
 
Example 19
Source File: TestChronoLocalDate.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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)
}
 
Example 20
Source File: TCKChronoPeriod.java    From j2objc with Apache License 2.0 5 votes vote down vote up
@Test()
@UseDataProvider("data_of_calendars")
public void test_addTo(Chronology chrono) {
    ChronoPeriod period = chrono.period(1, 2, 3);
    ChronoLocalDate date = chrono.dateNow();
    Temporal result = period.addTo(date);
    assertEquals(result, date.plus(14, MONTHS).plus(3, DAYS));
}