reversed
Returns a reversed LocalDateProgression, i.e. one that goes from last to first. The sign of the step is switched, in order to reverse the direction of the progression.
Samples
import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test
fun main() {
//sampleStart
// Creating LocalDateProgression and flipping its direction
check(
(LocalDate(2000, 1, 1)..LocalDate(2000, 1, 5)).reversed().toList() == listOf(
LocalDate(2000, 1, 5),
LocalDate(2000, 1, 4),
LocalDate(2000, 1, 3),
LocalDate(2000, 1, 2),
LocalDate(2000, 1, 1)
))
check(
(LocalDate(2000, 1, 5) downTo LocalDate(2000, 1, 1)).reversed().toList() == listOf(
LocalDate(2000, 1, 1),
LocalDate(2000, 1, 2),
LocalDate(2000, 1, 3),
LocalDate(2000, 1, 4),
LocalDate(2000, 1, 5)
))
//sampleEnd
}
Returns a reversed YearMonthProgression, i.e. one that goes from last to first. The sign of the step is switched, in order to reverse the direction of the progression.
Samples
import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test
fun main() {
//sampleStart
// Creating YearMonthProgression and flipping its direction
check(
(YearMonth(2000, 1)..YearMonth(2000, 5)).reversed().toList() == listOf(
YearMonth(2000, 5),
YearMonth(2000, 4),
YearMonth(2000, 3),
YearMonth(2000, 2),
YearMonth(2000, 1)
))
check(
(YearMonth(2000, 5) downTo YearMonth(2000, 1)).reversed().toList() == listOf(
YearMonth(2000, 1),
YearMonth(2000, 2),
YearMonth(2000, 3),
YearMonth(2000, 4),
YearMonth(2000, 5)
))
//sampleEnd
}