本文整理匯總了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;
}
示例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.");
}
}
示例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!");
}
}
示例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);
}
示例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);
}
}
示例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";
}
}
示例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";
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
示例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++;
}
}
示例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
}
示例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);
}