Scala LocalDate.plusDays
Advance a calendar date by two days to set a delivery deadline.
A simple example
LocalDate.plusDays
- Start with 2024-01-31
- Do this Add one calendar day
- Result 2024-02-01
Syntax
arrival.plusDays(2)
Run these examples in Scala
Save one example at a time as Lesson.scala. Use Scala 2.13 on JDK 21.
scalac Lesson.scala
scala LessonCalculate a delivery date across leap day
A reservation spans the end of February in a leap year. The booking system must use actual calendar days so that the extra day appears in the schedule or stay length.
import java.time.LocalDate
object Lesson {
def main(args: Array[String]): Unit = {
val arrival = LocalDate.parse("2024-02-28")
println(arrival.plusDays(2))
}
}
2024-03-01
The day after February 28 is February 29 in 2024. One more day brings the date to March 1.
Return a borrowed microscope
A school lends a microscope two days before the end of February in a leap year. Parse the stated local calendar date and add the indicated number of days. Which date goes on the reminder?
Send a year-end reminder
A gallery schedules its reminder one day after the final day of the year. Parse the stated local calendar date and add the indicated number of days. Which date goes on the reminder?
What to watch for
Calendar days include weekends. A business-day promise needs a separate holiday and weekend policy.