Skip to content

Commit d630038

Browse files
committed
Implement YearMonth
Fixes #168 Fixes #184
1 parent fbb2187 commit d630038

15 files changed

+1487
-365
lines changed

core/common/src/YearMonth.kt

+397
Large diffs are not rendered by default.

core/common/src/format/DateTimeFormat.kt

+1
Original file line numberDiff line numberDiff line change
@@ -166,5 +166,6 @@ private val allFormatConstants: List<Pair<String, CachedFormatStructure<*>>> by
166166
"${DateTimeFormatBuilder.WithUtcOffset::offset.name}(UtcOffset.Formats.ISO)" to unwrap(UtcOffset.Formats.ISO),
167167
"${DateTimeFormatBuilder.WithUtcOffset::offset.name}(UtcOffset.Formats.ISO_BASIC)" to unwrap(UtcOffset.Formats.ISO_BASIC),
168168
"${DateTimeFormatBuilder.WithUtcOffset::offset.name}(UtcOffset.Formats.FOUR_DIGITS)" to unwrap(UtcOffset.Formats.FOUR_DIGITS),
169+
"${DateTimeFormatBuilder.WithYearMonth::yearMonth.name}(YearMonth.Formats.ISO)" to unwrap(YearMonth.Formats.ISO),
169170
)
170171
}

core/common/src/format/DateTimeFormatBuilder.kt

+18-6
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@ public sealed interface DateTimeFormatBuilder {
2424
public fun chars(value: String)
2525

2626
/**
27-
* Functions specific to the datetime format builders containing the local-date fields.
27+
* Functions specific to the datetime format builders containing the year and month fields.
2828
*/
29-
public sealed interface WithDate : DateTimeFormatBuilder {
29+
public sealed interface WithYearMonth : DateTimeFormatBuilder {
3030
/**
3131
* A year number.
3232
*
@@ -35,7 +35,7 @@ public sealed interface DateTimeFormatBuilder {
3535
* For years outside this range, it's formatted as a decimal number with a leading sign, so the year 12345
3636
* is formatted as "+12345".
3737
*
38-
* @sample kotlinx.datetime.test.samples.format.LocalDateFormatSamples.year
38+
* @sample kotlinx.datetime.test.samples.format.YearMonthFormatSamples.year
3939
*/
4040
public fun year(padding: Padding = Padding.ZERO)
4141

@@ -54,7 +54,7 @@ public sealed interface DateTimeFormatBuilder {
5454
* and when given a full year number with a leading sign, it parses the full year number,
5555
* so "+1850" becomes 1850.
5656
*
57-
* @sample kotlinx.datetime.test.samples.format.LocalDateFormatSamples.yearTwoDigits
57+
* @sample kotlinx.datetime.test.samples.format.YearMonthFormatSamples.yearTwoDigits
5858
*/
5959
public fun yearTwoDigits(baseYear: Int)
6060

@@ -63,17 +63,29 @@ public sealed interface DateTimeFormatBuilder {
6363
*
6464
* By default, it's padded with zeros to two digits. This can be changed by passing [padding].
6565
*
66-
* @sample kotlinx.datetime.test.samples.format.LocalDateFormatSamples.monthNumber
66+
* @sample kotlinx.datetime.test.samples.format.YearMonthFormatSamples.monthNumber
6767
*/
6868
public fun monthNumber(padding: Padding = Padding.ZERO)
6969

7070
/**
7171
* A month name (for example, "January").
7272
*
73-
* @sample kotlinx.datetime.test.samples.format.LocalDateFormatSamples.monthName
73+
* @sample kotlinx.datetime.test.samples.format.YearMonthFormatSamples.monthName
7474
*/
7575
public fun monthName(names: MonthNames)
7676

77+
/**
78+
* An existing [DateTimeFormat] for the date part.
79+
*
80+
* @sample kotlinx.datetime.test.samples.format.YearMonthFormatSamples.yearMonth
81+
*/
82+
public fun yearMonth(format: DateTimeFormat<YearMonth>)
83+
}
84+
85+
/**
86+
* Functions specific to the datetime format builders containing the local-date fields.
87+
*/
88+
public sealed interface WithDate : WithYearMonth {
7789
/**
7890
* A day-of-month number, from 1 to 31.
7991
*

0 commit comments

Comments
 (0)