Spec-Zone.ru › Kotlin 2

isDistantFuture

kotlin-stdlib/kotlin.time/isDistantFuture

Версия Kotlin: 2.3

val Instant.isDistantFuture: Boolean

Возвращает true, если момент времени равен Instant.DISTANT_FUTURE или является более поздним.

Примеры

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/is-distant-future.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API