DISTANT_ FUTURE
Начиная с Kotlin: 2.3
val DISTANT_FUTURE: Instant
Момент времени, находящийся далеко в будущем.
isDistantFuture возвращает true для этого значения и всех более поздних значений.
Примеры
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 future that it's probably irrelevant.
val yearTenThousand = Instant.parse("+10000-01-01T00:00:00Z")
println(yearTenThousand.isDistantFuture) // false
// Instant.DISTANT_FUTURE is the earliest instant that is considered far in the future.
println(Instant.DISTANT_FUTURE) // +100000-01-01T00:00:00Z
println(Instant.DISTANT_FUTURE.isDistantFuture) // true
// All instants later than Instant.DISTANT_FUTURE are considered to be far in the future.
val laterThanDistantFuture = Instant.DISTANT_FUTURE + 1.nanoseconds
println(laterThanDistantFuture) // +100000-01-01T00:00:00.000000001Z
println(laterThanDistantFuture.isDistantFuture) // true
// All instants earlier than Instant.DISTANT_FUTURE are not considered to be far in the future.
val earlierThanDistantFuture = Instant.DISTANT_FUTURE - 1.nanoseconds
println(earlierThanDistantFuture) // +99999-12-31T23:59:59.999999999Z
println(earlierThanDistantFuture.isDistantFuture) // 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/-instant/-companion/-d-i-s-t-a-n-t_-f-u-t-u-r-e.html