當前位置: 首頁>>代碼示例>>Java>>正文


Java LocalDate.plusDays方法代碼示例

本文整理匯總了Java中java.time.LocalDate.plusDays方法的典型用法代碼示例。如果您正苦於以下問題:Java LocalDate.plusDays方法的具體用法?Java LocalDate.plusDays怎麽用?Java LocalDate.plusDays使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.time.LocalDate的用法示例。


在下文中一共展示了LocalDate.plusDays方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: shouldChangeSelectionFromTodayToTomorrow

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void shouldChangeSelectionFromTodayToTomorrow() {
    // Given
    LocalDate now = LocalDate.now();
    LocalDate tomorrow = now.plusDays(1);
    DateSelectionModel model = new DateSelectionModel();
    model.setSelectionMode(SelectionMode.SINGLE_DATE);

    // When
    model.select(now);
    model.select(tomorrow);

    // Then
    assertFalse(model.isEmpty());
    assertThat(model.getSelectedDates(), is(not(empty())));
    assertThat(model.getSelectedDates().size(), is(equalTo(1)));
    assertThat(model.getSelectedDates(), contains(tomorrow));
    assertThat(model.getLastSelected(), is(equalTo(tomorrow)));
    assertFalse(model.isSelected(now));
    assertTrue(model.isSelected(tomorrow));
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:22,代碼來源:DateSelectionModelTests.java

示例2: test_parse_resolve_localizedWomDow

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWomDow(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField womField = week.weekOfMonth();

    for (int i = 1; i <= 15; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(YEAR).appendLiteral(':')
                .appendValue(MONTH_OF_YEAR).appendLiteral(':')
                .appendValue(womField).appendLiteral(':')
                .appendValue(dowField).toFormatter();
        String str = date.getYear() + ":" + date.getMonthValue() + ":" +
                date.get(womField) + ":" + date.get(dowField);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);

        date = date.plusDays(1);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:22,代碼來源:TCKWeekFields.java

示例3: selectRange

import java.time.LocalDate; //導入方法依賴的package包/類
@Override
public void selectRange(LocalDate start, LocalDate end) {
    if (start == null || end == null || start.isAfter(end)) {
        return;
    }

    List<LocalDate> toSelect = new ArrayList<>();
    while (start.isBefore(end) || start.equals(end)) {
        if (!model.selectedDates.contains(start)) {
            toSelect.add(start);
        }
        start = start.plusDays(1);
    }

    model.selectedDates.addAll(toSelect);
    model.lastSelected = toSelect.get(toSelect.size() - 1);
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:18,代碼來源:DateSelectionModel.java

示例4: addEntryToResult

import java.time.LocalDate; //導入方法依賴的package包/類
private void addEntryToResult(Map<LocalDate, List<Entry<?>>> result, Entry<?> entry, LocalDate startDate, LocalDate endDate) {
    LocalDate entryStartDate = entry.getStartDate();
    LocalDate entryEndDate = entry.getEndDate();

    // entry does not intersect with time interval
    if (entryEndDate.isBefore(startDate) || entryStartDate.isAfter(endDate)) {
        return;
    }

    if (entryStartDate.isAfter(startDate)) {
        startDate = entryStartDate;
    }

    if (entryEndDate.isBefore(endDate)) {
        endDate = entryEndDate;
    }

    LocalDate date = startDate;
    do {
        result.computeIfAbsent(date, it -> new ArrayList<>()).add(entry);
        date = date.plusDays(1);
    } while (!date.isAfter(endDate));
}
 
開發者ID:dlemmermann,項目名稱:CalendarFX,代碼行數:24,代碼來源:Calendar.java

示例5: test_plusHours_fromOne

import java.time.LocalDate; //導入方法依賴的package包/類
@Test
public void test_plusHours_fromOne() {
    LocalDateTime base = TEST_2007_07_15_12_30_40_987654321.with(LocalTime.of(1, 0));
    LocalDate d = base.toLocalDate().minusDays(3);
    LocalTime t = LocalTime.of(22, 0);

    for (int i = -50; i < 50; i++) {
        LocalDateTime dt = base.plusHours(i);

        t = t.plusHours(1);

        if (t.getHour() == 0) {
            d = d.plusDays(1);
        }

        assertEquals(dt.toLocalDate(), d);
        assertEquals(dt.toLocalTime(), t);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:TCKLocalDateTime.java

示例6: test_parse_resolve_localizedWoWBYDow

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoWBYDow(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 31);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField wowbyField = week.weekOfWeekBasedYear();
    TemporalField yowbyField = week.weekBasedYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(yowbyField).appendLiteral(':')
                .appendValue(wowbyField).appendLiteral(':')
                .appendValue(dowField).toFormatter();
        String str = date.get(yowbyField) + ":" + date.get(wowbyField) + ":" +
                date.get(dowField);
        LocalDate parsed = LocalDate.parse(str, f);
        assertEquals(parsed, date, " :: " + str + " " + i);

        date = date.plusDays(1);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:TCKWeekFields.java

示例7: test_parse_resolve_localizedWoyDow_lenient

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider="weekFields")
public void test_parse_resolve_localizedWoyDow_lenient(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate date = LocalDate.of(2012, 12, 15);
    WeekFields week = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = week.dayOfWeek();
    TemporalField woyField = week.weekOfYear();

    for (int i = 1; i <= 60; i++) {
        DateTimeFormatter f = new DateTimeFormatterBuilder()
                .appendValue(YEAR).appendLiteral(':')
                .appendValue(woyField).appendLiteral(':')
                .appendValue(dowField).toFormatter().withResolverStyle(LENIENT);
        int woy = date.get(woyField);
        int dow = date.get(dowField);
        for (int j = woy - 60; j < woy + 60; j++) {
            String str = date.getYear() + ":" + j + ":" + dow;
            LocalDate parsed = LocalDate.parse(str, f);
            assertEquals(parsed, date.plusWeeks(j - woy), " ::" + str + ": :" + i + "::" + j);
        }

        date = date.plusDays(1);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:24,代碼來源:TCKWeekFields.java

示例8: testSplitLocalDate

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "directions")
public void testSplitLocalDate(boolean ascending) {
    final Period step = Period.ofDays(1);
    final LocalDate start = LocalDate.of(1990, 1, 1);
    final LocalDate end = ascending ? start.plusDays(10000) : start.minusDays(10000);
    final Range<LocalDate> range = Range.of(start, end, step);
    final List<Range<LocalDate>> segments = range.split(100);
    Assert.assertTrue(segments.size() > 1, "There are multiple segments");
    for (int i=1; i<segments.size(); ++i) {
        final Range<LocalDate> prior = segments.get(i-1);
        final Range<LocalDate> next = segments.get(i);
        Assert.assertEquals(prior.end(), next.start(), "Date connect as expect");
        if (i == 1) Assert.assertEquals(prior.start(), range.start(), "First segment start matches range start");
        if (i == segments.size()-1) {
            Assert.assertEquals(next.end(), range.end(), "Last segment end matches range end");
        }
    }
}
 
開發者ID:zavtech,項目名稱:morpheus-core,代碼行數:19,代碼來源:RangeSplitTests.java

示例9: nextOpeningDay

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Returns next opening relative to passed date. If the mensa is open on that day, the date is returned
 * @param date to find next opening day for
 * @param mensa to check
 * @return next opening relative to passed date
 */
public LocalDate nextOpeningDay(LocalDate date, Mensa mensa) {
    LocalDate result = date;
    while (!isOpeningDay(result, mensa)) {
        result = result.plusDays(1);
    }
    return result;
}
 
開發者ID:xabgesagtx,項目名稱:mensa-api,代碼行數:14,代碼來源:TimeUtils.java

示例10: test_adjustInto_week

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "fields")
public void test_adjustInto_week(TemporalField weekField, TemporalField yearField) {
    // tests every day from 2012 to 2016 inclusive
    LocalDate date = LocalDate.of(2012, 1, 2);
    int wby = 2012;
    int week = 1;
    int dow = 1;
    for (int i = 1; i <= ((52 + 52 + 52 + 53 + 52) * 7); i++) {
        int weeksInYear = (wby == 2015 ? 53 : 52);
        for (int j = 1; j <= weeksInYear; j++) {
            LocalDate adjusted = weekField.adjustInto(date, j);
            assertEquals(adjusted.get(weekField), j);
            assertEquals(adjusted.get(DAY_OF_WEEK), dow);
            assertEquals(adjusted.get(yearField), wby);
        }
        if (dow == 7) {
            dow = 1;
            week++;
        } else {
            dow++;
        }
        if (week > wbyLen(wby)) {
            week = 1;
            wby++;
        }
        date = date.plusDays(1);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:29,代碼來源:TestIsoWeekFields.java

示例11: test_weekOfWeekBasedYearField

import java.time.LocalDate; //導入方法依賴的package包/類
/**
 * Verify that the date can be reconstructed from the DOW, WeekOfWeekBasedYear,
 * and WeekBasedYear for every combination of start of week
 * and minimal days in week.
 * @param firstDayOfWeek the first day of the week
 * @param minDays the minimum number of days in the week
 */
@Test(dataProvider="weekFields")
public void test_weekOfWeekBasedYearField(DayOfWeek firstDayOfWeek, int minDays) {
    LocalDate day = LocalDate.of(2012, 12, 31);  // Known to be ISO Monday
    WeekFields weekDef = WeekFields.of(firstDayOfWeek, minDays);
    TemporalField dowField = weekDef.dayOfWeek();
    TemporalField wowbyField = weekDef.weekOfWeekBasedYear();
    TemporalField yowbyField = weekDef.weekBasedYear();

    for (int i = 1; i <= 15; i++) {
        int actualDOW = day.get(dowField);
        int actualWOWBY = day.get(wowbyField);
        int actualYOWBY = day.get(yowbyField);

        // Verify that the combination of day of week and week of month can be used
        // to reconstruct the same date.
        LocalDate day1 = LocalDate.of(actualYOWBY, 1, 1);
        DayOfWeek isoDOW = day1.getDayOfWeek();
        int dow = (7 + isoDOW.getValue() - firstDayOfWeek.getValue()) % 7 + 1;

        int weekStart = Math.floorMod(1 - dow, 7);
        if (weekStart + 1 > weekDef.getMinimalDaysInFirstWeek()) {
            // The previous week has the minimum days in the current month to be a 'week'
            weekStart -= 7;
        }
        weekStart += actualDOW - 1;
        weekStart += (actualWOWBY - 1) * 7;
        LocalDate result = day1.plusDays(weekStart);

        assertEquals(result, day, "Incorrect dayOfWeek or weekOfYear "
                + String.format("%s, ISO Dow: %s, weekStart: %s, actualDOW: %s, actualWOWBY: %s, YearOfWBY: %d, expected day: %s, result: %s%n",
                weekDef, day.getDayOfWeek(), weekStart, actualDOW, actualWOWBY, actualYOWBY, day, result));
        day = day.plusDays(1);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:42,代碼來源:TCKWeekFields.java

示例12: test_getFrom

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "fields")
public void test_getFrom(TemporalField weekField, TemporalField yearField) {
    // tests every day from 2011 to 2016 inclusive
    LocalDate date = LocalDate.of(2011, 1, 3);
    int wby = 2011;
    int week = 1;
    int dow = 1;
    for (int i = 1; i <= ((52 + 52 + 52 + 52 + 53 + 52) * 7); i++) {
        assertEquals(yearField.getFrom(date), wby);
        assertEquals(weekField.getFrom(date), week);
        assertEquals(DAY_OF_WEEK.getFrom(date), dow);
        if (dow == 7) {
            dow = 1;
            week++;
        } else {
            dow++;
        }
        if (week > wbyLen(wby)) {
            week = 1;
            wby++;
        }
        date = date.plusDays(1);
    }
    assertEquals(yearField.getFrom(date), 2017);
    assertEquals(weekField.getFrom(date), 1);
    assertEquals(DAY_OF_WEEK.getFrom(date), 1);
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:TestIsoWeekFields.java

示例13: test_adjustInto_dow

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "fields")
public void test_adjustInto_dow(TemporalField weekField, TemporalField yearField) {
    // tests every day from 2012 to 2016 inclusive
    LocalDate date = LocalDate.of(2012, 1, 2);
    int wby = 2012;
    int week = 1;
    int dow = 1;
    for (int i = 1; i <= ((52 + 52 + 52 + 53 + 52) * 7); i++) {
        for (int j = 1; j <= 7; j++) {
            LocalDate adjusted = DAY_OF_WEEK.adjustInto(date, j);
            assertEquals(adjusted.get(DAY_OF_WEEK), j);
            assertEquals(adjusted.get(weekField), week);
            assertEquals(adjusted.get(yearField), wby);
        }
        if (dow == 7) {
            dow = 1;
            week++;
        } else {
            dow++;
        }
        if (week > wbyLen(wby)) {
            week = 1;
            wby++;
        }
        date = date.plusDays(1);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:28,代碼來源:TestIsoWeekFields.java

示例14: test_addTo_weekBasedYears

import java.time.LocalDate; //導入方法依賴的package包/類
@Test(dataProvider = "fields")
public void test_addTo_weekBasedYears(TemporalField weekField, TemporalField yearField) {
    // tests every day from 2012 to 2016 inclusive
    LocalDate date = LocalDate.of(2012, 1, 2);
    int wby = 2012;
    int week = 1;
    int dow = 1;
    for (int i = 1; i <= ((52 + 52 + 52 + 53 + 52) * 7); i++) {
        for (int j = -5; j <= 5; j++) {
            LocalDate adjusted = IsoFields.WEEK_BASED_YEARS.addTo(date, j);
            assertEquals(adjusted.get(yearField), wby + j);
            assertEquals(adjusted.get(DAY_OF_WEEK), dow);
            assertEquals(adjusted.get(weekField), (week == 53 && wbyLen(wby + j) == 52 ? 52 : week), "" + date + " " + adjusted);
        }
        if (dow == 7) {
            dow = 1;
            week++;
        } else {
            dow++;
        }
        if (week > wbyLen(wby)) {
            week = 1;
            wby++;
        }
        date = date.plusDays(1);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:28,代碼來源:TestIsoWeekFields.java

示例15: test_atDay_notLeapYear

import java.time.LocalDate; //導入方法依賴的package包/類
@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);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:TCKYear.java


注:本文中的java.time.LocalDate.plusDays方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。