isDistantPast

Returns true if the instant is Instant.DISTANT_PAST or earlier.

Since Kotlin

2.1

Samples

import kotlin.test.*
import kotlin.time.*
import kotlin.time.Duration.Companion.hours
import kotlin.time.Duration.Companion.nanoseconds

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
}