lastOrNull

Returns the last LocalDate of the LocalDateProgression, or null if the progression is empty.

Samples

import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test

fun main() { 
   //sampleStart 
   // Getting the first and last elements of a LocalDateProgression
check((LocalDate(2000, 1, 1)..LocalDate(2000, 1, 5)).first() == LocalDate(2000, 1, 1))
check((LocalDate(2000, 1, 1)..LocalDate(2000, 1, 5)).last() == LocalDate(2000, 1, 5))
check((LocalDate(2000, 1, 1)..LocalDate(2000, 1, 6)).step(2, DateTimeUnit.DAY).first() == LocalDate(2000, 1, 1))
check((LocalDate(2000, 1, 1)..LocalDate(2000, 1, 6)).step(2, DateTimeUnit.DAY).last() == LocalDate(2000, 1, 5))
check((LocalDate(2000, 1, 5)..LocalDate(2000, 1, 1)).firstOrNull() == null)
check((LocalDate(2000, 1, 5)..LocalDate(2000, 1, 1)).lastOrNull() == null) 
   //sampleEnd
}

Returns the last YearMonth of the YearMonthProgression, or null if the progression is empty.

Samples

import kotlinx.datetime.*
import kotlin.random.Random
import kotlin.test.Test

fun main() { 
   //sampleStart 
   // Getting the first and last elements of a YearMonthProgression
check((YearMonth(2000, 1)..YearMonth(2000, 5)).first() == YearMonth(2000, 1))
check((YearMonth(2000, 1)..YearMonth(2000, 5)).last() == YearMonth(2000, 5))
check((YearMonth(2000, 1)..YearMonth(2000, 6)).step(2, DateTimeUnit.MONTH).first() == YearMonth(2000, 1))
check((YearMonth(2000, 1)..YearMonth(2000, 6)).step(2, DateTimeUnit.MONTH).last() == YearMonth(2000, 5))
check((YearMonth(2000, 5)..YearMonth(2000, 1)).firstOrNull() == null)
check((YearMonth(2000, 5)..YearMonth(2000, 1)).lastOrNull() == null) 
   //sampleEnd
}