@@ -58,7 +58,7 @@ import kotlinx.serialization.Serializable
58
58
* @sample kotlinx.datetime.test.samples.YearMonthSamples.customFormat
59
59
*/
60
60
@Serializable(with = YearMonthIso8601Serializer ::class )
61
- public class YearMonth
61
+ public expect class YearMonth
62
62
/* *
63
63
* Constructs a [YearMonth] instance from the given year-month components.
64
64
*
@@ -78,49 +78,37 @@ public constructor(year: Int, month: Int) : Comparable<YearMonth> {
78
78
*
79
79
* @sample kotlinx.datetime.test.samples.YearMonthSamples.year
80
80
*/
81
- public val year: Int = year
82
-
83
- /* *
84
- * Returns the number-of-the-month (1..12) component of the year-month.
85
- *
86
- * Shortcut for `month.number`.
87
- */
88
- internal val monthNumber: Int = month
89
-
90
- init {
91
- require(month in 1 .. 12 ) { " Month must be in 1..12, but was $month " }
92
- require(year in LocalDate .MIN .year.. LocalDate .MAX .year) {
93
- " Year $year is out of range: ${LocalDate .MIN .year} ..${LocalDate .MAX .year} "
94
- }
95
- }
81
+ public val year: Int
96
82
97
83
/* *
98
84
* Returns the month ([Month]) component of the year-month.
99
85
*
100
86
* @sample kotlinx.datetime.test.samples.YearMonthSamples.month
101
87
*/
102
- public val month: Month get() = Month (monthNumber)
88
+ public val month: Month
103
89
104
90
/* *
105
91
* Returns the first day of the year-month.
106
92
*
107
93
* @sample kotlinx.datetime.test.samples.YearMonthSamples.firstAndLastDay
108
94
*/
109
- public val firstDay: LocalDate get() = onDay( 1 )
95
+ public val firstDay: LocalDate
110
96
111
97
/* *
112
98
* Returns the last day of the year-month.
113
99
*
114
100
* @sample kotlinx.datetime.test.samples.YearMonthSamples.firstAndLastDay
115
101
*/
116
- public val lastDay: LocalDate get() = onDay(numberOfDays)
102
+ public val lastDay: LocalDate
117
103
118
104
/* *
119
105
* Returns the number of days in the year-month.
120
106
*
121
107
* @sample kotlinx.datetime.test.samples.YearMonthSamples.numberOfDays
122
108
*/
123
- public val numberOfDays: Int get() = monthNumber.monthLength(isLeapYear(year))
109
+ public val numberOfDays: Int
110
+
111
+ internal val monthNumber: Int
124
112
125
113
/* *
126
114
* Returns the range of days in the year-month.
@@ -138,7 +126,7 @@ public constructor(year: Int, month: Int) : Comparable<YearMonth> {
138
126
* @throws IllegalArgumentException if [year] is out of range.
139
127
* @sample kotlinx.datetime.test.samples.YearMonthSamples.constructorFunction
140
128
*/
141
- public constructor (year: Int , month: Month ): this (year, month.number)
129
+ public constructor (year: Int , month: Month )
142
130
143
131
public companion object {
144
132
/* *
@@ -155,8 +143,7 @@ public constructor(year: Int, month: Int) : Comparable<YearMonth> {
155
143
* @see YearMonth.format for formatting using a custom format.
156
144
* @sample kotlinx.datetime.test.samples.YearMonthSamples.parsing
157
145
*/
158
- public fun parse (input : CharSequence , format : DateTimeFormat <YearMonth > = Formats .ISO ): YearMonth =
159
- format.parse(input)
146
+ public fun parse (input : CharSequence , format : DateTimeFormat <YearMonth > = Formats .ISO ): YearMonth
160
147
161
148
/* *
162
149
* Creates a new format for parsing and formatting [YearMonth] values.
@@ -167,8 +154,7 @@ public constructor(year: Int, month: Int) : Comparable<YearMonth> {
167
154
* @sample kotlinx.datetime.test.samples.YearMonthSamples.customFormat
168
155
*/
169
156
@Suppress(" FunctionName" )
170
- public fun Format (block : DateTimeFormatBuilder .WithYearMonth .() -> Unit ): DateTimeFormat <YearMonth > =
171
- YearMonthFormat .build(block)
157
+ public fun Format (block : DateTimeFormatBuilder .WithYearMonth .() -> Unit ): DateTimeFormat <YearMonth >
172
158
}
173
159
174
160
/* *
@@ -194,9 +180,7 @@ public constructor(year: Int, month: Int) : Comparable<YearMonth> {
194
180
*
195
181
* @sample kotlinx.datetime.test.samples.YearMonthSamples.Formats.iso
196
182
*/
197
- public val ISO : DateTimeFormat <YearMonth > = YearMonthFormat .build {
198
- year(); char(' -' ); monthNumber()
199
- }
183
+ public val ISO : DateTimeFormat <YearMonth >
200
184
}
201
185
202
186
/* *
@@ -207,7 +191,7 @@ public constructor(year: Int, month: Int) : Comparable<YearMonth> {
207
191
*
208
192
* @sample kotlinx.datetime.test.samples.YearMonthSamples.compareToSample
209
193
*/
210
- override fun compareTo (other : YearMonth ): Int = compareValuesBy( this , other, YearMonth ::year, YearMonth ::month)
194
+ override fun compareTo (other : YearMonth ): Int
211
195
212
196
/* *
213
197
* Converts this year-month to the extended ISO 8601 string representation.
@@ -217,17 +201,7 @@ public constructor(year: Int, month: Int) : Comparable<YearMonth> {
217
201
* @see YearMonth.format for formatting using a custom format.
218
202
* @sample kotlinx.datetime.test.samples.YearMonthSamples.toStringSample
219
203
*/
220
- override fun toString (): String = Formats .ISO .format(this )
221
-
222
- /* *
223
- * @suppress
224
- */
225
- override fun equals (other : Any? ): Boolean = other is YearMonth && year == other.year && month == other.month
226
-
227
- /* *
228
- * @suppress
229
- */
230
- override fun hashCode (): Int = year * 31 + month.hashCode()
204
+ override fun toString (): String
231
205
}
232
206
233
207
/* *
0 commit comments