Skip to content

Commit

Permalink
Implement YearMonth
Browse files Browse the repository at this point in the history
Fixes #168
Fixes #184
  • Loading branch information
dkhalanskyjb committed Nov 13, 2024
1 parent fbb2187 commit d630038
Show file tree
Hide file tree
Showing 15 changed files with 1,487 additions and 365 deletions.
397 changes: 397 additions & 0 deletions core/common/src/YearMonth.kt

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/common/src/format/DateTimeFormat.kt
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,6 @@ private val allFormatConstants: List<Pair<String, CachedFormatStructure<*>>> by
"${DateTimeFormatBuilder.WithUtcOffset::offset.name}(UtcOffset.Formats.ISO)" to unwrap(UtcOffset.Formats.ISO),
"${DateTimeFormatBuilder.WithUtcOffset::offset.name}(UtcOffset.Formats.ISO_BASIC)" to unwrap(UtcOffset.Formats.ISO_BASIC),
"${DateTimeFormatBuilder.WithUtcOffset::offset.name}(UtcOffset.Formats.FOUR_DIGITS)" to unwrap(UtcOffset.Formats.FOUR_DIGITS),
"${DateTimeFormatBuilder.WithYearMonth::yearMonth.name}(YearMonth.Formats.ISO)" to unwrap(YearMonth.Formats.ISO),
)
}
24 changes: 18 additions & 6 deletions core/common/src/format/DateTimeFormatBuilder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public sealed interface DateTimeFormatBuilder {
public fun chars(value: String)

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

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

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

/**
* A month name (for example, "January").
*
* @sample kotlinx.datetime.test.samples.format.LocalDateFormatSamples.monthName
* @sample kotlinx.datetime.test.samples.format.YearMonthFormatSamples.monthName
*/
public fun monthName(names: MonthNames)

/**
* An existing [DateTimeFormat] for the date part.
*
* @sample kotlinx.datetime.test.samples.format.YearMonthFormatSamples.yearMonth
*/
public fun yearMonth(format: DateTimeFormat<YearMonth>)
}

/**
* Functions specific to the datetime format builders containing the local-date fields.
*/
public sealed interface WithDate : WithYearMonth {
/**
* A day-of-month number, from 1 to 31.
*
Expand Down
Loading

0 comments on commit d630038

Please sign in to comment.