Skip to content

Commit 565e50e

Browse files
committed
Add LocalDate.atTime function
1 parent a56ff87 commit 565e50e

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

core/commonMain/src/LocalDate.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public expect class LocalDate : Comparable<LocalDate> {
3737
*/
3838
public fun String.toLocalDate(): LocalDate = LocalDate.parse(this)
3939

40+
public fun LocalDate.atTime(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0): LocalDateTime =
41+
LocalDateTime(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond)
42+
4043

4144
/**
4245
* @throws DateTimeArithmeticException if arithmetic overflow occurs or the boundaries of [LocalDate] are exceeded at

core/commonTest/src/LocalDateTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ class LocalDateTest {
5858
checkLocalDateTimePart(date, datetime)
5959
}
6060

61+
@Test
62+
fun atTime() {
63+
val date = LocalDate(2016, 2, 29)
64+
val datetime = date.atTime(12, 1, 59)
65+
checkComponents(datetime, 2016, 2, 29, 12, 1, 59)
66+
checkLocalDateTimePart(date, datetime)
67+
}
68+
6169
@Test
6270
fun addComponents() {
6371
val startDate = LocalDate(2016, 2, 29)

0 commit comments

Comments
 (0)