Java Code Examples for java.time.chrono.ChronoLocalDate#get()

The following examples show how to use java.time.chrono.ChronoLocalDate#get() . 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: TestReducedParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYearOfEra(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR_OF_ERA, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR_OF_ERA);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR_OF_ERA);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 2
Source File: TestReducedParser.java    From j2objc with Apache License 2.0 6 votes vote down vote up
@Test
@UseDataProvider("provider_reducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR);
    assertEquals(String.format("Wrong date parsed, chrono: %s, input: %s", chrono, input),
        actual, expected);

}
 
Example 3
Source File: TestReducedParser.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYearOfEra(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR_OF_ERA, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR_OF_ERA);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR_OF_ERA);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 4
Source File: TestReducedParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYearOfEra(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR_OF_ERA, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR_OF_ERA);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR_OF_ERA);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 5
Source File: TestReducedParser.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 6
Source File: TestReducedParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 7
Source File: TestReducedParser.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 8
Source File: TestReducedParser.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYearOfEra(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR_OF_ERA, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR_OF_ERA);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR_OF_ERA);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 9
Source File: TestReducedParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 10
Source File: TestReducedParser.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 11
Source File: TestReducedParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYearOfEra(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR_OF_ERA, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR_OF_ERA);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR_OF_ERA);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 12
Source File: TestReducedParser.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYear(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 13
Source File: TestReducedParser.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
@Test(dataProvider="ReducedWithChrono")
public void test_reducedWithChronoYearOfEra(ChronoLocalDate date) {
    Chronology chrono = date.getChronology();
    DateTimeFormatter df
            = new DateTimeFormatterBuilder().appendValueReduced(YEAR_OF_ERA, 2, 2, LocalDate.of(2000, 1, 1))
            .toFormatter()
            .withChronology(chrono);
    int expected = date.get(YEAR_OF_ERA);
    String input = df.format(date);

    ParsePosition pos = new ParsePosition(0);
    TemporalAccessor parsed = df.parseUnresolved(input, pos);
    int actual = parsed.get(YEAR_OF_ERA);
    assertEquals(actual, expected,
            String.format("Wrong date parsed, chrono: %s, input: %s",
            chrono, input));

}
 
Example 14
Source File: TestExampleCode.java    From jdk8u60 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 15
Source File: TestExampleCode.java    From openjdk-jdk8u 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 16
Source File: TestExampleCode.java    From jdk8u-dev-jdk 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 17
Source File: TestExampleCode.java    From openjdk-jdk8u-backup 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: 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 19
Source File: TestExampleCode.java    From openjdk-jdk9 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 20
Source File: TestExampleCode.java    From dragonwell8_jdk 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);
}