orNull

actual fun orNull(hour: Int, minute: Int, second: Int, nanosecond: Int): LocalTime?(source)

Constructs a LocalTime instance from the given time components or returns null if a value is out of range.

The supported ranges of components:

Use LocalTime(hour, minute, second, nanosecond) to throw an exception instead of returning null when the parameters are invalid.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Constructing a LocalTime value using `orNull`
val time = LocalTime.orNull(8, 30, 15, 123_456_789)
// For valid values, `orNull` is equivalent to the constructor
check(time == LocalTime(8, 30, 15, 123_456_789))
// If a value can not be constructed, null is returned
check(LocalTime.orNull(24, 30) == null)
check(LocalTime.orNull(8, 60) == null)
check(LocalTime.orNull(8, 30, 60) == null)
check(LocalTime.orNull(8, 30, 15, 1_000_000_000) == null) 
   //sampleEnd
}
expect fun orNull(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0): LocalTime?(source)

Constructs a LocalTime instance from the given time components or returns null if a value is out of range.

The supported ranges of components:

Use LocalTime(hour, minute, second, nanosecond) to throw an exception instead of returning null when the parameters are invalid.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Constructing a LocalTime value using `orNull`
val time = LocalTime.orNull(8, 30, 15, 123_456_789)
// For valid values, `orNull` is equivalent to the constructor
check(time == LocalTime(8, 30, 15, 123_456_789))
// If a value can not be constructed, null is returned
check(LocalTime.orNull(24, 30) == null)
check(LocalTime.orNull(8, 60) == null)
check(LocalTime.orNull(8, 30, 60) == null)
check(LocalTime.orNull(8, 30, 15, 1_000_000_000) == null) 
   //sampleEnd
}
actual fun orNull(hour: Int, minute: Int, second: Int, nanosecond: Int): LocalTime?(source)

Constructs a LocalTime instance from the given time components or returns null if a value is out of range.

The supported ranges of components:

Use LocalTime(hour, minute, second, nanosecond) to throw an exception instead of returning null when the parameters are invalid.

Samples

import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*

fun main() { 
   //sampleStart 
   // Constructing a LocalTime value using `orNull`
val time = LocalTime.orNull(8, 30, 15, 123_456_789)
// For valid values, `orNull` is equivalent to the constructor
check(time == LocalTime(8, 30, 15, 123_456_789))
// If a value can not be constructed, null is returned
check(LocalTime.orNull(24, 30) == null)
check(LocalTime.orNull(8, 60) == null)
check(LocalTime.orNull(8, 30, 60) == null)
check(LocalTime.orNull(8, 30, 15, 1_000_000_000) == null) 
   //sampleEnd
}