at Date
Combines this time's components with the specified date components into a LocalDateTime value.
There is no check of whether the time is valid on the specified date because that depends on the time zone, which this method does not accept.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
fun main() {
//sampleStart
// Using the `atDate` function to covert a sequence of `LocalDate` values to `LocalDateTime`
val morning = LocalTime(8, 30)
val firstMorningOfEveryMonth = (1..12).map { month ->
morning.atDate(2021, month, 1)
}
check(firstMorningOfEveryMonth.all { it.time == morning && it.dayOfMonth == 1 })
//sampleEnd
}
Combines this time's components with the specified date components into a LocalDateTime value.
There is no check of whether the time is valid on the specified date because that depends on the time zone, which this method does not accept.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
fun main() {
//sampleStart
// Using the `atDate` function to covert a sequence of `LocalDate` values to `LocalDateTime`
val morning = LocalTime(8, 30)
val firstMorningOfEveryMonth = Month.entries.map { month ->
morning.atDate(2021, month, 1)
}
check(firstMorningOfEveryMonth.all { it.time == morning && it.dayOfMonth == 1 })
//sampleEnd
}
Combines this time's components with the specified LocalDate components into a LocalDateTime value.
There is no check of whether the time is valid on the specified date because that depends on the time zone, which this method does not accept.
Samples
import kotlinx.datetime.*
import kotlinx.datetime.format.*
import kotlin.random.*
import kotlin.test.*
fun main() {
//sampleStart
// Using the `atDate` function to covert a sequence of `LocalDate` values to `LocalDateTime`
val workdayStart = LocalTime(8, 30)
val startDate = LocalDate(2021, Month.JANUARY, 1)
val endDate = LocalDate(2021, Month.DECEMBER, 31)
val allWorkdays = buildList {
var currentDate = startDate
while (currentDate <= endDate) {
if (currentDate.dayOfWeek != DayOfWeek.SATURDAY && currentDate.dayOfWeek != DayOfWeek.SUNDAY) {
add(currentDate)
}
currentDate = currentDate.plus(1, DateTimeUnit.DAY)
}
}
val allStartsOfWorkdays = allWorkdays.map {
workdayStart.atDate(it)
}
check(allStartsOfWorkdays.all { it.time == workdayStart })
//sampleEnd
}