is Distant Past
Начиная с Kotlin: 2.3
val Instant.isDistantPast: Boolean
Возвращает true, если момент времени равен Instant.DISTANT_PAST или находится в прошлом относительно него.
Примеры
import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.nanoseconds
import kotlin.time.Duration.Companion.seconds
fun main() {
//sampleStart
// Checking if an instant is so far in the past that it's probably irrelevant.
val tenThousandYearsBC = Instant.parse("-10000-01-01T00:00:00Z")
println(tenThousandYearsBC.isDistantPast) // false
// Instant.DISTANT_PAST is the latest instant that is considered far in the past.
println(Instant.DISTANT_PAST) // -100001-12-31T23:59:59.999999999Z
println(Instant.DISTANT_PAST.isDistantPast) // true
// All instants earlier than Instant.DISTANT_PAST are considered to be far in the past.
val earlierThanDistantPast = Instant.DISTANT_PAST - 1.nanoseconds
println(earlierThanDistantPast) // -100001-12-31T23:59:59.999999998Z
println(earlierThanDistantPast.isDistantPast) // true
// All instants later than Instant.DISTANT_PAST are not considered to be far in the past.
val laterThanDistantPast = Instant.DISTANT_PAST + 1.nanoseconds
println(laterThanDistantPast) // -100000-01-01T00:00:00Z
println(laterThanDistantPast.isDistantPast) // false
//sampleEnd
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.time/is-distant-past.html