diff --git a/README.md b/README.md index 3d9a61f6..368d5a7f 100644 --- a/README.md +++ b/README.md @@ -108,7 +108,7 @@ val datetimeInSystemZone: LocalDateTime = currentMoment.toLocalDateTime(TimeZone ``` A `LocalDateTime` instance exposes familiar components of the Gregorian calendar: -`year`, `month`, `dayOfMonth`, `hour`, and so on up to `nanosecond`. +`year`, `month`, `day`, `hour`, and so on up to `nanosecond`. The property `dayOfWeek` shows what weekday that date is, and `dayOfYear` shows the day number since the beginning of a year. @@ -210,7 +210,7 @@ can define their own format or use some of the predefined ones: val dateFormat = LocalDate.Format { monthNumber(padding = Padding.SPACE) char('/') - dayOfMonth() + day() char(' ') year() } diff --git a/core/common/src/LocalDate.kt b/core/common/src/LocalDate.kt index 0146d6f9..0e4f91b2 100644 --- a/core/common/src/LocalDate.kt +++ b/core/common/src/LocalDate.kt @@ -8,6 +8,7 @@ package kotlinx.datetime import kotlinx.datetime.format.* import kotlinx.datetime.serializers.* import kotlinx.serialization.Serializable +import kotlin.internal.* /** * The date part of [LocalDateTime]. @@ -96,7 +97,7 @@ public expect class LocalDate : Comparable { * Creates a new format for parsing and formatting [LocalDate] values. * * Only parsing and formatting of well-formed values is supported. If the input does not fit the boundaries - * (for example, [dayOfMonth] is 31 for February), consider using [DateTimeComponents.Format] instead. + * (for example, [day] is 31 for February), consider using [DateTimeComponents.Format] instead. * * There is a collection of predefined formats in [LocalDate.Formats]. * @@ -157,19 +158,19 @@ public expect class LocalDate : Comparable { /** * Constructs a [LocalDate] instance from the given date components. * - * The components [monthNumber] and [dayOfMonth] are 1-based. + * The components [month] and [day] are 1-based. * * The supported ranges of components: * - [year] the range is platform-dependent, but at least is 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 + * - [month] `1..12` + * - [day] `1..31`, the upper bound can be less, depending on the month * - * @throws IllegalArgumentException if any parameter is out of range or if [dayOfMonth] is invalid for the - * given [monthNumber] and [year]. + * @throws IllegalArgumentException if any parameter is out of range or if [day] is invalid for the + * given [month] and [year]. * @sample kotlinx.datetime.test.samples.LocalDateSamples.constructorFunctionMonthNumber */ - public constructor(year: Int, monthNumber: Int, dayOfMonth: Int) + public constructor(year: Int, month: Int, day: Int) /** * Constructs a [LocalDate] instance from the given date components. @@ -178,13 +179,13 @@ public expect class LocalDate : Comparable { * - [year] the range is platform-dependent, but at least is enough to represent dates of all instants between * [Instant.DISTANT_PAST] and [Instant.DISTANT_FUTURE] * - [month] all values of the [Month] enum - * - [dayOfMonth] `1..31`, the upper bound can be less, depending on the month + * - [day] `1..31`, the upper bound can be less, depending on the month * - * @throws IllegalArgumentException if any parameter is out of range or if [dayOfMonth] is invalid for the + * @throws IllegalArgumentException if any parameter is out of range or if [day] is invalid for the * given [month] and [year]. * @sample kotlinx.datetime.test.samples.LocalDateSamples.constructorFunction */ - public constructor(year: Int, month: Month, dayOfMonth: Int) + public constructor(year: Int, month: Month, day: Int) /** * Returns the year component of the date. @@ -193,11 +194,8 @@ public expect class LocalDate : Comparable { */ public val year: Int - /** - * Returns the number-of-the-month (1..12) component of the date. - * - * Shortcut for `month.number`. - */ + /** @suppress */ + @Deprecated("Use the 'month' property instead", ReplaceWith("this.month.number"), level = DeprecationLevel.WARNING) public val monthNumber: Int /** @@ -210,8 +208,12 @@ public expect class LocalDate : Comparable { /** * Returns the day-of-month (`1..31`) component of the date. * - * @sample kotlinx.datetime.test.samples.LocalDateSamples.dayOfMonth + * @sample kotlinx.datetime.test.samples.LocalDateSamples.day */ + public val day: Int + + /** @suppress */ + @Deprecated("Use the 'day' property instead", ReplaceWith("this.day"), level = DeprecationLevel.WARNING) public val dayOfMonth: Int /** @@ -259,6 +261,32 @@ public expect class LocalDate : Comparable { public override fun toString(): String } +/** + * @suppress + */ +@Deprecated( + "Use the constructor that accepts a 'month' and a 'day'", + ReplaceWith("LocalDate(year = year, month = monthNumber, day = dayOfMonth)"), + level = DeprecationLevel.WARNING +) +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@LowPriorityInOverloadResolution +public fun LocalDate(year: Int, monthNumber: Int, dayOfMonth: Int): LocalDate = + LocalDate(year = year, month = monthNumber, day = dayOfMonth) + +/** + * @suppress + */ +@Deprecated( + "Use the constructor that accepts a 'day'", + ReplaceWith("LocalDate(year = year, month = month, day = dayOfMonth)"), + level = DeprecationLevel.WARNING +) +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@LowPriorityInOverloadResolution +public fun LocalDate(year: Int, month: Month, dayOfMonth: Int): LocalDate = + LocalDate(year = year, month = month, day = dayOfMonth) + /** * Formats this value using the given [format]. * Equivalent to calling [DateTimeFormat.format] on [format] with `this`. @@ -287,7 +315,7 @@ public fun String.toLocalDate(): LocalDate = LocalDate.parse(this) * @sample kotlinx.datetime.test.samples.LocalDateSamples.atTimeInline */ public fun LocalDate.atTime(hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0): LocalDateTime = - LocalDateTime(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond) + LocalDateTime(year, month, day, hour, minute, second, nanosecond) /** * Combines this date's components with the specified [LocalTime] components into a [LocalDateTime] value. diff --git a/core/common/src/LocalDateTime.kt b/core/common/src/LocalDateTime.kt index 08fef15e..84a08c75 100644 --- a/core/common/src/LocalDateTime.kt +++ b/core/common/src/LocalDateTime.kt @@ -9,6 +9,7 @@ import kotlinx.datetime.format.* import kotlinx.datetime.serializers.LocalDateTimeIso8601Serializer import kotlinx.datetime.serializers.LocalDateTimeComponentSerializer import kotlinx.serialization.Serializable +import kotlin.internal.* /** * The representation of a specific civil date and time without a reference to a particular time zone. @@ -137,7 +138,7 @@ public expect class LocalDateTime : Comparable { * * // `08/30 18:43:13`, using a custom format: * LocalDateTime.Format { - * monthNumber(); char('/'); dayOfMonth() + * monthNumber(); char('/'); day() * char(' ') * hour(); char(':'); minute() * optional { char(':'); second() } @@ -145,7 +146,7 @@ public expect class LocalDateTime : Comparable { * ``` * * Only parsing and formatting of well-formed values is supported. If the input does not fit the boundaries - * (for example, [dayOfMonth] is 31 for February), consider using [DateTimeComponents.Format] instead. + * (for example, [day] is 31 for February), consider using [DateTimeComponents.Format] instead. * * There is a collection of predefined formats in [LocalDateTime.Formats]. * @@ -194,27 +195,27 @@ public expect class LocalDateTime : Comparable { /** * Constructs a [LocalDateTime] instance from the given date and time components. * - * The components [monthNumber] and [dayOfMonth] are 1-based. + * The components [month] and [day] are 1-based. * * The supported ranges of components: * - [year] the range is platform-dependent, but at least is 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 + * - [month] `1..12` + * - [day] `1..31`, the upper bound can be less, depending on the month * - [hour] `0..23` * - [minute] `0..59` * - [second] `0..59` * - [nanosecond] `0..999_999_999` * * @throws IllegalArgumentException if any parameter is out of range - * or if [dayOfMonth] is invalid for the given [monthNumber] and [year]. + * or if [day] is invalid for the given [monthNumber] and [year]. * * @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.constructorFunctionWithMonthNumber */ public constructor( year: Int, - monthNumber: Int, - dayOfMonth: Int, + month: Int, + day: Int, hour: Int, minute: Int, second: Int = 0, @@ -228,21 +229,21 @@ public expect class LocalDateTime : Comparable { * - [year] the range is platform-dependent, but at least is enough to represent dates of all instants between * [Instant.DISTANT_PAST] and [Instant.DISTANT_FUTURE] * - [month] all values of the [Month] enum - * - [dayOfMonth] `1..31`, the upper bound can be less, depending on the month + * - [day] `1..31`, the upper bound can be less, depending on the month * - [hour] `0..23` * - [minute] `0..59` * - [second] `0..59` * - [nanosecond] `0..999_999_999` * * @throws IllegalArgumentException if any parameter is out of range, - * or if [dayOfMonth] is invalid for the given [month] and [year]. + * or if [day] is invalid for the given [month] and [year]. * * @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.constructorFunction */ public constructor( year: Int, month: Month, - dayOfMonth: Int, + day: Int, hour: Int, minute: Int, second: Int = 0, @@ -263,11 +264,8 @@ public expect class LocalDateTime : Comparable { */ public val year: Int - /** - * Returns the number-of-the-month (1..12) component of the [date]. - * - * @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.dateComponents - */ + /** @suppress */ + @Deprecated("Use the 'month' property instead", ReplaceWith("month.number"), level = DeprecationLevel.WARNING) public val monthNumber: Int /** @@ -282,6 +280,10 @@ public expect class LocalDateTime : Comparable { * * @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.dateComponents */ + public val day: Int + + /** @suppress */ + @Deprecated("Use the 'day' property instead", ReplaceWith("day"), level = DeprecationLevel.WARNING) public val dayOfMonth: Int /** @@ -383,6 +385,52 @@ public expect class LocalDateTime : Comparable { public override fun toString(): String } +/** + * @suppress + */ +@Deprecated( + "Use the constructor that accepts a 'month' and a 'day'", + ReplaceWith("LocalDateTime(year = year, month = monthNumber, day = dayOfMonth, hour = hour, minute = minute, second = second, nanosecond = nanosecond)"), + level = DeprecationLevel.WARNING +) +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@LowPriorityInOverloadResolution +public fun LocalDateTime( + year: Int, + monthNumber: Int, + dayOfMonth: Int, + hour: Int, + minute: Int, + second: Int = 0, + nanosecond: Int = 0, +): LocalDateTime = LocalDateTime( + year = year, month = monthNumber, day = dayOfMonth, + hour = hour, minute = minute, second = second, nanosecond = nanosecond +) + +/** + * @suppress + */ +@Deprecated( + "Use the constructor that accepts a 'day'", + ReplaceWith("LocalDateTime(year = year, month = month, day = dayOfMonth, hour = hour, minute = minute, second = second, nanosecond = nanosecond)"), + level = DeprecationLevel.WARNING +) +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@LowPriorityInOverloadResolution +public fun LocalDateTime( + year: Int, + month: Month, + dayOfMonth: Int, + hour: Int, + minute: Int, + second: Int = 0, + nanosecond: Int = 0, +): LocalDateTime = LocalDateTime( + year = year, month = month, day = dayOfMonth, + hour = hour, minute = minute, second = second, nanosecond = nanosecond +) + /** * Formats this value using the given [format]. * Equivalent to calling [DateTimeFormat.format] on [format] with `this`. diff --git a/core/common/src/LocalTime.kt b/core/common/src/LocalTime.kt index 695a1090..0c5dd8b3 100644 --- a/core/common/src/LocalTime.kt +++ b/core/common/src/LocalTime.kt @@ -10,6 +10,7 @@ import kotlinx.datetime.format.* import kotlinx.datetime.serializers.LocalTimeIso8601Serializer import kotlinx.datetime.serializers.LocalTimeComponentSerializer import kotlinx.serialization.Serializable +import kotlin.internal.* /** @@ -364,8 +365,21 @@ public fun String.toLocalTime(): LocalTime = LocalTime.parse(this) * * @sample kotlinx.datetime.test.samples.LocalTimeSamples.atDateComponentWiseMonthNumber */ -public fun LocalTime.atDate(year: Int, monthNumber: Int, dayOfMonth: Int = 0): LocalDateTime = - LocalDateTime(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond) +public fun LocalTime.atDate(year: Int, month: Int, day: Int = 0): LocalDateTime = + LocalDateTime(year, month, day, hour, minute, second, nanosecond) + +/** @suppress */ +@Deprecated( + "Use the overload that accepts a 'month' and a 'day' instead", + ReplaceWith("this.atDate(year = year, month = monthNumber, day = dayOfMonth)"), + DeprecationLevel.WARNING +) +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@LowPriorityInOverloadResolution +public fun LocalTime.atDate(year: Int, monthNumber: Int, dayOfMonth: Int, fakeArgument: Unit = Unit): LocalDateTime = + fakeArgument.let { + LocalDateTime(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond) + } /** * Combines this time's components with the specified date components into a [LocalDateTime] value. @@ -375,8 +389,21 @@ public fun LocalTime.atDate(year: Int, monthNumber: Int, dayOfMonth: Int = 0): L * * @sample kotlinx.datetime.test.samples.LocalTimeSamples.atDateComponentWise */ -public fun LocalTime.atDate(year: Int, month: Month, dayOfMonth: Int = 0): LocalDateTime = - LocalDateTime(year, month, dayOfMonth, hour, minute, second, nanosecond) +public fun LocalTime.atDate(year: Int, month: Month, day: Int = 0): LocalDateTime = + LocalDateTime(year, month, day, hour, minute, second, nanosecond) + +/** @suppress */ +@Deprecated( + "Use the overload that accepts a 'month' and a 'day' instead", + ReplaceWith("this.atDate(year = year, month = month, day = dayOfMonth)"), + DeprecationLevel.WARNING +) +@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE") +@LowPriorityInOverloadResolution +public fun LocalTime.atDate(year: Int, month: Month, dayOfMonth: Int, fakeArgument: Unit = Unit): LocalDateTime = + fakeArgument.let { + LocalDateTime(year, month, dayOfMonth, hour, minute, second, nanosecond) + } /** * Combines this time's components with the specified [LocalDate] components into a [LocalDateTime] value. diff --git a/core/common/src/TimeZone.kt b/core/common/src/TimeZone.kt index 808a8ad6..23767380 100644 --- a/core/common/src/TimeZone.kt +++ b/core/common/src/TimeZone.kt @@ -130,12 +130,12 @@ public expect open class TimeZone { * Returns an instant that corresponds to this civil datetime value in the time zone provided as an implicit receiver. * * Note that the conversion is not always well-defined. There can be the following possible situations: - * - Only one instant has this datetime value in the [timeZone]. + * - Only one instant has this datetime value in the time zone. * In this case, the conversion is unambiguous. - * - No instant has this datetime value in the [timeZone]. + * - No instant has this datetime value in the time zone. * Such a situation appears when the time zone experiences a transition from a lesser to a greater offset. * In this case, the conversion is performed with the lesser (earlier) offset, as if the time gap didn't occur yet. - * - Two possible instants can have these datetime components in the [timeZone]. + * - Two possible instants can have these datetime components in the time zone. * In this case, the earlier instant is returned. * * @see Instant.toLocalDateTime diff --git a/core/common/src/format/DateTimeComponents.kt b/core/common/src/format/DateTimeComponents.kt index 436fa499..b145189e 100644 --- a/core/common/src/format/DateTimeComponents.kt +++ b/core/common/src/format/DateTimeComponents.kt @@ -143,7 +143,7 @@ public class DateTimeComponents internal constructor(internal val contents: Date dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED) chars(", ") } - dayOfMonth(Padding.NONE) + day(Padding.NONE) char(' ') monthName(MonthNames.ENGLISH_ABBREVIATED) char(' ') @@ -183,7 +183,7 @@ public class DateTimeComponents internal constructor(internal val contents: Date /** * Writes the contents of the specified [localDate] to this [DateTimeComponents]. - * The [localDate] is written to the [year], [monthNumber], [dayOfMonth], and [dayOfWeek] fields. + * The [localDate] is written to the [year], [monthNumber], [day], and [dayOfWeek] fields. * * If any of the fields are already set, they will be overwritten. * @@ -196,7 +196,7 @@ public class DateTimeComponents internal constructor(internal val contents: Date /** * Writes the contents of the specified [localDateTime] to this [DateTimeComponents]. * The [localDateTime] is written to the - * [year], [monthNumber], [dayOfMonth], [dayOfWeek], + * [year], [monthNumber], [day], [dayOfWeek], * [hour], [hourOfAmPm], [amPm], [minute], [second] and [nanosecond] fields. * * If any of the fields are already set, they will be overwritten. @@ -267,6 +267,9 @@ public class DateTimeComponents internal constructor(internal val contents: Date /** * The number-of-month (1..12) component of the date. + * + * As opposed to [month], this field can be out-of-bounds, but it must be in the `0..99` range. + * * @throws IllegalArgumentException during assignment if the value is outside the `0..99` range. * @sample kotlinx.datetime.test.samples.format.DateTimeComponentsSamples.date */ @@ -294,7 +297,11 @@ public class DateTimeComponents internal constructor(internal val contents: Date * @throws IllegalArgumentException during assignment if the value is outside the `0..99` range. * @sample kotlinx.datetime.test.samples.format.DateTimeComponentsSamples.date */ - public var dayOfMonth: Int? by TwoDigitNumber(contents.date::dayOfMonth) + public var day: Int? by TwoDigitNumber(contents.date::day) + + /** @suppress */ + @Deprecated("Use 'day' instead", ReplaceWith("day")) + public var dayOfMonth: Int? by TwoDigitNumber(contents.date::day) /** * The day-of-week component of the date. @@ -415,7 +422,7 @@ public class DateTimeComponents internal constructor(internal val contents: Date * This method uses the following fields: * * [year] * * [monthNumber] - * * [dayOfMonth] + * * [day] * * Also, [dayOfWeek] is checked for consistency with the other fields. * @@ -445,7 +452,7 @@ public class DateTimeComponents internal constructor(internal val contents: Date * This method uses the following fields: * * [year] * * [monthNumber] - * * [dayOfMonth] + * * [day] * * [hour], [hourOfAmPm], and [amPm] * * [minute] * * [second] (default value is 0) diff --git a/core/common/src/format/DateTimeFormatBuilder.kt b/core/common/src/format/DateTimeFormatBuilder.kt index 932653b5..ff651335 100644 --- a/core/common/src/format/DateTimeFormatBuilder.kt +++ b/core/common/src/format/DateTimeFormatBuilder.kt @@ -74,6 +74,10 @@ public sealed interface DateTimeFormatBuilder { */ public fun monthName(names: MonthNames) + /** @suppress */ + @Deprecated("Use 'day' instead", ReplaceWith("day(padding = padding)")) + public fun dayOfMonth(padding: Padding = Padding.ZERO) { day(padding) } + /** * A day-of-month number, from 1 to 31. * @@ -81,7 +85,7 @@ public sealed interface DateTimeFormatBuilder { * * @sample kotlinx.datetime.test.samples.format.LocalDateFormatSamples.dayOfMonth */ - public fun dayOfMonth(padding: Padding = Padding.ZERO) + public fun day(padding: Padding = Padding.ZERO) /** * A day-of-week name (for example, "Thursday"). @@ -341,9 +345,9 @@ internal fun DateTimeFormatBuilder.WithTime.secondFractionInternal( * Example: * ``` * alternativeParsing( - * { dayOfMonth(); char('-'); monthNumber() }, - * { monthNumber(); char(' '); dayOfMonth() }, - * ) { monthNumber(); char('/'); dayOfMonth() } + * { day(); char('-'); monthNumber() }, + * { monthNumber(); char(' '); day() }, + * ) { monthNumber(); char('/'); day() } * ``` * * This will always format a date as `MM/DD`, but will also accept `DD-MM` and `MM DD`. diff --git a/core/common/src/format/LocalDateFormat.kt b/core/common/src/format/LocalDateFormat.kt index bc6638e6..1433a8e4 100644 --- a/core/common/src/format/LocalDateFormat.kt +++ b/core/common/src/format/LocalDateFormat.kt @@ -199,7 +199,7 @@ internal fun requireParsedField(field: T?, name: String): T { internal interface DateFieldContainer { var year: Int? var monthNumber: Int? - var dayOfMonth: Int? + var day: Int? var isoDayOfWeek: Int? var dayOfYear: Int? } @@ -207,7 +207,7 @@ internal interface DateFieldContainer { private object DateFields { val year = GenericFieldSpec(PropertyAccessor(DateFieldContainer::year)) val month = UnsignedFieldSpec(PropertyAccessor(DateFieldContainer::monthNumber), minValue = 1, maxValue = 12) - val dayOfMonth = UnsignedFieldSpec(PropertyAccessor(DateFieldContainer::dayOfMonth), minValue = 1, maxValue = 31) + val day = UnsignedFieldSpec(PropertyAccessor(DateFieldContainer::day), minValue = 1, maxValue = 31) val isoDayOfWeek = UnsignedFieldSpec(PropertyAccessor(DateFieldContainer::isoDayOfWeek), minValue = 1, maxValue = 7) val dayOfYear = UnsignedFieldSpec(PropertyAccessor(DateFieldContainer::dayOfYear), minValue = 1, maxValue = 366) } @@ -218,7 +218,7 @@ private object DateFields { internal class IncompleteLocalDate( override var year: Int? = null, override var monthNumber: Int? = null, - override var dayOfMonth: Int? = null, + override var day: Int? = null, override var isoDayOfWeek: Int? = null, override var dayOfYear: Int? = null, ) : DateFieldContainer, Copyable { @@ -228,7 +228,7 @@ internal class IncompleteLocalDate( null -> LocalDate( year, requireParsedField(monthNumber, "monthNumber"), - requireParsedField(dayOfMonth, "dayOfMonth") + requireParsedField(day, "day") ) else -> LocalDate(year, 1, 1).plus(dayOfYear - 1, DateTimeUnit.DAY).also { if (it.year != year) { @@ -244,11 +244,11 @@ internal class IncompleteLocalDate( "but $monthNumber was specified as the month number" ) } - if (dayOfMonth != null && it.dayOfMonth != dayOfMonth) { + if (day != null && it.day != day) { throw DateTimeFormatException( "Can not create a LocalDate from the given input: " + - "the day of year is $dayOfYear, which is the day ${it.dayOfMonth} of ${it.month}, " + - "but $dayOfMonth was specified as the day of month" + "the day of year is $dayOfYear, which is the day ${it.day} of ${it.month}, " + + "but $day was specified as the day of month" ) } } @@ -266,27 +266,27 @@ internal class IncompleteLocalDate( fun populateFrom(date: LocalDate) { year = date.year - monthNumber = date.monthNumber - dayOfMonth = date.dayOfMonth + monthNumber = date.month.number + day = date.day isoDayOfWeek = date.dayOfWeek.isoDayNumber dayOfYear = date.dayOfYear } override fun copy(): IncompleteLocalDate = - IncompleteLocalDate(year, monthNumber, dayOfMonth, isoDayOfWeek, dayOfYear) + IncompleteLocalDate(year, monthNumber, day, isoDayOfWeek, dayOfYear) override fun equals(other: Any?): Boolean = other is IncompleteLocalDate && year == other.year && monthNumber == other.monthNumber && - dayOfMonth == other.dayOfMonth && isoDayOfWeek == other.isoDayOfWeek && dayOfYear == other.dayOfYear + day == other.day && isoDayOfWeek == other.isoDayOfWeek && dayOfYear == other.dayOfYear override fun hashCode(): Int = year.hashCode() * 923521 + monthNumber.hashCode() * 29791 + - dayOfMonth.hashCode() * 961 + + day.hashCode() * 961 + isoDayOfWeek.hashCode() * 31 + dayOfYear.hashCode() override fun toString(): String = - "${year ?: "??"}-${monthNumber ?: "??"}-${dayOfMonth ?: "??"} (day of week is ${isoDayOfWeek ?: "??"})" + "${year ?: "??"}-${monthNumber ?: "??"}-${day ?: "??"} (day of week is ${isoDayOfWeek ?: "??"})" } private class YearDirective(private val padding: Padding, private val isYearOfEra: Boolean = false) : @@ -394,14 +394,14 @@ private class MonthNameDirective(private val names: MonthNames) : private class DayDirective(private val padding: Padding) : UnsignedIntFieldFormatDirective( - DateFields.dayOfMonth, + DateFields.day, minDigits = padding.minDigits(2), spacePadding = padding.spaces(2), ) { override val builderRepresentation: String get() = when (padding) { - Padding.ZERO -> "${DateTimeFormatBuilder.WithDate::dayOfMonth.name}()" - else -> "${DateTimeFormatBuilder.WithDate::dayOfMonth.name}(${padding.toKotlinCode()})" + Padding.ZERO -> "${DateTimeFormatBuilder.WithDate::day.name}()" + else -> "${DateTimeFormatBuilder.WithDate::day.name}(${padding.toKotlinCode()})" } override fun equals(other: Any?): Boolean = other is DayDirective && padding == other.padding @@ -477,7 +477,9 @@ internal interface AbstractWithDateBuilder : DateTimeFormatBuilder.WithDate { override fun monthName(names: MonthNames) = addFormatStructureForDate(BasicFormatStructure(MonthNameDirective(names))) - override fun dayOfMonth(padding: Padding) = addFormatStructureForDate(BasicFormatStructure(DayDirective(padding))) + override fun day(padding: Padding) = + addFormatStructureForDate(BasicFormatStructure(DayDirective(padding))) + override fun dayOfWeek(names: DayOfWeekNames) = addFormatStructureForDate(BasicFormatStructure(DayOfWeekDirective(names))) @@ -492,10 +494,10 @@ internal interface AbstractWithDateBuilder : DateTimeFormatBuilder.WithDate { // these are constants so that the formats are not recreated every time they are used internal val ISO_DATE by lazy { - LocalDateFormat.build { year(); char('-'); monthNumber(); char('-'); dayOfMonth() } + LocalDateFormat.build { year(); char('-'); monthNumber(); char('-'); day() } } internal val ISO_DATE_BASIC by lazy { - LocalDateFormat.build { year(); monthNumber(); dayOfMonth() } + LocalDateFormat.build { year(); monthNumber(); day() } } private val emptyIncompleteLocalDate = IncompleteLocalDate() diff --git a/core/common/src/format/Unicode.kt b/core/common/src/format/Unicode.kt index 4f483dbd..13655bce 100644 --- a/core/common/src/format/Unicode.kt +++ b/core/common/src/format/Unicode.kt @@ -329,8 +329,8 @@ internal sealed interface UnicodeFormat { class DayOfMonth(override val formatLength: Int) : DateBased() { override val formatLetter = 'd' override fun addToFormat(builder: DateTimeFormatBuilder.WithDate) = when (formatLength) { - 1 -> builder.dayOfMonth(Padding.NONE) - 2 -> builder.dayOfMonth(Padding.ZERO) + 1 -> builder.day(Padding.NONE) + 2 -> builder.day(Padding.ZERO) else -> unknownLength() } } diff --git a/core/common/src/serializers/LocalDateSerializers.kt b/core/common/src/serializers/LocalDateSerializers.kt index e1c1c5e9..824ce518 100644 --- a/core/common/src/serializers/LocalDateSerializers.kt +++ b/core/common/src/serializers/LocalDateSerializers.kt @@ -5,7 +5,7 @@ package kotlinx.datetime.serializers -import kotlinx.datetime.LocalDate +import kotlinx.datetime.* import kotlinx.serialization.* import kotlinx.serialization.descriptors.* import kotlinx.serialization.encoding.* @@ -70,8 +70,8 @@ public object LocalDateComponentSerializer: KSerializer { override fun serialize(encoder: Encoder, value: LocalDate) { encoder.encodeStructure(descriptor) { encodeIntElement(descriptor, 0, value.year) - encodeShortElement(descriptor, 1, value.monthNumber.toShort()) - encodeShortElement(descriptor, 2, value.dayOfMonth.toShort()) + encodeShortElement(descriptor, 1, value.month.number.toShort()) + encodeShortElement(descriptor, 2, value.day.toShort()) } } diff --git a/core/common/src/serializers/LocalDateTimeSerializers.kt b/core/common/src/serializers/LocalDateTimeSerializers.kt index 73f29115..f9a45553 100644 --- a/core/common/src/serializers/LocalDateTimeSerializers.kt +++ b/core/common/src/serializers/LocalDateTimeSerializers.kt @@ -84,8 +84,8 @@ public object LocalDateTimeComponentSerializer: KSerializer { override fun serialize(encoder: Encoder, value: LocalDateTime) { encoder.encodeStructure(descriptor) { encodeIntElement(descriptor, 0, value.year) - encodeShortElement(descriptor, 1, value.monthNumber.toShort()) - encodeShortElement(descriptor, 2, value.dayOfMonth.toShort()) + encodeShortElement(descriptor, 1, value.month.number.toShort()) + encodeShortElement(descriptor, 2, value.day.toShort()) encodeShortElement(descriptor, 3, value.hour.toShort()) encodeShortElement(descriptor, 4, value.minute.toShort()) if (value.second != 0 || value.nanosecond != 0) { diff --git a/core/common/test/LocalDateTest.kt b/core/common/test/LocalDateTest.kt index 74a2286d..b3022d37 100644 --- a/core/common/test/LocalDateTest.kt +++ b/core/common/test/LocalDateTest.kt @@ -20,9 +20,9 @@ class LocalDateTest { private fun checkComponents(value: LocalDate, year: Int, month: Int, day: Int, dayOfWeek: Int? = null, dayOfYear: Int? = null) { assertEquals(year, value.year) - assertEquals(month, value.monthNumber) + assertEquals(month, value.month.number) assertEquals(Month(month), value.month) - assertEquals(day, value.dayOfMonth) + assertEquals(day, value.day) if (dayOfWeek != null) assertEquals(dayOfWeek, value.dayOfWeek.isoDayNumber) if (dayOfYear != null) assertEquals(dayOfYear, value.dayOfYear) @@ -32,7 +32,7 @@ class LocalDateTest { private fun checkLocalDateTimePart(date: LocalDate, datetime: LocalDateTime) { checkEquals(date, datetime.date) - checkComponents(date, datetime.year, datetime.monthNumber, datetime.dayOfMonth, datetime.dayOfWeek.isoDayNumber, datetime.dayOfYear) + checkComponents(date, datetime.year, datetime.month.number, datetime.day, datetime.dayOfWeek.isoDayNumber, datetime.dayOfYear) } @Test @@ -296,7 +296,7 @@ class LocalDateTest { fun checkInvalidDate(constructor: (year: Int, month: Int, day: Int) -> LocalDate) { assertFailsWith { constructor(2007, 2, 29) } - assertEquals(29, constructor(2008, 2, 29).dayOfMonth) + assertEquals(29, constructor(2008, 2, 29).day) assertFailsWith { constructor(2007, 4, 31) } assertFailsWith { constructor(2007, 1, 0) } assertFailsWith { constructor(2007,1, 32) } @@ -307,19 +307,19 @@ fun checkInvalidDate(constructor: (year: Int, month: Int, day: Int) -> LocalDate } private val LocalDate.next: LocalDate get() = - if (dayOfMonth != monthNumber.monthLength(isLeapYear(year))) { - LocalDate(year, monthNumber, dayOfMonth + 1) - } else if (monthNumber != 12) { - LocalDate(year, monthNumber + 1, 1) + if (day != month.number.monthLength(isLeapYear(year))) { + LocalDate(year, month.number, day + 1) + } else if (month.number != 12) { + LocalDate(year, month.number + 1, 1) } else { LocalDate(year + 1, 1, 1) } private val LocalDate.previous: LocalDate get() = - if (dayOfMonth != 1) { - LocalDate(year, monthNumber, dayOfMonth - 1) - } else if (monthNumber != 1) { - val newMonthNumber = monthNumber - 1 + if (day != 1) { + LocalDate(year, month.number, day - 1) + } else if (month.number != 1) { + val newMonthNumber = month.number - 1 LocalDate(year, newMonthNumber, newMonthNumber.monthLength(isLeapYear(year))) } else { LocalDate(year - 1, 12, 31) diff --git a/core/common/test/LocalDateTimeTest.kt b/core/common/test/LocalDateTimeTest.kt index 906ef933..fff490a3 100644 --- a/core/common/test/LocalDateTimeTest.kt +++ b/core/common/test/LocalDateTimeTest.kt @@ -134,9 +134,9 @@ class LocalDateTimeTest { fun checkComponents(value: LocalDateTime, year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int = 0, nanosecond: Int = 0, dayOfWeek: Int? = null, dayOfYear: Int? = null) { assertEquals(year, value.year, "years") - assertEquals(month, value.monthNumber, "months") + assertEquals(month, value.month.number, "months") assertEquals(Month(month), value.month) - assertEquals(day, value.dayOfMonth, "days") + assertEquals(day, value.day, "days") assertEquals(hour, value.hour, "hours") assertEquals(minute, value.minute, "minutes") assertEquals(second, value.second, "seconds") diff --git a/core/common/test/ReadmeTest.kt b/core/common/test/ReadmeTest.kt index 696ff151..a6d8636a 100644 --- a/core/common/test/ReadmeTest.kt +++ b/core/common/test/ReadmeTest.kt @@ -77,7 +77,7 @@ class ReadmeTest { val dateFormat = LocalDate.Format { monthNumber(padding = Padding.SPACE) char('/') - dayOfMonth() + day() char(' ') year() } diff --git a/core/common/test/TimeZoneTest.kt b/core/common/test/TimeZoneTest.kt index f59bd2ce..24c6d9e8 100644 --- a/core/common/test/TimeZoneTest.kt +++ b/core/common/test/TimeZoneTest.kt @@ -245,7 +245,7 @@ class TimeZoneTest { } } - private fun LocalDateTime(year: Int, monthNumber: Int, dayOfMonth: Int) = LocalDateTime(year, monthNumber, dayOfMonth, 0, 0) + private fun LocalDateTime(year: Int, month: Int, day: Int) = LocalDateTime(year, month, day, 0, 0) } diff --git a/core/common/test/format/DateTimeComponentsFormatTest.kt b/core/common/test/format/DateTimeComponentsFormatTest.kt index 07973d75..be995e32 100644 --- a/core/common/test/format/DateTimeComponentsFormatTest.kt +++ b/core/common/test/format/DateTimeComponentsFormatTest.kt @@ -20,14 +20,14 @@ class DateTimeComponentsFormatTest { // the same date, but with an incorrect day-of-week: assertDateTimeComponentsEqual( DateTimeComponents().apply { - year = 2008; monthNumber = 6; dayOfMonth = 3; dayOfWeek = DayOfWeek.MONDAY + year = 2008; monthNumber = 6; day = 3; dayOfWeek = DayOfWeek.MONDAY setTime(LocalTime(11, 5, 30)) setOffset(UtcOffset.ZERO) }, format.parse("Mon, 3 Jun 2008 11:05:30 GMT")) assertDateTimeComponentsEqual( DateTimeComponents().apply { - year = 2008; monthNumber = 6; dayOfMonth = 40; dayOfWeek = DayOfWeek.TUESDAY + year = 2008; monthNumber = 6; day = 40; dayOfWeek = DayOfWeek.TUESDAY setTime(LocalTime(11, 5, 30)) setOffset(UtcOffset.ZERO) }, @@ -124,7 +124,7 @@ class DateTimeComponentsFormatTest { private fun assertDateTimeComponentsEqual(a: DateTimeComponents, b: DateTimeComponents, message: String? = null) { assertEquals(a.year, b.year, message) assertEquals(a.monthNumber, b.monthNumber, message) - assertEquals(a.dayOfMonth, b.dayOfMonth, message) + assertEquals(a.day, b.day, message) if (a.dayOfWeek != null && b.dayOfWeek != null) assertEquals(a.dayOfWeek, b.dayOfWeek, message) assertEquals(a.hour, b.hour, message) diff --git a/core/common/test/format/DateTimeComponentsTest.kt b/core/common/test/format/DateTimeComponentsTest.kt index c6184126..8575c601 100644 --- a/core/common/test/format/DateTimeComponentsTest.kt +++ b/core/common/test/format/DateTimeComponentsTest.kt @@ -53,7 +53,7 @@ class DateTimeComponentsTest { val twoDigitFields = listOf( DateTimeComponents::monthNumber, - DateTimeComponents::dayOfMonth, + DateTimeComponents::day, DateTimeComponents::hour, DateTimeComponents::minute, DateTimeComponents::second, diff --git a/core/common/test/format/DateTimeFormatTest.kt b/core/common/test/format/DateTimeFormatTest.kt index 34119f3f..830124cf 100644 --- a/core/common/test/format/DateTimeFormatTest.kt +++ b/core/common/test/format/DateTimeFormatTest.kt @@ -19,7 +19,7 @@ class DateTimeFormatTest { dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED) chars(", ") } - dayOfMonth(Padding.NONE) + day(Padding.NONE) char(' ') monthName(MonthNames("Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec.")) char(' ') @@ -50,7 +50,7 @@ class DateTimeFormatTest { dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED) chars(", ") } - dayOfMonth(Padding.NONE) + day(Padding.NONE) char(' ') monthName(MonthNames("Jan.", "Feb.", "Mar.", "Apr.", "May", "Jun.", "Jul.", "Aug.", "Sep.", "Oct.", "Nov.", "Dec.")) char(' ') @@ -133,7 +133,7 @@ class DateTimeFormatTest { assertFailsWith { DateTimeComponents.Format { monthNumber(Padding.NONE) - dayOfMonth(Padding.NONE) + day(Padding.NONE) } } } diff --git a/core/common/test/format/LocalDateFormatTest.kt b/core/common/test/format/LocalDateFormatTest.kt index 35f7e6d9..3be5b765 100644 --- a/core/common/test/format/LocalDateFormatTest.kt +++ b/core/common/test/format/LocalDateFormatTest.kt @@ -46,7 +46,7 @@ class LocalDateFormatTest { char(s) monthNumber() char(s) - dayOfMonth() + day() }) } } @@ -71,7 +71,7 @@ class LocalDateFormatTest { year() }) test(dates, LocalDate.Format { - dayOfMonth() + day() char(s) monthNumber() char(s) @@ -101,7 +101,7 @@ class LocalDateFormatTest { test(dates, LocalDate.Format { year() monthNumber() - dayOfMonth() + day() }) } @@ -120,7 +120,7 @@ class LocalDateFormatTest { put(LocalDate(-123456, 5, 1), ("01 May -123456" to setOf())) } val format = LocalDate.Format { - dayOfMonth() + day() char(' ') monthName(MonthNames.ENGLISH_FULL) char(' ') @@ -144,7 +144,7 @@ class LocalDateFormatTest { put(LocalDate(-123456, 5, 1), ("01 V -123456" to setOf())) } val format = LocalDate.Format { - dayOfMonth() + day() char(' ') monthName(MonthNames("I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII")) char(' ') @@ -170,7 +170,7 @@ class LocalDateFormatTest { val format = LocalDate.Format { yearTwoDigits(baseYear = 1960) monthNumber() - dayOfMonth() + day() } test(dates, format) } @@ -237,7 +237,7 @@ class LocalDateFormatTest { char(' ') monthName(MonthNames.ENGLISH_ABBREVIATED) char(' ') - dayOfMonth() + day() } assertEquals("2020 Jan 05", format.format(LocalDate(2020, 1, 5))) } diff --git a/core/common/test/format/LocalDateTimeFormatTest.kt b/core/common/test/format/LocalDateTimeFormatTest.kt index 15a8bfa0..32ab5596 100644 --- a/core/common/test/format/LocalDateTimeFormatTest.kt +++ b/core/common/test/format/LocalDateTimeFormatTest.kt @@ -45,7 +45,7 @@ class LocalDateTimeFormatTest { char('-') monthNumber() char('-') - dayOfMonth() + day() char(' ') hour() char(':') @@ -78,7 +78,7 @@ class LocalDateTimeFormatTest { char('-') monthNumber() char('-') - dayOfMonth() + day() char(' ') hour() char(':') @@ -107,7 +107,7 @@ class LocalDateTimeFormatTest { test(dateTimes, LocalDateTime.Format { year() monthNumber() - dayOfMonth() + day() hour() minute() second() @@ -137,7 +137,7 @@ class LocalDateTimeFormatTest { char('-') monthNumber(Padding.NONE) char('-') - dayOfMonth(Padding.NONE) + day(Padding.NONE) char(' ') hour(Padding.NONE) char(':') @@ -168,7 +168,7 @@ class LocalDateTimeFormatTest { char('-') monthNumber(Padding.SPACE) char('-') - dayOfMonth(Padding.SPACE) + day(Padding.SPACE) char(' ') hour(Padding.SPACE) char(':') @@ -230,7 +230,7 @@ class LocalDateTimeFormatTest { val format1 = LocalDateTime.Format { date(LocalDate.Formats.ISO); char(' '); time(LocalTime.Formats.ISO) } assertEquals("2020-08-30 18:43:13", dateTime.format(format1)) val format2 = LocalDateTime.Format { - monthNumber(); char('/'); dayOfMonth() + monthNumber(); char('/'); day() char(' ') hour(); char(':'); minute() optional { char(':'); second() } diff --git a/core/common/test/samples/LocalDateSamples.kt b/core/common/test/samples/LocalDateSamples.kt index 194af1f8..a70776d4 100644 --- a/core/common/test/samples/LocalDateSamples.kt +++ b/core/common/test/samples/LocalDateSamples.kt @@ -24,7 +24,7 @@ class LocalDateSamples { // Parsing LocalDate values using predefined and custom formats check(LocalDate.parse("2024-04-16") == LocalDate(2024, Month.APRIL, 16)) val customFormat = LocalDate.Format { - monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); chars(", "); year() + monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); day(); chars(", "); year() } check(LocalDate.parse("Apr 16, 2024", customFormat) == LocalDate(2024, Month.APRIL, 16)) } @@ -42,7 +42,7 @@ class LocalDateSamples { fun customFormat() { // Parsing and formatting LocalDate values using a custom format val customFormat = LocalDate.Format { - monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); chars(", "); year() + monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); day(); chars(", "); year() } val date = customFormat.parse("Apr 16, 2024") check(date == LocalDate(2024, Month.APRIL, 16)) @@ -55,9 +55,9 @@ class LocalDateSamples { // Constructing a LocalDate value using its constructor val date = LocalDate(2024, 4, 16) check(date.year == 2024) - check(date.monthNumber == 4) + check(date.month.number == 4) check(date.month == Month.APRIL) - check(date.dayOfMonth == 16) + check(date.day == 16) } @Test @@ -66,7 +66,7 @@ class LocalDateSamples { val date = LocalDate(2024, Month.APRIL, 16) check(date.year == 2024) check(date.month == Month.APRIL) - check(date.dayOfMonth == 16) + check(date.day == 16) } @Test @@ -86,10 +86,10 @@ class LocalDateSamples { } @Test - fun dayOfMonth() { + fun day() { // Getting the day of the month - for (dayOfMonth in 1..30) { - check(LocalDate(2024, Month.APRIL, dayOfMonth).dayOfMonth == dayOfMonth) + for (day in 1..30) { + check(LocalDate(2024, Month.APRIL, day).day == day) } } @@ -140,7 +140,7 @@ class LocalDateSamples { check(LocalDate(2024, 4, 16).toString() == "2024-04-16") check(LocalDate(2024, 4, 16).format(LocalDate.Formats.ISO) == "2024-04-16") val customFormat = LocalDate.Format { - monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); chars(", "); year() + monthName(MonthNames.ENGLISH_ABBREVIATED); char(' '); day(); chars(", "); year() } check(LocalDate(2024, 4, 16).format(customFormat) == "Apr 16, 2024") } diff --git a/core/common/test/samples/LocalDateTimeSamples.kt b/core/common/test/samples/LocalDateTimeSamples.kt index 7b8c7ae9..eea04c30 100644 --- a/core/common/test/samples/LocalDateTimeSamples.kt +++ b/core/common/test/samples/LocalDateTimeSamples.kt @@ -14,9 +14,9 @@ class LocalDateTimeSamples { @Test fun alternativeConstruction() { // Constructing a LocalDateTime value by specifying its components - val dateTime1 = LocalDateTime(year = 2021, monthNumber = 3, dayOfMonth = 27, hour = 2, minute = 16, second = 20) + val dateTime1 = LocalDateTime(year = 2021, month = 3, day = 27, hour = 2, minute = 16, second = 20) val dateTime2 = LocalDateTime( - year = 2021, month = Month.MARCH, dayOfMonth = 27, + year = 2021, month = Month.MARCH, day = 27, hour = 2, minute = 16, second = 20, nanosecond = 0 ) check(dateTime1 == dateTime2) @@ -71,21 +71,21 @@ class LocalDateTimeSamples { // Constructing a LocalDateTime value using its constructor val dateTime = LocalDateTime( year = 2024, - monthNumber = 2, - dayOfMonth = 15, + month = 2, + day = 15, hour = 16, minute = 48, second = 59, - nanosecond = 999_999_999, + nanosecond = 999_999_999 ) check(dateTime.date == LocalDate(2024, 2, 15)) check(dateTime.time == LocalTime(16, 48, 59, 999_999_999)) val dateTimeWithoutSeconds = LocalDateTime( year = 2024, - monthNumber = 2, - dayOfMonth = 15, + month = 2, + day = 15, hour = 16, - minute = 48, + minute = 48 ) check(dateTimeWithoutSeconds.date == LocalDate(2024, 2, 15)) check(dateTimeWithoutSeconds.time == LocalTime(16, 48)) @@ -97,20 +97,20 @@ class LocalDateTimeSamples { val dateTime = LocalDateTime( year = 2024, month = Month.FEBRUARY, - dayOfMonth = 15, + day = 15, hour = 16, minute = 48, second = 59, - nanosecond = 999_999_999, + nanosecond = 999_999_999 ) check(dateTime.date == LocalDate(2024, Month.FEBRUARY, 15)) check(dateTime.time == LocalTime(16, 48, 59, 999_999_999)) val dateTimeWithoutSeconds = LocalDateTime( year = 2024, month = Month.FEBRUARY, - dayOfMonth = 15, + day = 15, hour = 16, - minute = 48, + minute = 48 ) check(dateTimeWithoutSeconds.date == LocalDate(2024, Month.FEBRUARY, 15)) check(dateTimeWithoutSeconds.time == LocalTime(16, 48)) @@ -136,8 +136,7 @@ class LocalDateTimeSamples { val dateTime = LocalDateTime(date, time) check(dateTime.year == dateTime.date.year) check(dateTime.month == dateTime.date.month) - check(dateTime.monthNumber == dateTime.date.monthNumber) - check(dateTime.dayOfMonth == dateTime.date.dayOfMonth) + check(dateTime.day == dateTime.date.day) check(dateTime.dayOfWeek == dateTime.date.dayOfWeek) check(dateTime.dayOfYear == dateTime.date.dayOfYear) } diff --git a/core/common/test/samples/LocalTimeSamples.kt b/core/common/test/samples/LocalTimeSamples.kt index df75f6ce..3bbb19e8 100644 --- a/core/common/test/samples/LocalTimeSamples.kt +++ b/core/common/test/samples/LocalTimeSamples.kt @@ -242,7 +242,7 @@ class LocalTimeSamples { val firstMorningOfEveryMonth = (1..12).map { month -> morning.atDate(2021, month, 1) } - check(firstMorningOfEveryMonth.all { it.time == morning && it.dayOfMonth == 1 }) + check(firstMorningOfEveryMonth.all { it.time == morning && it.day == 1 }) } /** @@ -255,7 +255,7 @@ class LocalTimeSamples { val firstMorningOfEveryMonth = Month.entries.map { month -> morning.atDate(2021, month, 1) } - check(firstMorningOfEveryMonth.all { it.time == morning && it.dayOfMonth == 1 }) + check(firstMorningOfEveryMonth.all { it.time == morning && it.day == 1 }) } @Test diff --git a/core/common/test/samples/format/DateTimeComponentsSamples.kt b/core/common/test/samples/format/DateTimeComponentsSamples.kt index e3e81daa..fbfd5d19 100644 --- a/core/common/test/samples/format/DateTimeComponentsSamples.kt +++ b/core/common/test/samples/format/DateTimeComponentsSamples.kt @@ -167,13 +167,13 @@ class DateTimeComponentsSamples { fun date() { // Formatting and parsing a date in complex scenarios val format = DateTimeComponents.Format { - year(); char('-'); monthNumber(); char('-'); dayOfMonth() + year(); char('-'); monthNumber(); char('-'); day() } val formattedDate = format.format { setDate(LocalDate(2023, 1, 2)) check(year == 2023) check(month == Month.JANUARY) - check(dayOfMonth == 2) + check(day == 2) check(dayOfWeek == DayOfWeek.MONDAY) check(dayOfYear == 2) } @@ -182,7 +182,7 @@ class DateTimeComponentsSamples { check(parsedDate.toLocalDate() == LocalDate(2023, 1, 2)) check(parsedDate.year == 2023) check(parsedDate.month == Month.JANUARY) - check(parsedDate.dayOfMonth == 2) + check(parsedDate.day == 2) check(parsedDate.dayOfWeek == null) check(parsedDate.dayOfYear == null) } diff --git a/core/common/test/samples/format/DateTimeFormatBuilderSamples.kt b/core/common/test/samples/format/DateTimeFormatBuilderSamples.kt index c660c78c..a8190acd 100644 --- a/core/common/test/samples/format/DateTimeFormatBuilderSamples.kt +++ b/core/common/test/samples/format/DateTimeFormatBuilderSamples.kt @@ -17,7 +17,7 @@ class DateTimeFormatBuilderSamples { val format = LocalDate.Format { monthNumber() char('/') - dayOfMonth() + day() chars(", ") year() } @@ -96,7 +96,7 @@ class DateTimeFormatBuilderSamples { char('-') monthNumber() char('-') - dayOfMonth() + day() } check(LocalDate(2020, 1, 1).format(format) == "2020-01-01") } diff --git a/core/common/test/samples/format/DateTimeFormatSamples.kt b/core/common/test/samples/format/DateTimeFormatSamples.kt index aabd28bb..1a91c7a2 100644 --- a/core/common/test/samples/format/DateTimeFormatSamples.kt +++ b/core/common/test/samples/format/DateTimeFormatSamples.kt @@ -43,7 +43,7 @@ class DateTimeFormatSamples { // the input string is in the expected format, but the value is invalid } // to parse strings that have valid formats but invalid values, use `DateTimeComponents`: - check(DateTimeComponents.Format { date(LocalDate.Formats.ISO) }.parse("2021-02-40").dayOfMonth == 40) + check(DateTimeComponents.Format { date(LocalDate.Formats.ISO) }.parse("2021-02-40").day == 40) } @Test @@ -55,7 +55,7 @@ class DateTimeFormatSamples { check(LocalDate.Formats.ISO.parseOrNull("2021-02-40") == null) // to parse strings that have valid formats but invalid values, use `DateTimeComponents`: val dateTimeComponentsFormat = DateTimeComponents.Format { date(LocalDate.Formats.ISO) } - check(dateTimeComponentsFormat.parseOrNull("2021-02-40")?.dayOfMonth == 40) + check(dateTimeComponentsFormat.parseOrNull("2021-02-40")?.day == 40) } @Test @@ -70,7 +70,7 @@ class DateTimeFormatSamples { customFormatAsKotlinCode.contains(""" monthNumber() char('/') - dayOfMonth() + day() char(' ') year() """.trimIndent()) @@ -86,7 +86,7 @@ class DateTimeFormatSamples { chars(", ") monthNumber(Padding.NONE) char('/') - dayOfMonth(Padding.ZERO) + day(Padding.ZERO) } val leoFirstReignStart = LocalDate(457, 2, 7) check(leoFirstReignStart.format(format) == " 457, 2/07") @@ -98,7 +98,7 @@ class DateTimeFormatSamples { val format = LocalDate.Format { monthNumber(Padding.ZERO) // padding with zeros is the default, but can be explicitly specified char('/') - dayOfMonth() + day() char(' ') year() } @@ -119,7 +119,7 @@ class DateTimeFormatSamples { val format = LocalDate.Format { monthNumber(Padding.NONE) char('/') - dayOfMonth() + day() char(' ') year() } @@ -136,7 +136,7 @@ class DateTimeFormatSamples { val format = LocalDate.Format { monthNumber(Padding.SPACE) char('/') - dayOfMonth() + day() char(' ') year() } diff --git a/core/common/test/samples/format/LocalDateFormatSamples.kt b/core/common/test/samples/format/LocalDateFormatSamples.kt index 192ec754..50b50e27 100644 --- a/core/common/test/samples/format/LocalDateFormatSamples.kt +++ b/core/common/test/samples/format/LocalDateFormatSamples.kt @@ -15,7 +15,7 @@ class LocalDateFormatSamples { fun year() { // Using the year number in a custom format val format = LocalDate.Format { - year(); char(' '); monthNumber(); char('/'); dayOfMonth() + year(); char(' '); monthNumber(); char('/'); day() } check(format.format(LocalDate(2021, 1, 13)) == "2021 01/13") check(format.format(LocalDate(13, 1, 13)) == "0013 01/13") @@ -27,7 +27,7 @@ class LocalDateFormatSamples { fun yearTwoDigits() { // Using two-digit years in a custom format val format = LocalDate.Format { - yearTwoDigits(baseYear = 1960); char(' '); monthNumber(); char('/'); dayOfMonth() + yearTwoDigits(baseYear = 1960); char(' '); monthNumber(); char('/'); day() } check(format.format(LocalDate(1960, 1, 13)) == "60 01/13") check(format.format(LocalDate(2000, 1, 13)) == "00 01/13") @@ -41,12 +41,12 @@ class LocalDateFormatSamples { fun monthNumber() { // Using month number with various paddings in a custom format val zeroPaddedMonths = LocalDate.Format { - monthNumber(); char('/'); dayOfMonth(); char('/'); year() + monthNumber(); char('/'); day(); char('/'); year() } check(zeroPaddedMonths.format(LocalDate(2021, 1, 13)) == "01/13/2021") check(zeroPaddedMonths.format(LocalDate(2021, 12, 13)) == "12/13/2021") val spacePaddedMonths = LocalDate.Format { - monthNumber(padding = Padding.SPACE); char('/'); dayOfMonth(); char('/'); year() + monthNumber(padding = Padding.SPACE); char('/'); day(); char('/'); year() } check(spacePaddedMonths.format(LocalDate(2021, 1, 13)) == " 1/13/2021") check(spacePaddedMonths.format(LocalDate(2021, 12, 13)) == "12/13/2021") @@ -56,7 +56,7 @@ class LocalDateFormatSamples { fun monthName() { // Using strings for month names in a custom format val format = LocalDate.Format { - monthName(MonthNames.ENGLISH_FULL); char(' '); dayOfMonth(); char('/'); year() + monthName(MonthNames.ENGLISH_FULL); char(' '); day(); char('/'); year() } check(format.format(LocalDate(2021, 1, 13)) == "January 13/2021") check(format.format(LocalDate(2021, 12, 13)) == "December 13/2021") @@ -66,12 +66,12 @@ class LocalDateFormatSamples { fun dayOfMonth() { // Using day-of-month with various paddings in a custom format val zeroPaddedDays = LocalDate.Format { - dayOfMonth(); char('/'); monthNumber(); char('/'); year() + day(); char('/'); monthNumber(); char('/'); year() } check(zeroPaddedDays.format(LocalDate(2021, 1, 6)) == "06/01/2021") check(zeroPaddedDays.format(LocalDate(2021, 1, 31)) == "31/01/2021") val spacePaddedDays = LocalDate.Format { - dayOfMonth(padding = Padding.SPACE); char('/'); monthNumber(); char('/'); year() + day(padding = Padding.SPACE); char('/'); monthNumber(); char('/'); year() } check(spacePaddedDays.format(LocalDate(2021, 1, 6)) == " 6/01/2021") check(spacePaddedDays.format(LocalDate(2021, 1, 31)) == "31/01/2021") @@ -81,7 +81,7 @@ class LocalDateFormatSamples { fun dayOfWeek() { // Using strings for day-of-week names in a custom format val format = LocalDate.Format { - dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED); char(' '); dayOfMonth(); char('/'); monthNumber(); char('/'); year() + dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED); char(' '); day(); char('/'); monthNumber(); char('/'); year() } check(format.format(LocalDate(2021, 1, 13)) == "Wed 13/01/2021") check(format.format(LocalDate(2021, 12, 13)) == "Mon 13/12/2021") @@ -115,7 +115,7 @@ class LocalDateFormatSamples { val format = LocalDate.Format { monthName(MonthNames.ENGLISH_ABBREVIATED) // "Jan", "Feb", ... char(' ') - dayOfMonth() + day() chars(", ") year() } @@ -159,7 +159,7 @@ class LocalDateFormatSamples { val format = LocalDate.Format { monthName(MonthNames.ENGLISH_FULL) char(' ') - dayOfMonth() + day() chars(", ") year() } @@ -172,7 +172,7 @@ class LocalDateFormatSamples { val format = LocalDate.Format { monthName(MonthNames.ENGLISH_ABBREVIATED) char(' ') - dayOfMonth() + day() chars(", ") year() } diff --git a/core/common/test/samples/format/UnicodeSamples.kt b/core/common/test/samples/format/UnicodeSamples.kt index 26d9a16f..ad9438e0 100644 --- a/core/common/test/samples/format/UnicodeSamples.kt +++ b/core/common/test/samples/format/UnicodeSamples.kt @@ -22,7 +22,7 @@ class UnicodeSamples { DateTimeFormat.formatAsKotlinBuilderDsl(customFormat) == """ monthNumber() char('/') - dayOfMonth() + day() char(' ') year() """.trimIndent() diff --git a/core/commonJs/src/LocalDate.kt b/core/commonJs/src/LocalDate.kt index bfca5511..6fd51712 100644 --- a/core/commonJs/src/LocalDate.kt +++ b/core/commonJs/src/LocalDate.kt @@ -55,20 +55,23 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa public actual val ISO_BASIC: DateTimeFormat = ISO_DATE_BASIC } - public actual constructor(year: Int, monthNumber: Int, dayOfMonth: Int) : + public actual constructor(year: Int, month: Int, day: Int) : this(try { - jsTry { jtLocalDate.of(year, monthNumber, dayOfMonth) } + jsTry { jtLocalDate.of(year, month, day) } } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw IllegalArgumentException(e) throw e }) - public actual constructor(year: Int, month: Month, dayOfMonth: Int) : this(year, month.number, dayOfMonth) + public actual constructor(year: Int, month: Month, day: Int) : this(year, month.number, day) public actual val year: Int get() = value.year() + @Deprecated("Use the 'month' property instead", ReplaceWith("this.month.number"), level = DeprecationLevel.WARNING) public actual val monthNumber: Int get() = value.monthValue() public actual val month: Month get() = value.month().toMonth() + @Deprecated("Use the 'day' property instead", ReplaceWith("this.day"), level = DeprecationLevel.WARNING) public actual val dayOfMonth: Int get() = value.dayOfMonth() + public actual val day: Int get() = value.dayOfMonth() public actual val dayOfWeek: DayOfWeek get() = value.dayOfWeek().toDayOfWeek() public actual val dayOfYear: Int get() = value.dayOfYear() diff --git a/core/commonJs/src/LocalDateTime.kt b/core/commonJs/src/LocalDateTime.kt index b8c8f67d..ab098b2f 100644 --- a/core/commonJs/src/LocalDateTime.kt +++ b/core/commonJs/src/LocalDateTime.kt @@ -15,24 +15,27 @@ import kotlinx.datetime.internal.JSJoda.LocalDateTime as jtLocalDateTime @Serializable(with = LocalDateTimeIso8601Serializer::class) public actual class LocalDateTime internal constructor(internal val value: jtLocalDateTime) : Comparable { - public actual constructor(year: Int, monthNumber: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : + public actual constructor(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : this(try { - jsTry { jtLocalDateTime.of(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond) } + jsTry { jtLocalDateTime.of(year, month, day, hour, minute, second, nanosecond) } } catch (e: Throwable) { if (e.isJodaDateTimeException()) throw IllegalArgumentException(e) throw e }) - public actual constructor(year: Int, month: Month, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : - this(year, month.number, dayOfMonth, hour, minute, second, nanosecond) + public actual constructor(year: Int, month: Month, day: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : + this(year, month.number, day, hour, minute, second, nanosecond) public actual constructor(date: LocalDate, time: LocalTime) : this(jsTry { jtLocalDateTime.of(date.value, time.value) }) public actual val year: Int get() = value.year() + @Deprecated("Use the 'month' property instead", ReplaceWith("this.month.number"), level = DeprecationLevel.WARNING) public actual val monthNumber: Int get() = value.monthValue() public actual val month: Month get() = value.month().toMonth() + @Deprecated("Use the 'day' property instead", ReplaceWith("this.day"), level = DeprecationLevel.WARNING) public actual val dayOfMonth: Int get() = value.dayOfMonth() + public actual val day: Int get() = value.dayOfMonth() public actual val dayOfWeek: DayOfWeek get() = value.dayOfWeek().toDayOfWeek() public actual val dayOfYear: Int get() = value.dayOfYear() diff --git a/core/commonKotlin/src/LocalDate.kt b/core/commonKotlin/src/LocalDate.kt index 14ee3a17..1507cbf4 100644 --- a/core/commonKotlin/src/LocalDate.kt +++ b/core/commonKotlin/src/LocalDate.kt @@ -23,23 +23,29 @@ private fun isValidYear(year: Int): Boolean = year >= YEAR_MIN && year <= YEAR_MAX @Serializable(with = LocalDateIso8601Serializer::class) -public actual class LocalDate actual constructor(public actual val year: Int, public actual val monthNumber: Int, public actual val dayOfMonth: Int) : Comparable { +public actual class LocalDate actual constructor(public actual val year: Int, month: Int, public actual val day: Int) : Comparable { + + private val _month: Int = month + @Deprecated("Use the 'month' property instead", ReplaceWith("this.month.number"), level = DeprecationLevel.WARNING) + public actual val monthNumber: Int get() = _month + @Deprecated("Use the 'day' property instead", ReplaceWith("this.day"), level = DeprecationLevel.WARNING) + public actual val dayOfMonth: Int get() = day init { // org.threeten.bp.LocalDate#create require(isValidYear(year)) { "Invalid date: the year is out of range" } - require(monthNumber in 1..12) { "Invalid date: month must be a number between 1 and 12, got $monthNumber" } - require(dayOfMonth in 1..31) { "Invalid date: day of month must be a number between 1 and 31, got $dayOfMonth" } - if (dayOfMonth > 28 && dayOfMonth > monthNumber.monthLength(isLeapYear(year))) { - if (dayOfMonth == 29) { + require(_month in 1..12) { "Invalid date: month must be a number between 1 and 12, got $_month" } + require(day in 1..31) { "Invalid date: day of month must be a number between 1 and 31, got $day" } + if (day > 28 && day > _month.monthLength(isLeapYear(year))) { + if (day == 29) { throw IllegalArgumentException("Invalid date 'February 29' as '$year' is not a leap year") } else { - throw IllegalArgumentException("Invalid date '${month.name} $dayOfMonth'") + throw IllegalArgumentException("Invalid date '${Month(month)} $day'") } } } - public actual constructor(year: Int, month: Month, dayOfMonth: Int) : this(year, month.number, dayOfMonth) + public actual constructor(year: Int, month: Month, day: Int) : this(year, month.number, day) public actual companion object { public actual fun parse(input: CharSequence, format: DateTimeFormat): LocalDate = format.parse(input) @@ -102,7 +108,7 @@ public actual class LocalDate actual constructor(public actual val year: Int, pu // org.threeten.bp.LocalDate#toEpochDay public actual fun toEpochDays(): Int { val y = year - val m = monthNumber + val m = _month var total = 0 total += 365 * y if (y >= 0) { @@ -111,7 +117,7 @@ public actual class LocalDate actual constructor(public actual val year: Int, pu total -= y / -4 - y / -100 + y / -400 } total += ((367 * m - 362) / 12) - total += dayOfMonth - 1 + total += day - 1 if (m > 2) { total-- if (!isLeapYear(year)) { @@ -122,7 +128,7 @@ public actual class LocalDate actual constructor(public actual val year: Int, pu } public actual val month: Month - get() = Month(monthNumber) + get() = Month(_month) // org.threeten.bp.LocalDate#getDayOfWeek public actual val dayOfWeek: DayOfWeek @@ -133,7 +139,7 @@ public actual class LocalDate actual constructor(public actual val year: Int, pu // org.threeten.bp.LocalDate#getDayOfYear public actual val dayOfYear: Int - get() = month.firstDayOfYear(isLeapYear(year)) + dayOfMonth - 1 + get() = month.firstDayOfYear(isLeapYear(year)) + day - 1 // Several times faster than using `compareBy` actual override fun compareTo(other: LocalDate): Int { @@ -141,11 +147,11 @@ public actual class LocalDate actual constructor(public actual val year: Int, pu if (y != 0) { return y } - val m = monthNumber.compareTo(other.monthNumber) + val m = _month.compareTo(other._month) if (m != 0) { return m } - return dayOfMonth.compareTo(other.dayOfMonth) + return day.compareTo(other.day) } // org.threeten.bp.LocalDate#resolvePreviousValid @@ -166,11 +172,11 @@ public actual class LocalDate actual constructor(public actual val year: Int, pu if (monthsToAdd == 0) { return this } - val monthCount = year * 12 + (monthNumber - 1) + val monthCount = year * 12 + (_month - 1) val calcMonths = safeAdd(monthCount, monthsToAdd) val newYear = calcMonths.floorDiv(12) val newMonth = calcMonths.mod(12) + 1 - return resolvePreviousValid(newYear, newMonth, dayOfMonth) + return resolvePreviousValid(newYear, newMonth, day) } // org.threeten.bp.LocalDate#plusDays @@ -188,8 +194,8 @@ public actual class LocalDate actual constructor(public actual val year: Int, pu // org.threeten.bp.LocalDate#hashCode override fun hashCode(): Int { val yearValue = year - val monthValue: Int = monthNumber - val dayValue: Int = dayOfMonth + val monthValue: Int = _month + val dayValue: Int = day return yearValue and -0x800 xor (yearValue shl 11) + (monthValue shl 6) + dayValue } @@ -243,12 +249,12 @@ public actual fun LocalDate.daysUntil(other: LocalDate): Int = other.toEpochDays() - this.toEpochDays() // org.threeten.bp.LocalDate#getProlepticMonth -internal val LocalDate.prolepticMonth get() = (year * 12) + (monthNumber - 1) +internal val LocalDate.prolepticMonth get() = (year * 12) + (month.number - 1) // org.threeten.bp.LocalDate#monthsUntil public actual fun LocalDate.monthsUntil(other: LocalDate): Int { - val packed1 = prolepticMonth * 32 + dayOfMonth - val packed2 = other.prolepticMonth * 32 + other.dayOfMonth + val packed1 = prolepticMonth * 32 + day + val packed2 = other.prolepticMonth * 32 + other.day return (packed2 - packed1) / 32 } diff --git a/core/commonKotlin/src/LocalDateTime.kt b/core/commonKotlin/src/LocalDateTime.kt index 33187d4a..d878c7e1 100644 --- a/core/commonKotlin/src/LocalDateTime.kt +++ b/core/commonKotlin/src/LocalDateTime.kt @@ -35,16 +35,19 @@ public actual constructor(public actual val date: LocalDate, public actual val t public actual val ISO: DateTimeFormat = ISO_DATETIME } - public actual constructor(year: Int, monthNumber: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : - this(LocalDate(year, monthNumber, dayOfMonth), LocalTime.of(hour, minute, second, nanosecond)) + public actual constructor(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : + this(LocalDate(year, month, day), LocalTime.of(hour, minute, second, nanosecond)) - public actual constructor(year: Int, month: Month, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : - this(LocalDate(year, month, dayOfMonth), LocalTime.of(hour, minute, second, nanosecond)) + public actual constructor(year: Int, month: Month, day: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : + this(LocalDate(year, month, day), LocalTime.of(hour, minute, second, nanosecond)) public actual val year: Int get() = date.year - public actual val monthNumber: Int get() = date.monthNumber + @Deprecated("Use the 'month' property instead", ReplaceWith("this.month.number"), level = DeprecationLevel.WARNING) + public actual val monthNumber: Int get() = date.month.number public actual val month: Month get() = date.month - public actual val dayOfMonth: Int get() = date.dayOfMonth + @Deprecated("Use the 'day' property instead", ReplaceWith("this.day"), level = DeprecationLevel.WARNING) + public actual val dayOfMonth: Int get() = date.day + public actual val day: Int get() = date.day public actual val dayOfWeek: DayOfWeek get() = date.dayOfWeek public actual val dayOfYear: Int get() = date.dayOfYear public actual val hour: Int get() = time.hour diff --git a/core/commonKotlin/src/internal/MonthDayTime.kt b/core/commonKotlin/src/internal/MonthDayTime.kt index 22cb0a06..a7e564e2 100644 --- a/core/commonKotlin/src/internal/MonthDayTime.kt +++ b/core/commonKotlin/src/internal/MonthDayTime.kt @@ -53,7 +53,7 @@ internal fun JulianDayOfYearSkippingLeapDate(dayOfYear: Int) : DateOfYear { // For example, `dayOfYear = 60` is always 1st March, even in leap years. // We take a non-leap year, as in that case, this is the same as JulianDayOfYear, so regular addition works. val date = LocalDate(2011, 1, 1).plusDays(dayOfYear - 1) - return MonthDayOfYear(date.month, MonthDayOfYear.TransitionDay.ExactlyDayOfMonth(date.dayOfMonth)) + return MonthDayOfYear(date.month, MonthDayOfYear.TransitionDay.ExactlyDayOfMonth(date.day)) } internal class MonthDayOfYear(val month: Month, val day: TransitionDay) : DateOfYear { diff --git a/core/darwin/src/Converters.kt b/core/darwin/src/Converters.kt index 6ffdfe65..cf785dea 100644 --- a/core/darwin/src/Converters.kt +++ b/core/darwin/src/Converters.kt @@ -74,8 +74,8 @@ public fun NSTimeZone.toKotlinTimeZone(): TimeZone = TimeZone.of(name) public fun LocalDate.toNSDateComponents(): NSDateComponents { val components = NSDateComponents() components.year = year.convert() - components.month = monthNumber.convert() - components.day = dayOfMonth.convert() + components.month = month.number.convert() + components.day = day.convert() return components } diff --git a/core/jvm/src/LocalDate.kt b/core/jvm/src/LocalDate.kt index 8d1bcc23..067faebc 100644 --- a/core/jvm/src/LocalDate.kt +++ b/core/jvm/src/LocalDate.kt @@ -51,19 +51,22 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa public actual val ISO_BASIC: DateTimeFormat = ISO_DATE_BASIC } - public actual constructor(year: Int, monthNumber: Int, dayOfMonth: Int) : + public actual constructor(year: Int, month: Int, day: Int) : this(try { - jtLocalDate.of(year, monthNumber, dayOfMonth) + jtLocalDate.of(year, month, day) } catch (e: DateTimeException) { throw IllegalArgumentException(e) }) - public actual constructor(year: Int, month: Month, dayOfMonth: Int) : this(year, month.number, dayOfMonth) + public actual constructor(year: Int, month: Month, day: Int) : this(year, month.number, day) public actual val year: Int get() = value.year + @Deprecated("Use the 'month' property instead", ReplaceWith("this.month.number"), level = DeprecationLevel.WARNING) public actual val monthNumber: Int get() = value.monthValue public actual val month: Month get() = value.month + @Deprecated("Use the 'day' property instead", ReplaceWith("this.day"), level = DeprecationLevel.WARNING) public actual val dayOfMonth: Int get() = value.dayOfMonth + public actual val day: Int get() = value.dayOfMonth public actual val dayOfWeek: DayOfWeek get() = value.dayOfWeek public actual val dayOfYear: Int get() = value.dayOfYear diff --git a/core/jvm/src/LocalDateTime.kt b/core/jvm/src/LocalDateTime.kt index 406b16cd..89df0eb8 100644 --- a/core/jvm/src/LocalDateTime.kt +++ b/core/jvm/src/LocalDateTime.kt @@ -19,23 +19,26 @@ public actual typealias DayOfWeek = java.time.DayOfWeek @Serializable(with = LocalDateTimeIso8601Serializer::class) public actual class LocalDateTime internal constructor(internal val value: jtLocalDateTime) : Comparable { - public actual constructor(year: Int, monthNumber: Int, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : + public actual constructor(year: Int, month: Int, day: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : this(try { - jtLocalDateTime.of(year, monthNumber, dayOfMonth, hour, minute, second, nanosecond) + jtLocalDateTime.of(year, month, day, hour, minute, second, nanosecond) } catch (e: DateTimeException) { throw IllegalArgumentException(e) }) - public actual constructor(year: Int, month: Month, dayOfMonth: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : - this(year, month.number, dayOfMonth, hour, minute, second, nanosecond) + public actual constructor(year: Int, month: Month, day: Int, hour: Int, minute: Int, second: Int, nanosecond: Int) : + this(year, month.number, day, hour, minute, second, nanosecond) public actual constructor(date: LocalDate, time: LocalTime) : this(jtLocalDateTime.of(date.value, time.value)) public actual val year: Int get() = value.year + @Deprecated("Use the 'month' property instead", ReplaceWith("this.month.number"), level = DeprecationLevel.WARNING) public actual val monthNumber: Int get() = value.monthValue public actual val month: Month get() = value.month + @Deprecated("Use the 'day' property instead", ReplaceWith("this.day"), level = DeprecationLevel.WARNING) public actual val dayOfMonth: Int get() = value.dayOfMonth + public actual val day: Int get() = value.dayOfMonth public actual val dayOfWeek: DayOfWeek get() = value.dayOfWeek public actual val dayOfYear: Int get() = value.dayOfYear diff --git a/core/jvm/test/ConvertersTest.kt b/core/jvm/test/ConvertersTest.kt index 18d75993..52b8c243 100644 --- a/core/jvm/test/ConvertersTest.kt +++ b/core/jvm/test/ConvertersTest.kt @@ -61,7 +61,7 @@ class ConvertersTest { @Test fun localDateTime() { fun test(ktDateTime: LocalDateTime) { - val jtDateTime = with(ktDateTime) { JTLocalDateTime.of(year, month, dayOfMonth, hour, minute, second, nanosecond) } + val jtDateTime = with(ktDateTime) { JTLocalDateTime.of(year, month, day, hour, minute, second, nanosecond) } assertEquals(ktDateTime, jtDateTime.toKotlinLocalDateTime()) assertEquals(jtDateTime, ktDateTime.toJavaLocalDateTime()) @@ -95,7 +95,7 @@ class ConvertersTest { @Test fun localDate() { fun test(ktDate: LocalDate) { - val jtDate = with(ktDate) { JTLocalDate.of(year, month, dayOfMonth) } + val jtDate = with(ktDate) { JTLocalDate.of(year, month, day) } assertEquals(ktDate, jtDate.toKotlinLocalDate()) assertEquals(jtDate, ktDate.toJavaLocalDate()) diff --git a/core/jvm/test/UnicodeFormatTest.kt b/core/jvm/test/UnicodeFormatTest.kt index fe2faa18..67982bda 100644 --- a/core/jvm/test/UnicodeFormatTest.kt +++ b/core/jvm/test/UnicodeFormatTest.kt @@ -168,7 +168,7 @@ private val dateTimeComponentsTemporalQuery = TemporalQuery { accessor -> ChronoField.YEAR_OF_ERA to { year = it }, ChronoField.YEAR to { year = it }, ChronoField.MONTH_OF_YEAR to { monthNumber = it }, - ChronoField.DAY_OF_MONTH to { dayOfMonth = it }, + ChronoField.DAY_OF_MONTH to { day = it }, ChronoField.DAY_OF_YEAR to { dayOfYear = it }, ChronoField.DAY_OF_WEEK to { dayOfWeek = DayOfWeek(it) }, ChronoField.AMPM_OF_DAY to { amPm = if (it == 1) AmPmMarker.PM else AmPmMarker.AM },