Skip to content

WIP: Don't typealias Month #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions core/common/src/Month.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package kotlinx.datetime

import kotlin.native.concurrent.*

public expect enum class Month {
public enum class Month {
JANUARY,
FEBRUARY,
MARCH,
Expand All @@ -21,11 +21,9 @@ public expect enum class Month {
NOVEMBER,
DECEMBER;

// val value: Int // member missing in java.time.Month has to be an extension
public val number: Int get() = ordinal + 1
}

public val Month.number: Int get() = ordinal + 1

@SharedImmutable
private val allMonths = Month.values().asList()

Expand Down
15 changes: 0 additions & 15 deletions core/js/src/Month.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,4 @@ package kotlinx.datetime

import kotlinx.datetime.internal.JSJoda.Month as jsMonth

public actual enum class Month {
JANUARY,
FEBRUARY,
MARCH,
APRIL,
MAY,
JUNE,
JULY,
AUGUST,
SEPTEMBER,
OCTOBER,
NOVEMBER,
DECEMBER;
}

internal fun jsMonth.toMonth(): Month = Month(this.value().toInt())
11 changes: 11 additions & 0 deletions core/jvm/src/Converters.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@

package kotlinx.datetime

/**
* Converts this [kotlinx.datetime.Month][Month] value to a [java.time.Month][java.time.Month] value.
*/
public fun Month.toJavaMonth(): java.time.Month = java.time.Month.of(number)

/**
* Converts this [java.time.Month][java.time.Month] value to a [kotlinx.datetime.Month][Month] value.
*/
public fun java.time.Month.toKotlinMonth(): Month = Month(value)


/**
* Converts this [kotlinx.datetime.Instant][Instant] value to a [java.time.Instant][java.time.Instant] value.
*/
Expand Down
2 changes: 1 addition & 1 deletion core/jvm/src/LocalDate.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public actual class LocalDate internal constructor(internal val value: jtLocalDa

public actual val year: Int get() = value.year
public actual val monthNumber: Int get() = value.monthValue
public actual val month: Month get() = value.month
public actual val month: Month get() = value.month.toKotlinMonth()
public actual val dayOfMonth: Int get() = value.dayOfMonth
public actual val dayOfWeek: DayOfWeek get() = value.dayOfWeek
public actual val dayOfYear: Int get() = value.dayOfYear
Expand Down
3 changes: 1 addition & 2 deletions core/jvm/src/LocalDateTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import java.time.DateTimeException
import java.time.format.DateTimeParseException
import java.time.LocalDateTime as jtLocalDateTime

public actual typealias Month = java.time.Month
public actual typealias DayOfWeek = java.time.DayOfWeek

@Serializable(with = LocalDateTimeIso8601Serializer::class)
Expand All @@ -29,7 +28,7 @@ public actual class LocalDateTime internal constructor(internal val value: jtLoc

public actual val year: Int get() = value.year
public actual val monthNumber: Int get() = value.monthValue
public actual val month: Month get() = value.month
public actual val month: Month get() = value.month.toKotlinMonth()
public actual val dayOfMonth: Int get() = value.dayOfMonth
public actual val dayOfWeek: DayOfWeek get() = value.dayOfWeek
public actual val dayOfYear: Int get() = value.dayOfYear
Expand Down
4 changes: 0 additions & 4 deletions core/native/src/Month.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@

package kotlinx.datetime

public actual enum class Month {
JANUARY, FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER, OCTOBER, NOVEMBER, DECEMBER;
}

// From threetenbp
internal fun Month.firstDayOfYear(leapYear: Boolean): Int {
val leap = if (leapYear) 1 else 0
Expand Down