orNull
Constructs a LocalDate instance from the given date components or returns null if a value is out of range or invalid.
The components month and day are 1-based.
The supported ranges of components:
year the range is at least enough to represent dates of all instants between Instant.DISTANT_PAST and Instant.DISTANT_FUTURE
month
1..12day
1..31, the upper bound can be less, depending on the month
Use LocalDate(year, month, day) 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 LocalDate value using `orNull`
val date = LocalDate.orNull(2024, 4, 16)
// For valid values, `orNull` is equivalent to the constructor
check(date == LocalDate(2024, 4, 16))
// If a value can not be constructed, null is returned
check(LocalDate.orNull(2024, 1, 99) == null)
//sampleEnd
}Constructs a LocalDate instance from the given date components or returns null if a value is out of range or invalid.
The supported ranges of components:
year the range at least is enough to represent dates of all instants between Instant.DISTANT_PAST and Instant.DISTANT_FUTURE
day
1..31, the upper bound can be less, depending on the month
Use LocalDate(year, month, day) 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 LocalDate value using `orNull`
val date = LocalDate.orNull(2024, Month.APRIL, 16)
// For valid values, `orNull` is equivalent to the constructor
check(date == LocalDate(2024, Month.APRIL, 16))
// If a value can not be constructed, null is returned
check(LocalDate.orNull(2024, Month.FEBRUARY, 31) == null)
//sampleEnd
}Constructs a LocalDate instance from the given date components or returns null if a value is out of range or invalid.
The components month and day are 1-based.
The supported ranges of components:
year the range is at least enough to represent dates of all instants between Instant.DISTANT_PAST and Instant.DISTANT_FUTURE
month
1..12day
1..31, the upper bound can be less, depending on the month
Use LocalDate(year, month, day) 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 LocalDate value using `orNull`
val date = LocalDate.orNull(2024, 4, 16)
// For valid values, `orNull` is equivalent to the constructor
check(date == LocalDate(2024, 4, 16))
// If a value can not be constructed, null is returned
check(LocalDate.orNull(2024, 1, 99) == null)
//sampleEnd
}Constructs a LocalDate instance from the given date components or returns null if a value is out of range or invalid.
The supported ranges of components:
year the range at least is enough to represent dates of all instants between Instant.DISTANT_PAST and Instant.DISTANT_FUTURE
day
1..31, the upper bound can be less, depending on the month
Use LocalDate(year, month, day) 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 LocalDate value using `orNull`
val date = LocalDate.orNull(2024, Month.APRIL, 16)
// For valid values, `orNull` is equivalent to the constructor
check(date == LocalDate(2024, Month.APRIL, 16))
// If a value can not be constructed, null is returned
check(LocalDate.orNull(2024, Month.FEBRUARY, 31) == null)
//sampleEnd
}Constructs a LocalDate instance from the given date components or returns null if a value is out of range or invalid.
The components month and day are 1-based.
The supported ranges of components:
year the range is at least enough to represent dates of all instants between Instant.DISTANT_PAST and Instant.DISTANT_FUTURE
month
1..12day
1..31, the upper bound can be less, depending on the month
Use LocalDate(year, month, day) 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 LocalDate value using `orNull`
val date = LocalDate.orNull(2024, 4, 16)
// For valid values, `orNull` is equivalent to the constructor
check(date == LocalDate(2024, 4, 16))
// If a value can not be constructed, null is returned
check(LocalDate.orNull(2024, 1, 99) == null)
//sampleEnd
}Constructs a LocalDate instance from the given date components or returns null if a value is out of range or invalid.
The supported ranges of components:
year the range at least is enough to represent dates of all instants between Instant.DISTANT_PAST and Instant.DISTANT_FUTURE
day
1..31, the upper bound can be less, depending on the month
Use LocalDate(year, month, day) 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 LocalDate value using `orNull`
val date = LocalDate.orNull(2024, Month.APRIL, 16)
// For valid values, `orNull` is equivalent to the constructor
check(date == LocalDate(2024, Month.APRIL, 16))
// If a value can not be constructed, null is returned
check(LocalDate.orNull(2024, Month.FEBRUARY, 31) == null)
//sampleEnd
}