diff --git a/core/common/src/DateTimePeriod.kt b/core/common/src/DateTimePeriod.kt index 129fe028..b35908cd 100644 --- a/core/common/src/DateTimePeriod.kt +++ b/core/common/src/DateTimePeriod.kt @@ -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 { /** @@ -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 { diff --git a/core/common/src/LocalDate.kt b/core/common/src/LocalDate.kt index f418462e..e9841575 100644 --- a/core/common/src/LocalDate.kt +++ b/core/common/src/LocalDate.kt @@ -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 @@ -168,7 +168,7 @@ public expect class LocalDate : Comparable { * 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 diff --git a/core/common/test/InstantTest.kt b/core/common/test/InstantTest.kt index c521fae6..8bc41f01 100644 --- a/core/common/test/InstantTest.kt +++ b/core/common/test/InstantTest.kt @@ -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") } } } @@ -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) diff --git a/settings.gradle.kts b/settings.gradle.kts index 1a9b35c1..a342b81f 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -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")