当前位置: 首页>>代码示例>>Java>>正文


Java LocalDate.plus方法代码示例

本文整理汇总了Java中java.time.LocalDate.plus方法的典型用法代码示例。如果您正苦于以下问题:Java LocalDate.plus方法的具体用法?Java LocalDate.plus怎么用?Java LocalDate.plus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.time.LocalDate的用法示例。


在下文中一共展示了LocalDate.plus方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: split

import java.time.LocalDate; //导入方法依赖的package包/类
/**
 * Splits the given period into multiple slices of one month long.
 *
 * @param start the start of the period.
 * @param end   the end of the period.
 * @return The list of slices result of the splitting.
 */
public static List<Slice> split(LocalDate start, LocalDate end) {
    Objects.requireNonNull(start);
    Objects.requireNonNull(end);
    Preconditions.checkArgument(!start.isAfter(end));

    List<Slice> slices = Lists.newArrayList();

    LocalDate startOfMonth = start.withDayOfMonth(1);
    LocalDate endOfMonth = YearMonth.from(end).atEndOfMonth();

    do {
        slices.add(new Slice(startOfMonth, YearMonth.from(startOfMonth).atEndOfMonth()));
        startOfMonth = startOfMonth.plus(1, ChronoUnit.MONTHS);
    }
    while (startOfMonth.isBefore(endOfMonth) || startOfMonth.isEqual(endOfMonth));

    return slices;
}
 
开发者ID:dlemmermann,项目名称:CalendarFX,代码行数:26,代码来源:Slice.java

示例2: isReturnExtensionAllowed

import java.time.LocalDate; //导入方法依赖的package包/类
private void isReturnExtensionAllowed() {
    LocalDate today = LocalDate.now();
    LocalDate next2Week = today.plus(2, ChronoUnit.WEEKS);
    
    if(bookDetails.getReturn_date().toLocalDate().isBefore(today)) {
        extend.setDisable(true);
        warning.setTextFill(Color.web("#FF0000"));
        warning.setText("Return date has passed!");
        if(bookDetails.getFee_applied() == 0) {
            user.updateUserBalance(bookDetails.getUser_id(), -2.75);
            borrowed.updateFeeAppliedToTrue(bookDetails.getId());
        }
        
    }
    else if(bookDetails.getReturn_date().toLocalDate().isAfter(next2Week)) {
        extend.setDisable(true);
        warning.setTextFill(Color.web("#FF0000"));
        warning.setText("Return date is longer than 2 weeks.");
    }
}
 
开发者ID:bartoszgajda55,项目名称:IP1,代码行数:21,代码来源:BorrowedDetailsController.java

示例3: borrowBook

import java.time.LocalDate; //导入方法依赖的package包/类
@FXML
private void borrowBook(ActionEvent event) {
    if(!borrowed.isBookBorrowedAlready(Main.getId(), this.bookId)) {
        LocalDate today = LocalDate.now();
        LocalDate next2Week = today.plus(2, ChronoUnit.WEEKS);

        borrowed.addNewBorrowedBook(Main.getId(), this.bookId, today.toString(), next2Week.toString());
        book.updateBookQuantity(this.bookId, -1);

        quantity.setText(Integer.toString(bookDetails.getQuantity() - 1));
        warning.setTextFill(Color.web("#00FF00"));
        warning.setText("Book successfully borrowed!");

        this.isBorrowOrRequestAllowed();
    } else {
        warning.setTextFill(Color.web("#FF0000"));
        warning.setText("Book borrowed already!");
    }
}
 
开发者ID:bartoszgajda55,项目名称:IP1,代码行数:20,代码来源:SearchDetailsController.java

示例4: performDateMath

import java.time.LocalDate; //导入方法依赖的package包/类
private DateCalculatorResult performDateMath(final DateToken startDateToken, final OperatorToken operatorToken,
            final Queue<Token> tokens) {
        LocalDate result = startDateToken.getValue();
        int negate = operatorToken.isAddition() ? 1 : -1;
//    assertThat(tokens.size() % 2 == 0,
//            "Date math requires that all right hand values be pairs of units and units of measure (e.g., '2 weeks'");

        while (!tokens.isEmpty()) {
            validateToken(tokens.peek(), IntegerToken.class);
            int amount = ((IntegerToken) tokens.poll()).getValue() * negate;
            validateToken(tokens.peek(), UnitOfMeasureToken.class);
            result = result.plus(amount, ((UnitOfMeasureToken) tokens.poll()).getValue());
        }

        return new DateCalculatorResult(result);
    }
 
开发者ID:PacktPublishing,项目名称:Java-9-Programming-Blueprints,代码行数:17,代码来源:DateCalculator.java

示例5: test_IsoChrono_vsCalendar

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider = "RangeVersusCalendar")
public void test_IsoChrono_vsCalendar(LocalDate isoStartDate, LocalDate isoEndDate) {
    GregorianCalendar cal = new GregorianCalendar();
    assertEquals(cal.getCalendarType(), "gregory", "Unexpected calendar type");
    LocalDate isoDate = IsoChronology.INSTANCE.date(isoStartDate);

    cal.setTimeZone(TimeZone.getTimeZone("GMT+00"));
    cal.set(Calendar.YEAR, isoDate.get(YEAR));
    cal.set(Calendar.MONTH, isoDate.get(MONTH_OF_YEAR) - 1);
    cal.set(Calendar.DAY_OF_MONTH, isoDate.get(DAY_OF_MONTH));

    while (isoDate.isBefore(isoEndDate)) {
        assertEquals(isoDate.get(DAY_OF_MONTH), cal.get(Calendar.DAY_OF_MONTH), "Day mismatch in " + isoDate + ";  cal: " + cal);
        assertEquals(isoDate.get(MONTH_OF_YEAR), cal.get(Calendar.MONTH) + 1, "Month mismatch in " + isoDate);
        assertEquals(isoDate.get(YEAR_OF_ERA), cal.get(Calendar.YEAR), "Year mismatch in " + isoDate);

        isoDate = isoDate.plus(1, ChronoUnit.DAYS);
        cal.add(Calendar.DAY_OF_MONTH, 1);
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:21,代码来源:TestIsoChronoImpl.java

示例6: getProfNotifications

import java.time.LocalDate; //导入方法依赖的package包/类
@GetMapping(value = "/prof/noti")
public String getProfNotifications(Model model) {
    try {
        LocalDate currDate = LocalDate.now();
        if (currDate.getDayOfWeek().equals(DayOfWeek.SATURDAY)
                || currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY))
            currDate = currDate.plus(3, ChronoUnit.DAYS);

        LocalDate startDateOfSchoolWeek = currDate.with(DayOfWeek.MONDAY);

        String profEmail = authFacade.getAuthentication().getName();
        Professor prof = professorService.getProfessorByEmail(profEmail);

        List<BookingSlot> profBookings
                = bookingSlotService.getSlotsByProfAndSWeek(prof.getAlias(), startDateOfSchoolWeek);

        model.addAttribute("bookings", filterBookingSlots(profBookings));
        return "fragments/prof_noti";

    } catch (Exception ex) {
        ex.printStackTrace();

        model.addAttribute("message", ex.toString());
        return "error";
    }
}
 
开发者ID:ericywl,项目名称:InfoSys-1D,代码行数:27,代码来源:ProfCalendarController.java

示例7: getStudentNotifications

import java.time.LocalDate; //导入方法依赖的package包/类
@GetMapping(value = "/student/noti")
public String getStudentNotifications(Model model) {
    try {
        LocalDate currDate = LocalDate.now();
        if (currDate.getDayOfWeek().equals(DayOfWeek.SATURDAY)
                || currDate.getDayOfWeek().equals(DayOfWeek.SUNDAY))
            currDate = currDate.plus(3, ChronoUnit.DAYS);

        LocalDate startDateOfSchoolWeek = currDate.with(DayOfWeek.MONDAY);

        String studentEmail = authFacade.getAuthentication().getName();
        Student student = studentService.getStudentByEmail(studentEmail);

        List<BookingSlot> studentBookings
                = bookingSlotService.getSlotsByStudentAndSWeek(student.getId(), startDateOfSchoolWeek);

        model.addAttribute("bookings", filterStudentBookings(studentBookings));
        return "fragments/student_noti";

    } catch (Exception ex) {
        ex.printStackTrace();

        model.addAttribute("message", ex.toString());
        return "error";
    }
}
 
开发者ID:ericywl,项目名称:InfoSys-1D,代码行数:27,代码来源:StudentCalendarController.java

示例8: createStudentCourseCalMatrix

import java.time.LocalDate; //导入方法依赖的package包/类
private List<List<String>> createStudentCourseCalMatrix(String courseId, int studentId,
                                                        LocalDate startDateOfSchoolWeek) {
    List<BookingSlot> slotList = slotService.getSlotsByCourseAndSWeek(courseId, startDateOfSchoolWeek);
    List<List<String>> output = new ArrayList<>();
    List<String> temp;

    for (int i = 0; i < WEEK_CAL_ROW; i++) {
        LocalTime timePart = ROW_TO_TIME.get(i);
        String timeRange = timeRangeFormat(timePart);

        temp = new ArrayList<>();
        temp.add(timeRange);

        for (int j = 0; j < WEEK_CAL_COL; j++) {
            LocalDate datePart = startDateOfSchoolWeek.plus(j, ChronoUnit.DAYS);
            LocalDateTime dateTime = LocalDateTime.of(datePart, timePart);

            temp.add(createStudentCourseCalString(dateTime, slotList, studentId));
        }

        output.add(temp);
    }

    return output;
}
 
开发者ID:ericywl,项目名称:InfoSys-1D,代码行数:26,代码来源:WeekCalendarServiceImpl.java

示例9: createStudentProfCalMatrix

import java.time.LocalDate; //导入方法依赖的package包/类
private List<List<String>> createStudentProfCalMatrix(String profAlias, LocalDate startDateOfSchoolWeek,
                                                      int studentId) {

    List<BookingSlot> slotList = slotService.getSlotsByProfAndSWeek(profAlias, startDateOfSchoolWeek);
    List<List<String>> output = new ArrayList<>();
    List<String> temp;

    for (int i = 0; i < WEEK_CAL_ROW; i++) {
        LocalTime timePart = ROW_TO_TIME.get(i);
        String timeRange = timeRangeFormat(timePart);

        temp = new ArrayList<>();
        temp.add(timeRange);

        for (int j = 0; j < WEEK_CAL_COL; j++) {
            LocalDate datePart = startDateOfSchoolWeek.plus(j, ChronoUnit.DAYS);
            LocalDateTime dateTime = LocalDateTime.of(datePart, timePart);

            temp.add(createStudentProfCalString(dateTime, slotList, studentId));
        }

        output.add(temp);
    }

    return output;
}
 
开发者ID:ericywl,项目名称:InfoSys-1D,代码行数:27,代码来源:WeekCalendarServiceImpl.java

示例10: createProfCalMatrix

import java.time.LocalDate; //导入方法依赖的package包/类
private List<List<String>> createProfCalMatrix(String profAlias, LocalDate startDateOfSchoolWeek) {
    List<BookingSlot> slotList = slotService.getSlotsByProfAndSWeek(profAlias, startDateOfSchoolWeek);
    List<List<String>> output = new ArrayList<>();
    List<String> temp;

    for (int i = 0; i < WEEK_CAL_ROW; i++) {
        LocalTime timePart = ROW_TO_TIME.get(i);
        String timeRange = timeRangeFormat(timePart);

        temp = new ArrayList<>();
        temp.add(timeRange);

        for (int j = 0; j < WEEK_CAL_COL; j++) {
            LocalDate datePart = startDateOfSchoolWeek.plus(j, ChronoUnit.DAYS);
            LocalDateTime dateTime = LocalDateTime.of(datePart, timePart);

            temp.add(createProfCalString(dateTime, slotList));
        }

        output.add(temp);
    }

    return output;
}
 
开发者ID:ericywl,项目名称:InfoSys-1D,代码行数:25,代码来源:WeekCalendarServiceImpl.java

示例11: getSlotsByStudentAndSWeek

import java.time.LocalDate; //导入方法依赖的package包/类
@Override
// Get slots by student and the week (5-day school week) specified
public List<BookingSlot> getSlotsByStudentAndSWeek(int studentId, LocalDate startDateOfSchoolWeek) {
    LocalDate endDateOfSchoolWeek = startDateOfSchoolWeek.plus(5, ChronoUnit.DAYS);
    List<BookingSlot> studentSlots = getSlotsByStudentId(studentId);
    List<BookingSlot> output = new ArrayList<>();

    for (BookingSlot slot : studentSlots) {
        if (!(slot.getDate().isBefore(startDateOfSchoolWeek)
                || slot.getDate().isAfter(endDateOfSchoolWeek)))

            if (!slot.getBookStatus().equalsIgnoreCase(CANCELLED)) output.add(slot);
    }

    return output;
}
 
开发者ID:ericywl,项目名称:InfoSys-1D,代码行数:17,代码来源:BookingSlotServiceImpl.java

示例12: testRangeOfLocalDates

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider = "localDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
    final Range<LocalDate> range = Range.of(start, end, step);
    final Array<LocalDate> array = range.toArray(parallel);
    final boolean ascend = start.isBefore(end);
    final int expectedLength = (int)Math.ceil(Math.abs((double)ChronoUnit.DAYS.between(start, end)) / (double)step.getDays());
    Assert.assertEquals(array.length(), expectedLength);
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    LocalDate expected = null;
    for (int i=0; i<array.length(); ++i) {
        final LocalDate actual = array.getValue(i);
        expected = expected == null ? start : ascend ? expected.plus(step) : expected.minus(step);
        Assert.assertEquals(actual, expected, "Value matches at " + i);
        Assert.assertTrue(ascend ? actual.compareTo(start) >=0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + i);
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:20,代码来源:RangeBasicTests.java

示例13: testRangeOfLocalDates

import java.time.LocalDate; //导入方法依赖的package包/类
@Test(dataProvider = "LocalDateRanges")
public void testRangeOfLocalDates(LocalDate start, LocalDate end, Period step, boolean parallel) {
    final boolean ascend = start.isBefore(end);
    final Range<LocalDate> range = Range.of(start, end, step, v -> v.getDayOfWeek() == DayOfWeek.MONDAY);
    final Array<LocalDate> array = range.toArray(parallel);
    final LocalDate first = array.first(v -> true).map(ArrayValue::getValue).get();
    final LocalDate last = array.last(v -> true).map(ArrayValue::getValue).get();
    Assert.assertEquals(array.typeCode(), ArrayType.LOCAL_DATE);
    Assert.assertTrue(!array.style().isSparse());
    Assert.assertEquals(range.start(), start, "The range start");
    Assert.assertEquals(range.end(), end, "The range end");
    int index = 0;
    LocalDate value = first;
    while (ascend ? value.isBefore(last) : value.isAfter(last)) {
        final LocalDate actual = array.getValue(index);
        Assert.assertEquals(actual, value, "Value matches at " + index);
        Assert.assertTrue(ascend ? actual.compareTo(start) >= 0 && actual.isBefore(end) : actual.compareTo(start) <= 0 && actual.isAfter(end), "Value in bounds at " + index);
        value = ascend ? value.plus(step) : value.minus(step);
        while (value.getDayOfWeek() == DayOfWeek.MONDAY) value = ascend ? value.plus(step) : value.minus(step);
        index++;
    }
}
 
开发者ID:zavtech,项目名称:morpheus-core,代码行数:23,代码来源:RangeFilterTests.java

示例14: localDate

import java.time.LocalDate; //导入方法依赖的package包/类
public static void localDate() {

        LocalDate now = LocalDate.now();
        LocalDate plus = now.plus(1, ChronoUnit.DAYS);
        LocalDate minus = now.minusDays(1);

        System.out.println(now); //2017-09-20
        System.out.println(plus); //2017-09-21
        System.out.println(minus); //2017-09-19

        LocalDate customDate = LocalDate.of(2017, Month.SEPTEMBER, 20);
        DayOfWeek dayOfWeek = customDate.getDayOfWeek();
        System.out.println(dayOfWeek); //WEDNESDAY 星期三

        DateTimeFormatter dateTimeFormatter = DateTimeFormatter
                .ofLocalizedDate(FormatStyle.MEDIUM)
                .withLocale(Locale.CHINA);
        LocalDate parse = LocalDate.parse("2017-09-20", dateTimeFormatter);
        System.out.println(parse); //2017-09-20
    }
 
开发者ID:daishicheng,项目名称:outcomes,代码行数:21,代码来源:Main.java

示例15: borrowBook

import java.time.LocalDate; //导入方法依赖的package包/类
@FXML
private void borrowBook(ActionEvent event) {
    LocalDate today = LocalDate.now();
    LocalDate next2Week = today.plus(2, ChronoUnit.WEEKS);
    
    requested.deleteBookRequest(this.requestId);
    book.updateBookQuantity(requestedDetails.getBook_id(), -1);
    borrowed.addNewBorrowedBook(Main.getId(), requestedDetails.getBook_id(), today.toString(), next2Week.toString());
    
    this.close(event);
}
 
开发者ID:bartoszgajda55,项目名称:IP1,代码行数:12,代码来源:RequestedDetailsController.java


注:本文中的java.time.LocalDate.plus方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。