Skip to content

Commit a241a66

Browse files
committed
Preserve some source-level compatibility
1 parent b3861d9 commit a241a66

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

core/jvm/src/LocalDate.kt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,13 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa
9393
internal fun toEpochDaysJvm(): Int = value.toEpochDay().clampToInt()
9494
}
9595

96+
@Deprecated(
97+
"Use kotlinx.datetime.Month",
98+
ReplaceWith("LocalDate(year, month.toKotlinMonth(), dayOfMonth)")
99+
)
100+
public fun LocalDate(year: Int, month: java.time.Month, dayOfMonth: Int): LocalDate =
101+
LocalDate(year, month.toKotlinMonth(), dayOfMonth)
102+
96103
@Deprecated("Use the plus overload with an explicit number of units", ReplaceWith("this.plus(1, unit)"))
97104
public actual fun LocalDate.plus(unit: DateTimeUnit.DateBased): LocalDate =
98105
plus(1L, unit)
@@ -170,3 +177,6 @@ public actual fun LocalDate.monthsUntil(other: LocalDate): Int =
170177

171178
public actual fun LocalDate.yearsUntil(other: LocalDate): Int =
172179
this.value.until(other.value, ChronoUnit.YEARS).toInt()
180+
181+
@Deprecated("Use kotlinx.datetime.Month", ReplaceWith("toKotlinMonth().number"))
182+
public val java.time.Month.number: Int get() = toKotlinMonth().number

core/jvm/src/LocalDateTime.kt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,25 @@ public actual class LocalDateTime internal constructor(internal val value: jtLoc
8686
}
8787

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

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)