Skip to content

Commit f764b7b

Browse files
committed
Clarify setting DateTimeComponents.month
1 parent 0e295ae commit f764b7b

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

core/common/src/format/DateTimeComponents.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,14 @@ public class DateTimeComponents internal constructor(internal val contents: Date
274274

275275
/**
276276
* The month ([Month]) component of the date.
277+
*
278+
* This is a view of [monthNumber].
279+
* Setting it will set [monthNumber], and getting it will return a [Month] instance if [monthNumber] is a valid
280+
* month.
281+
*
277282
* @throws IllegalArgumentException during getting if [monthNumber] is outside the `1..12` range.
278283
* @sample kotlinx.datetime.test.samples.format.DateTimeComponentsSamples.date
284+
* @sample kotlinx.datetime.test.samples.format.DateTimeComponentsSamples.setMonth
279285
*/
280286
public var month: Month?
281287
get() = monthNumber?.let { Month(it) }

core/common/test/samples/format/DateTimeComponentsSamples.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ class DateTimeComponentsSamples {
155155
check(parsedDate.dayOfWeek == null)
156156
}
157157

158+
@Test
159+
fun setMonth() {
160+
val input = "Mon, 30 Jul 2008 11:05:30 GMT"
161+
val parsed = DateTimeComponents.Formats.RFC_1123.parse(input)
162+
check(parsed.monthNumber == 7)
163+
check(parsed.month == Month.JULY)
164+
parsed.month = Month.JUNE
165+
check(parsed.monthNumber == 6)
166+
check(parsed.month == Month.JUNE)
167+
}
168+
158169
@Test
159170
fun timeAmPm() {
160171
val format = DateTimeComponents.Format {

0 commit comments

Comments
 (0)