July 2018
Intermediate to advanced
242 pages
8h 6m
English
Now, we are able to declare range expressions for the LocalDate type. Let's see how to use our implementation. In the following example, we will use our custom LocalDate.rangeTo operator implementation in order to create a range of dates and iterate its elements:
val startDate = LocalDate.of(2020, 1, 1)val endDate = LocalDate.of(2020, 12, 31)for (date in startDate..endDate step 7) { println("${date.dayOfWeek} $date ")}
As a result, we are going to have the dates printed out to the console with a week-long interval:
WEDNESDAY 2020-01-01WEDNESDAY 2020-01-08WEDNESDAY 2020-01-15WEDNESDAY 2020-01-22WEDNESDAY 2020-01-29WEDNESDAY 2020-02-05...WEDNESDAY 2020-12-16WEDNESDAY 2020-12-23WEDNESDAY 2020-12-30
The DateIterator class holds ...
Read now
Unlock full access