@@ -6,7 +6,10 @@ import scala.annotation.tailrec
6
6
7
7
object DateListGenerator {
8
8
9
- def recursiveDateList (startDate : LocalDate , endDate : LocalDate ): List [LocalDate ] = {
9
+ def recursiveDateList (
10
+ startDate : LocalDate ,
11
+ endDate : LocalDate
12
+ ): List [LocalDate ] = {
10
13
@ tailrec
11
14
def findNextDate (
12
15
currentDate : LocalDate ,
@@ -21,30 +24,45 @@ object DateListGenerator {
21
24
findNextDate(startDate, Nil )
22
25
}
23
26
24
- def foldLeftDateList (startDate : LocalDate , endDate : LocalDate ): List [LocalDate ] = {
27
+ def foldLeftDateList (
28
+ startDate : LocalDate ,
29
+ endDate : LocalDate
30
+ ): List [LocalDate ] = {
25
31
val noOfDays = ChronoUnit .DAYS .between(startDate, endDate) + 1
26
32
(0 until noOfDays.toInt).foldLeft(List .empty[LocalDate ]) { (acc, incr) =>
27
33
acc :+ startDate.plusDays(incr)
28
34
}
29
35
}
30
36
31
- def iteratorDateList (startDate : LocalDate , endDate : LocalDate ): List [LocalDate ] = {
37
+ def iteratorDateList (
38
+ startDate : LocalDate ,
39
+ endDate : LocalDate
40
+ ): List [LocalDate ] = {
32
41
Iterator
33
42
.iterate(startDate)(_.plusDays(1 ))
34
43
.takeWhile(! _.isAfter(endDate))
35
44
.toList
36
45
}
37
46
38
- def tabulateDateList (startDate : LocalDate , endDate : LocalDate ): List [LocalDate ] = {
47
+ def tabulateDateList (
48
+ startDate : LocalDate ,
49
+ endDate : LocalDate
50
+ ): List [LocalDate ] = {
39
51
val noOfDays = ChronoUnit .DAYS .between(startDate, endDate) + 1
40
52
List .tabulate(noOfDays.toInt)(startDate.plusDays(_))
41
53
}
42
54
43
- def dateListEpochDays (startDate : LocalDate , endDate : LocalDate ): List [LocalDate ] = {
55
+ def dateListEpochDays (
56
+ startDate : LocalDate ,
57
+ endDate : LocalDate
58
+ ): List [LocalDate ] = {
44
59
startDate.toEpochDay.to(endDate.toEpochDay).map(LocalDate .ofEpochDay).toList
45
60
}
46
61
47
- def dateListDaysBetween (startDate : LocalDate , endDate : LocalDate ): List [LocalDate ] = {
62
+ def dateListDaysBetween (
63
+ startDate : LocalDate ,
64
+ endDate : LocalDate
65
+ ): List [LocalDate ] = {
48
66
val noOfDays = ChronoUnit .DAYS .between(startDate, endDate) + 1
49
67
(0 until noOfDays.toInt).map(startDate.plusDays(_)).toList
50
68
}
0 commit comments