step
Returns a LocalDateProgression with the same start and end, but a changed step value.
Pitfall: the value parameter represents the magnitude of the step, not the direction, and therefore must be positive. Its sign will be matched to the sign of the existing step, in order to maintain the direction of the progression. If you wish to switch the direction of the progression, use LocalDateProgression.reversed
Samples
import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test
fun main() {
//sampleStart
// Creating LocalDateProgression with a step size other than 1 day
check(
(LocalDate(2000, 1, 1)..LocalDate(2000, 1, 5)).step(2, DateTimeUnit.DAY).toList() == listOf(
LocalDate(2000, 1, 1),
LocalDate(2000, 1, 3),
LocalDate(2000, 1, 5)
))
check(
(LocalDate(2000, 1, 5) downTo LocalDate(2000, 1, 1)).step(2, DateTimeUnit.DAY).toList() == listOf(
LocalDate(2000, 1, 5),
LocalDate(2000, 1, 3),
LocalDate(2000, 1, 1)
))
//sampleEnd
}
Returns a YearMonthProgression with the same start and end, but a changed step value.
Pitfall: the value parameter represents the magnitude of the step, not the direction, and therefore must be positive. Its sign will be matched to the sign of the existing step, in order to maintain the direction of the progression. If you wish to switch the direction of the progression, use YearMonthProgression.reversed
Samples
import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test
fun main() {
//sampleStart
// Creating YearMonthProgression with a step size other than 1 day
check(
(YearMonth(2000, 1)..YearMonth(2000, 5)).step(2, DateTimeUnit.MONTH).toList() == listOf(
YearMonth(2000, 1),
YearMonth(2000, 3),
YearMonth(2000, 5)
))
check(
(YearMonth(2000, 5) downTo YearMonth(2000, 1)).step(2, DateTimeUnit.MONTH).toList() == listOf(
YearMonth(2000, 5),
YearMonth(2000, 3),
YearMonth(2000, 1)
))
//sampleEnd
}