Skip to content

Commit 8de9787

Browse files
committed
Preserve some source-level compatibility
1 parent f4ae79a commit 8de9787

File tree

4 files changed

+71
-0
lines changed

4 files changed

+71
-0
lines changed

core/jvm/src/LocalDate.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa
7878
public actual fun toEpochDays(): Int = value.toEpochDay().clampToInt()
7979
}
8080

81+
@Deprecated(
82+
"Use kotlinx.datetime.Month",
83+
ReplaceWith("LocalDate(year, month.toKotlinMonth(), dayOfMonth)")
84+
)
85+
public fun LocalDate(year: Int, month: java.time.Month, dayOfMonth: Int): LocalDate =
86+
LocalDate(year, month.toKotlinMonth(), dayOfMonth)
87+
8188
@Deprecated("Use the plus overload with an explicit number of units", ReplaceWith("this.plus(1, unit)"))
8289
public actual fun LocalDate.plus(unit: DateTimeUnit.DateBased): LocalDate =
8390
plus(1L, unit)
@@ -149,3 +156,6 @@ public actual fun LocalDate.monthsUntil(other: LocalDate): Int =
149156

150157
public actual fun LocalDate.yearsUntil(other: LocalDate): Int =
151158
this.value.until(other.value, ChronoUnit.YEARS).clampToInt()
159+
160+
@Deprecated("Use kotlinx.datetime.Month", ReplaceWith("toKotlinMonth().number"))
161+
public val java.time.Month.number: Int get() = toKotlinMonth().number

core/jvm/src/LocalDateTime.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,24 @@ public actual class LocalDateTime internal constructor(internal val value: jtLoc
8282

8383
}
8484

85+
@Deprecated(
86+
"Use kotlinx.datetime.Month",
87+
ReplaceWith("LocalDateTime(year, month.toKotlinMonth(), dayOfMonth, hour, minute, second, nanosecond)")
88+
)
89+
public fun LocalDateTime(
90+
year: Int,
91+
month: java.time.Month,
92+
dayOfMonth: Int,
93+
hour: Int,
94+
minute: Int,
95+
second: Int = 0,
96+
nanosecond: Int = 0
97+
): LocalDateTime = LocalDateTime(
98+
year,
99+
month.toKotlinMonth(),
100+
dayOfMonth,
101+
hour,
102+
minute,
103+
second,
104+
nanosecond
105+
)

core/jvm/src/LocalTime.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,10 @@ public actual class LocalTime internal constructor(internal val value: jtLocalTi
9090

9191
}
9292
}
93+
94+
@Deprecated(
95+
"Use kotlinx.datetime.Month",
96+
ReplaceWith("atDate(year, month.toKotlinMonth(), dayOfMonth)")
97+
)
98+
public fun LocalTime.atDate(year: Int, month: java.time.Month, dayOfMonth: Int = 0): LocalDateTime =
99+
atDate(year, month.toKotlinMonth(), dayOfMonth)
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright 2019-2024 JetBrains s.r.o. and contributors.
3+
* Use of this source code is governed by the Apache 2.0 License that can be found in the LICENSE.txt file.
4+
*/
5+
package kotlinx.datetime.test
6+
7+
import kotlinx.datetime.*
8+
9+
/**
10+
* To test the deprecation replacements, remove the `Suppress` annotation and try automatically replacing the deprecated
11+
* API usages with the new ones.
12+
*/
13+
@Suppress("DEPRECATION")
14+
class DeprecationReplacements {
15+
fun localTimeAtDate() {
16+
LocalTime(18, 43, 15, 100500000)
17+
.atDate(2023, java.time.Month.JANUARY, 20)
18+
}
19+
20+
fun monthNumber() {
21+
java.time.Month.JANUARY.number
22+
}
23+
24+
fun localDateConstruction() {
25+
LocalDate(2023, java.time.Month.JANUARY, 20)
26+
}
27+
28+
fun localDateTimeConstruction() {
29+
LocalDateTime(2023, java.time.Month.JANUARY, 20, 18, 43, 15, 100500000)
30+
LocalDateTime(2023, java.time.Month.JANUARY, 20, 18, 43, 15)
31+
LocalDateTime(2023, java.time.Month.JANUARY, 20, 18, 43)
32+
}
33+
}

0 commit comments

Comments
 (0)