-
Notifications
You must be signed in to change notification settings - Fork 119
Description
Per request I am opening an issue to explain #189
My use case comes from my recent exploration of the new Kotlin Spark API. In data engineering, a lot of batch jobs are parameterized with startDate
and endDate
. Processing the latest date of data in a daily task runner (such as Airflow) is done by feeding the same date as both startDate
and endDate
; processing a backfill is done by feeding an appropriate range to (re)process.
For some jobs it is necessary to iterate over every date in the range. This could be required if the relevant data files are organized by date in the S3/HDFS/etc path (s3://some-bucket/data_type/{date}/[00..n].parquet
), or if the job calls a process that is parameterized by a single date, or another reason.
As mentioned, there is a similar request for Instant Interval #34. I contemplated adding something similar in my pull request (specifically I considered doing for LocalDateTime
what I did for LocalDate
), but decided against it for the following reasons:
- The pattern used by the builtin Kotlin progressions requires a default step size.
Integer
s,Long
s, andChar
s all have a natural value for that step, because they are discrete.LocalDate
is likewise discrete, and therefore a progression with a step size of one day is a natural fit.LocalDateTime
is not discrete, and therefore there is no natural step size. Should(dateTime1..dateTime2).forEach { ... }
run for every second between the twoLocalDateTime
s? Every hour? Every nanosecond? - Without Kotlin's Progression concept being a good fit for
LocalDateTime
, there is still a valid use case for the general range semantics. However, most of that use case is already covered by the genericClosedRange<T : [Comparable]<T>>
that Kotlin gives you out of the box for anyComparable
.(dateTime1..dateTime2).contains(dateTime3)
is already provided free of charge. - Arithmetic on LocalDateTime is not provided. The reasons for this are likely the same reasons that a LocalDateTime progression is a bad idea.
The third reason does not apply to Instant
, but the first two reasons do. If others disagree that they are sufficient to preclude a use case for an InstantRange
that applies Kotlin's progression semantics, I can add it to my pull request. But for now I omitted it.