first
Returns the first LocalDate of the LocalDateProgression.
Throws
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 first YearMonth of the YearMonthProgression.
Throws
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
}