-
Notifications
You must be signed in to change notification settings - Fork 102
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement the same ranges for all platforms #453
base: master
Are you sure you want to change the base?
Conversation
core/common/src/LocalDate.kt
Outdated
@@ -471,7 +473,7 @@ public expect fun LocalDate.plus(value: Int, unit: DateTimeUnit.DateBased): Loca | |||
* @throws DateTimeArithmeticException if the result exceeds the boundaries of [LocalDate]. | |||
* @sample kotlinx.datetime.test.samples.LocalDateSamples.minus | |||
*/ | |||
public expect fun LocalDate.minus(value: Int, unit: DateTimeUnit.DateBased): LocalDate | |||
public fun LocalDate.minus(value: Int, unit: DateTimeUnit.DateBased): LocalDate = plus(-value.toLong(), unit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be a good idea to use parenthesis here, because of this:
val value = Int.MIN_VALUE
println( -value.toLong() ) // 2147483648
println( -(value.toLong()) ) // 2147483648
println( (-value).toLong() ) // -2147483648
core/common/src/LocalDate.kt
Outdated
@@ -344,7 +350,7 @@ public operator fun LocalDate.minus(period: DatePeriod): LocalDate = | |||
* - Negative or zero if this date is later than the other. | |||
* - Exactly zero if this date is equal to the other. | |||
* | |||
* @throws DateTimeArithmeticException if the number of months between the two dates exceeds an Int (JVM only). | |||
* @throws DateTimeArithmeticException if the number of months between the two dates exceeds an Int. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this still true now that DatePeriod.totalMonths
is a Long
?
0f69a99
to
74cbbe3
Compare
b7c293c
to
ae4373e
Compare
ae4373e
to
e1a2c61
Compare
* @see LocalDate.fromEpochDays | ||
* @sample kotlinx.datetime.test.samples.LocalDateSamples.toEpochDays | ||
*/ | ||
public fun toEpochDays(): Int | ||
public fun toEpochDays(): Long |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you considered retaining source and/or binary compatibility?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't find a way to choose an overload based on its return type, so we can't restore source compatibility. Also, on Native, the binary compatibility can't be restored, as two signatures with different return types cause a compilation error.
Restored the binary compatibility for the JVM.
zones[components[0]]?.let { rules -> | ||
zones[components[1]] = rules | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the order of the two time zones specified? I mean is it possible that the second time zone has rules but the first doesn't?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://momentjs.com/timezone/docs/#/data-formats/link-format/ doesn't say anything either way, so the js-joda implementation is the best guidance we have on this, and they do assume this order.
} catch (e: IllegalArgumentException) { | ||
throw DateTimeArithmeticException("Boundaries of LocalDate exceeded when adding a value", e) | ||
} | ||
public actual fun LocalDate.plus(unit: DateTimeUnit.DateBased): LocalDate = plus(1, unit) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Can the implementation be moved to the common source set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. The JVM overload is in @file:JvmName("LocalDateJvmKt")
, and moving it to LocalDateKt
would be a breaking change. We could keep a LowPriorityInOverloadResolution
DeprecationLevel.HIDDEN
copy in LocalDateJvmKt
, but then what's the point in moving it to common code? It's deprecated anyway.
Fixes #432