Skip to content

Commit

Permalink
Address the review
Browse files Browse the repository at this point in the history
  • Loading branch information
dkhalanskyjb committed Jan 22, 2025
1 parent 997a93f commit 5882b5c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
6 changes: 3 additions & 3 deletions core/common/src/DateTimePeriod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ public class DatePeriod internal constructor(

/** The number of nanoseconds in this period. Always equal to zero. */
override val nanoseconds: Int get() = 0
override val totalNanoseconds: Long get() = 0
internal override val totalNanoseconds: Long get() = 0

public companion object {
/**
Expand Down Expand Up @@ -495,9 +495,9 @@ public class DatePeriod internal constructor(
public fun String.toDatePeriod(): DatePeriod = DatePeriod.parse(this)

private class DateTimePeriodImpl(
override val totalMonths: Long,
internal override val totalMonths: Long,
override val days: Int,
override val totalNanoseconds: Long,
internal override val totalNanoseconds: Long,
) : DateTimePeriod()

private fun totalMonths(years: Int, months: Int): Long = (years.toLong() * 12 + months.toLong()).also {
Expand Down
4 changes: 2 additions & 2 deletions core/common/src/LocalDate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import kotlinx.serialization.Serializable
* is `2020-08-31` everywhere): see various [LocalDate.plus] and [LocalDate.minus] functions, as well
* as [LocalDate.periodUntil] and various other [*until][LocalDate.daysUntil] functions.
*
* The range of supported years is at least is enough to represent dates of all instants between
* The range of supported years is at least enough to represent dates of all instants between
* [Instant.DISTANT_PAST] and [Instant.DISTANT_FUTURE].
*
* ### Arithmetic operations
Expand Down Expand Up @@ -168,7 +168,7 @@ public expect class LocalDate : Comparable<LocalDate> {
* The components [monthNumber] and [dayOfMonth] are 1-based.
*
* The supported ranges of components:
* - [year] the range is at least is enough to represent dates of all instants between
* - [year] the range is at least enough to represent dates of all instants between
* [Instant.DISTANT_PAST] and [Instant.DISTANT_FUTURE]
* - [monthNumber] `1..12`
* - [dayOfMonth] `1..31`, the upper bound can be less, depending on the month
Expand Down
15 changes: 8 additions & 7 deletions core/common/test/InstantTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,7 @@ class InstantTest {
val diff2 = date1.periodUntil(date2)

if (diff1 != diff2)
throw AssertionError(
"start: $instant1, end: $instant2, diff by instants: $diff1, diff by dates: $diff2"
)
fail("start: $instant1, end: $instant2, diff by instants: $diff1, diff by dates: $diff2")
}
}
}
Expand Down Expand Up @@ -560,10 +558,13 @@ class InstantRangeTest {
assertArithmeticFails("$instant") { instant.plus(Long.MIN_VALUE, DateTimeUnit.YEAR, UTC) }
}
for (instant in smallInstants) {
instant.plus(2 * Int.MAX_VALUE.toLong(), DateTimeUnit.DAY, UTC)
instant.plus(2 * Int.MIN_VALUE.toLong(), DateTimeUnit.DAY, UTC)
instant.plus(2 * Int.MAX_VALUE.toLong(), DateTimeUnit.MONTH, UTC)
instant.plus(2 * Int.MIN_VALUE.toLong(), DateTimeUnit.MONTH, UTC)
fun roundTrip(value: Long, unit: DateTimeUnit) {
assertEquals(instant, instant.plus(value, unit, UTC).minus(value, unit, UTC))
}
roundTrip(2L * Int.MAX_VALUE, DateTimeUnit.DAY)
roundTrip(2L * Int.MIN_VALUE, DateTimeUnit.DAY)
roundTrip(2L * Int.MAX_VALUE, DateTimeUnit.MONTH)
roundTrip(2L * Int.MIN_VALUE, DateTimeUnit.MONTH)
}
// Overflowing a LocalDateTime in input
maxValidInstant.plus(-1, DateTimeUnit.NANOSECOND, UTC)
Expand Down
2 changes: 1 addition & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ project(":timezones/full").name = "kotlinx-datetime-zoneinfo"
include(":serialization")
project(":serialization").name = "kotlinx-datetime-serialization"
include(":js-without-timezones")
project(":js-without-timezones").name = "kotlinx-datetime-js-without-timezones"
project(":js-without-timezones").name = "kotlinx-datetime-js-test-without-timezones"
include(":benchmarks")

0 comments on commit 5882b5c

Please sign in to comment.