Skip to content

Commit c719ba9

Browse files
committed
Fix incorrect plus(Long,...) behavior in js-joda
When 0L was passed as JS number argument, it failed to equal strictly to zero number, thus triggering an incorrect execution path.
1 parent 9eba478 commit c719ba9

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

core/commonTest/src/LocalDateTest.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class LocalDateTest {
8282
@Test
8383
fun diffInvariant() {
8484
val origin = LocalDate(2001, 1, 1)
85+
assertEquals(origin, origin.plus(0, DateTimeUnit.DAY))
86+
assertEquals(origin, origin.plus(DatePeriod(days = 0)))
8587

8688
repeat(1000) {
8789
val days1 = Random.nextInt(-3652..3652)

core/jsMain/src/LocalDate.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private fun LocalDate.plusNumber(value: Number, unit: CalendarUnit): LocalDate =
4949
}.let(::LocalDate)
5050

5151
public actual fun LocalDate.plus(value: Long, unit: CalendarUnit): LocalDate =
52-
plusNumber(value, unit)
52+
plusNumber(value.toDouble(), unit)
5353

5454
public actual fun LocalDate.plus(value: Int, unit: CalendarUnit): LocalDate =
5555
plusNumber(value, unit)

0 commit comments

Comments
 (0)