Java Code Examples for java.time.LocalDate.of()

The following are Jave code examples for showing how to use of() of the java.time.LocalDate class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: openjdk-jdk10   File: TCKOffsetTime.java   View Source Code Vote up 6 votes
@DataProvider(name="adjustInto")
Object[][] data_adjustInto() {
    return new Object[][]{
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(LocalTime.of(1, 1, 1, 100), ZoneOffset.UTC), OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.MIN, OffsetTime.of(LocalTime.of(23 , 5), OFFSET_PONE), null},
            {OffsetTime.MAX, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MAX.toLocalTime(), ZoneOffset.ofHours(-18)), null},
            {OffsetTime.MIN, OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetTime.of(OffsetTime.MIN.toLocalTime(), ZoneOffset.ofHours(18)), null},


            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZONE_GAZA), ZonedDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), ZONE_GAZA), null},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), ZoneOffset.UTC), OffsetDateTime.of(LocalDateTime.of(2012, 3, 4, 23, 5), OFFSET_PONE), null},

            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDateTime.of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalDate.of(2210, 2, 2), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), LocalTime.of(22, 3, 0), null, DateTimeException.class},
            {OffsetTime.of(LocalTime.of(23, 5), OFFSET_PONE), null, null, NullPointerException.class},

    };
}
 
Example 2
Project: jdk8u-jdk   File: TCKChronoZonedDateTime.java   View Source Code Vote up 6 votes
@Test(dataProvider="calendars")
public void test_badPlusTemporalUnitChrono(Chronology chrono) {
    LocalDate refDate = LocalDate.of(2013, 1, 1);
    ChronoZonedDateTime<?> czdt = chrono.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
    for (Chronology[] clist : data_of_calendars()) {
        Chronology chrono2 = clist[0];
        ChronoZonedDateTime<?> czdt2 = chrono2.date(refDate).atTime(LocalTime.NOON).atZone(ZoneOffset.UTC);
        TemporalUnit adjuster = new FixedTemporalUnit(czdt2);
        if (chrono != chrono2) {
            try {
                czdt.plus(1, adjuster);
                Assert.fail("TemporalUnit.doPlus plus should have thrown a ClassCastException, " + czdt
                        + " can not be cast to " + czdt2);
            } catch (ClassCastException cce) {
                // Expected exception; not an error
            }
        } else {
            // Same chronology,
            ChronoZonedDateTime<?> result = czdt.plus(1, adjuster);
            assertEquals(result, czdt2, "WithAdjuster failed to replace date");
        }
    }
}
 
Example 3
Project: openjdk-jdk10   File: TCKDateTimeParseResolver.java   View Source Code Vote up 6 votes
@DataProvider(name="resolveTwoToDate")
Object[][] data_resolveTwoToDate() {
    return new Object[][]{
            // merge
            {YEAR, 2012, DAY_OF_YEAR, 32, LocalDate.of(2012, 2, 1)},
            {YEAR_OF_ERA, 2012, DAY_OF_YEAR, 32, LocalDate.of(2012, 2, 1)},

            // merge
            {PROLEPTIC_MONTH, 2012 * 12 + (2 - 1), DAY_OF_MONTH, 25, LocalDate.of(2012, 2, 25)},
            {PROLEPTIC_MONTH, 2012 * 12 + (2 - 1), DAY_OF_YEAR, 56, LocalDate.of(2012, 2, 25)},

            // cross-check
            {EPOCH_DAY, 32, ERA, 1, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, -146097 * 5L, ERA, 0, LocalDate.of(1970 - (400 * 5), 1, 1)},
            {EPOCH_DAY, 32, YEAR, 1970, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, -146097 * 5L, YEAR, 1970 - (400 * 5), LocalDate.of(1970 - (400 * 5), 1, 1)},
            {EPOCH_DAY, 32, YEAR_OF_ERA, 1970, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, -146097 * 5L, YEAR_OF_ERA, 1 - (1970 - (400 * 5)), LocalDate.of(1970 - (400 * 5), 1, 1)},
            {EPOCH_DAY, 32, MONTH_OF_YEAR, 2, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, 32, DAY_OF_YEAR, 33, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, 32, DAY_OF_MONTH, 2, LocalDate.of(1970, 2, 2)},
            {EPOCH_DAY, 32, DAY_OF_WEEK, 1, LocalDate.of(1970, 2, 2)},
    };
}
 
Example 4
Project: openjdk-jdk10   File: TCKChronoUnit.java   View Source Code Vote up 5 votes
@DataProvider(name="unitAndTemporal")
Object[][] data_unitAndTemporal() {
    return new Object[][] {
            {CENTURIES, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2100, 1, 10)},
            {DECADES, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2010, 1, 10)},
            {YEARS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2001, 1, 10)},
            {MONTHS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 2, 10)},
            {WEEKS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 1, 17)},
            {DAYS, LocalDate.of(2000, 1, 10), true, 1, LocalDate.of(2000, 1, 11)},

            {HALF_DAYS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(13, 2, 3, 400)},
            {HOURS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(2, 2, 3, 400)},
            {MINUTES, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 3, 3, 400)},
            {SECONDS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 4, 400)},
            {MICROS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1000 + 400)},
            {MILLIS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1000*1000 + 400)},
            {NANOS, LocalTime.of(1, 2, 3, 400), true, 1, LocalTime.of(1, 2, 3, 1 + 400)},

            {CENTURIES, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {DECADES, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {YEARS, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {MONTHS, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {WEEKS, LocalTime.of(1, 2, 3, 400), false, 1, null},
            {DAYS, LocalTime.of(1, 2, 3, 400), false, 1, null},

            {HALF_DAYS, LocalDate.of(2000, 2, 29), false, 1, null},
            {HOURS, LocalDate.of(2000, 2, 29), false, 1, null},
            {MINUTES, LocalDate.of(2000, 2, 29), false, 1, null},
            {SECONDS, LocalDate.of(2000, 2, 29), false, 1, null},
            {MICROS, LocalDate.of(2000, 2, 29), false, 1, null},
            {MILLIS, LocalDate.of(2000, 2, 29), false, 1, null},
            {NANOS, LocalDate.of(2000, 2, 29), false, 1, null},

    };
}
 
Example 5
Project: jdk8u-jdk   File: TCKLocalizedFieldParser.java   View Source Code Vote up 5 votes
@DataProvider(name="LocalWeekMonthYearPatterns")
Object[][] provider_patternLocalDate() {
    return new Object[][] {
        {"e W M y",  "1 1 1 2012", 0, 10, LocalDate.of(2012, 1, 1)},
        {"e W M y",  "1 2 1 2012", 0, 10, LocalDate.of(2012, 1, 8)},
        {"e W M y",  "2 2 1 2012", 0, 10, LocalDate.of(2012, 1, 9)},
        {"e W M y",  "3 2 1 2012", 0, 10, LocalDate.of(2012, 1, 10)},
        {"e W M y",  "1 3 1 2012", 0, 10, LocalDate.of(2012, 1, 15)},
        {"e W M y",  "2 3 1 2012", 0, 10, LocalDate.of(2012, 1, 16)},
        {"e W M y",  "6 2 1 2012", 0, 10, LocalDate.of(2012, 1, 13)},
        {"e W M y",  "6 2 7 2012", 0, 10, LocalDate.of(2012, 7, 13)},
        {"'Date: 'y-MM', day-of-week: 'e', week-of-month: 'W",
            "Date: 2012-07, day-of-week: 6, week-of-month: 3", 0, 47, LocalDate.of(2012, 7, 20)},
    };
}
 
Example 6
Project: CalendarFX   File: IntervalTest.java   View Source Code Vote up 5 votes
@Test
public void shouldNotBeEqualBecauseOfDifferentLocalDate() {
    // given
    Interval interval1 = new Interval(LocalDate.of(2017, 1, 14), LocalTime.of(10, 00), LocalDate.of(2017, 1, 15), LocalTime.of(23, 00));
    Interval interval2 = new Interval(LocalDate.of(2017, 1, 14), LocalTime.of(10, 00), LocalDate.of(2017, 1, 16), LocalTime.of(23, 00));

    // when
    boolean equal = interval1.equals(interval2);

    // then
    assertThat(equal, is(false));
}
 
Example 7
Project: openjdk-jdk10   File: TCKYear.java   View Source Code Vote up 5 votes
@Test
public void test_atDay_notLeapYear() {
    Year test = Year.of(2007);
    LocalDate expected = LocalDate.of(2007, 1, 1);
    for (int i = 1; i <= 365; i++) {
        assertEquals(test.atDay(i), expected);
        expected = expected.plusDays(1);
    }
}
 
Example 8
Project: openjdk-jdk10   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test
public void test_atTime_OffsetTime() {
    LocalDate t = LocalDate.of(2008, 6, 30);
    assertEquals(t.atTime(OffsetTime.of(11, 30, 0, 0, OFFSET_PONE)), OffsetDateTime.of(2008, 6, 30, 11, 30, 0, 0, OFFSET_PONE));
}
 
Example 9
Project: openjdk-jdk10   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void test_plusMonths_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.plusMonths(Long.MIN_VALUE);
}
 
Example 10
Project: jdk8u-jdk   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void test_atTime_int_int_int_int_secondTooSmall() {
    LocalDate t = LocalDate.of(2008, 6, 30);
    t.atTime(11, 30, -1, 50);
}
 
Example 11
Project: jdk8u-jdk   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test
public void test_plusWeeks_maximum() {
    LocalDate t = LocalDate.of(Year.MAX_VALUE, 12, 24).plusWeeks(1);
    LocalDate expected = LocalDate.of(Year.MAX_VALUE, 12, 31);
    assertEquals(t, expected);
}
 
Example 12
Project: openjdk-jdk10   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test(dataProvider="sampleToString")
public void test_toString(int y, int m, int d, String expected) {
    LocalDate t = LocalDate.of(y, m, d);
    String str = t.toString();
    assertEquals(str, expected);
}
 
Example 13
Project: openjdk-jdk10   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_ints_dayTooLow() {
    LocalDate.of(2007, 1, 0);
}
 
Example 14
Project: emojava   File: Generator.java   View Source Code Vote up 4 votes
private static void readAll() throws IOException {
    final InternalEmojiDatabase collectorV1 = new InternalEmojiDatabase();
    readUnicodeV1(UNICODE_9_NAMES_LIST_TXT, collectorV1);
    readEmojiItemsV1(EMOJI_1_0_EMOJI_DATA_TXT, collectorV1);
    LocalDate releaseV1 = LocalDate.of(2015, 8, 4);
    writeCsv(TARGET_EMOJI_V1_CSV, releaseV1, collectorV1.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V1_MD, "Emoji 1.0", releaseV1, collectorV1.getCsvRowsForEmojiOnly());

    final InternalEmojiDatabase collectorV2 = new InternalEmojiDatabase();
    readUnicodeV2(UNICODE_9_NAMES_LIST_TXT, collectorV2);
    readEmojiItemsV2(EMOJI_1_0_EMOJI_DATA_TXT, EMOJI_2_0_EMOJI_DATA_TXT, collectorV2);
    readEmojiSequencesV2(EMOJI_2_0_EMOJI_SEQUENCES_TXT, collectorV2);
    readEmojiSequencesV2(EMOJI_2_0_EMOJI_ZWJ_SEQUENCES_TXT, collectorV2);
    LocalDate releaseV2 = LocalDate.of(2015, 11, 11);
    writeCsv(TARGET_EMOJI_V2_CSV, releaseV2, collectorV2.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V2_MD, "Emoji 2.0", releaseV2, collectorV2.getCsvRowsForEmojiOnly());

    final InternalEmojiDatabase collectorV3 = new InternalEmojiDatabase();
    readUnicodeV2(UNICODE_9_NAMES_LIST_TXT, collectorV3);
    readEmojiItemsV2(EMOJI_1_0_EMOJI_DATA_TXT, EMOJI_3_0_EMOJI_DATA_TXT, collectorV3);
    readEmojiSequencesV3(EMOJI_3_0_EMOJI_SEQUENCES_TXT, collectorV3);
    readEmojiSequencesV3(EMOJI_3_0_EMOJI_ZWJ_SEQUENCES_TXT, collectorV3);
    LocalDate releaseV3 = LocalDate.of(2016, 6, 2);
    writeCsv(TARGET_EMOJI_V3_CSV, releaseV3, collectorV3.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V3_MD, "Emoji 3.0", releaseV3, collectorV3.getCsvRowsForEmojiOnly());

    final InternalEmojiDatabase collectorV4 = new InternalEmojiDatabase();
    readUnicodeV2(UNICODE_9_NAMES_LIST_TXT, collectorV4);
    readEmojiItemsV2(EMOJI_1_0_EMOJI_DATA_TXT, EMOJI_4_0_EMOJI_DATA_TXT, collectorV4);
    readEmojiSequencesV4(EMOJI_4_0_EMOJI_SEQUENCES_TXT, collectorV4);
    readEmojiSequencesV4(EMOJI_4_0_EMOJI_ZWJ_SEQUENCES_TXT, collectorV4);
    LocalDate releaseV4 = LocalDate.of(2016, 11, 14);
    writeCsv(TARGET_EMOJI_V4_CSV, releaseV4, collectorV4.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V4_MD, "Emoji 4.0", releaseV4, collectorV4.getCsvRowsForEmojiOnly());

    final InternalEmojiDatabase collectorV5 = new InternalEmojiDatabase();
    readUnicodeV2(UNICODE_10_NAMES_LIST_TXT, collectorV5);
    readEmojiItemsV2(EMOJI_1_0_EMOJI_DATA_TXT, EMOJI_5_0_EMOJI_DATA_TXT, collectorV5);
    readEmojiSequencesV4(EMOJI_5_0_EMOJI_SEQUENCES_TXT, collectorV5);
    readEmojiSequencesV4(EMOJI_5_0_EMOJI_ZWJ_SEQUENCES_TXT, collectorV5);
    LocalDate releaseV5 = LocalDate.of(2017, 3, 27);
    writeCsv(TARGET_EMOJI_V5_CSV, releaseV5, collectorV5.getCsvRows());
    writeMarkdown(TARGET_EMOJI_V5_MD, "Emoji 5.0", releaseV5, collectorV5.getCsvRowsForEmojiOnly());
}
 
Example 15
Project: openjdk-jdk10   File: TCKLocalDate.java   View Source Code Vote up 4 votes
private LocalDate date(int year, int month, int day) {
    return LocalDate.of(year, month, day);
}
 
Example 16
Project: jdk8u-jdk   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void test_plusYears_long_invalidTooLargeMaxAddMin() {
    LocalDate test = LocalDate.of(Year.MAX_VALUE, 12, 1);
    test.plusYears(Long.MIN_VALUE);
}
 
Example 17
Project: jdk8u-jdk   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void test_atTime_int_int_int_hourTooSmall() {
    LocalDate t = LocalDate.of(2008, 6, 30);
    t.atTime(-1, 30, 40);
}
 
Example 18
Project: light-access   File: Product.java   View Source Code Vote up 4 votes
public Product(int id, String name) {
    this(id, name, LocalDate.of(2017, 07, 29));
}
 
Example 19
Project: openjdk-jdk10   File: TCKLocalDate.java   View Source Code Vote up 4 votes
@Test(expectedExceptions=DateTimeException.class)
public void factory_of_ints_monthTooLow() {
    LocalDate.of(2007, 0, 1);
}
 
Example 20
Project: jdk8u-jdk   File: TestMonthDay.java   View Source Code Vote up 4 votes
@Test
public void test_adjustDate_same() {
    MonthDay test = MonthDay.of(6, 30);
    LocalDate date = LocalDate.of(2007, 6, 30);
    assertSame(test.adjustInto(date), date);
}