Skip to content
Merged
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
7 changes: 7 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ allprojects {
options.release.set(8)
}
}
tasks.withType<KotlinCompile> {
compilerOptions {
// enables support for kotlin.time.Instant as kotlinx.datetime.Instant was deprecated; Issue #1350
// Can be removed once kotlin.time.Instant is marked "stable".
optIn.add("kotlin.time.ExperimentalTime")
}
}

// Attempts to configure ktlint for each sub-project that uses the plugin
afterEvaluate {
Expand Down
49 changes: 37 additions & 12 deletions core/api/core.api

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ public interface GlobalParserOptions {
* In notebooks, add `-opt-in=kotlin.uuid.ExperimentalUuidApi` to the compiler arguments.
*/
public var parseExperimentalUuid: Boolean

/**
* Whether to allow parsing to the experimental [kotlin.time.Instant] type.
* By default, this is false and instants are recognized as the deprecated [kotlinx.datetime.Instant] type (#1350).
*
* NOTE: Interacting with an [Instant][kotlin.time.Instant] in your code might require
* `@`[OptIn][OptIn]`(`[ExperimentalTime][kotlin.time.ExperimentalTime]`::class)`.
* In notebooks, add `-opt-in=kotlin.time.ExperimentalTime` to the compiler arguments.
*/
public var parseExperimentalInstant: Boolean
}

/**
Expand Down Expand Up @@ -118,6 +128,11 @@ public interface GlobalParserOptions {
* NOTE: Interacting with a [Uuid][Uuid] in your code might require
* `@`[OptIn][OptIn]`(`[ExperimentalUuidApi][ExperimentalUuidApi]`::class)`.
* In notebooks, add `-opt-in=kotlin.uuid.ExperimentalUuidApi` to the compiler arguments.
* @param parseExperimentalInstant whether to allow parsing to the experimental [kotlin.time.Instant] type.
* By default, this is false and instants are recognized as the deprecated [kotlinx.datetime.Instant] type (#1350).
* NOTE: Interacting with an [Instant][kotlin.time.Instant] in your code might require
* `@`[OptIn][OptIn]`(`[ExperimentalTime][kotlin.time.ExperimentalTime]`::class)`.
* In notebooks, add `-opt-in=kotlin.time.ExperimentalTime` to the compiler arguments.
*/
public class ParserOptions(
public val locale: Locale? = null,
Expand All @@ -128,6 +143,7 @@ public class ParserOptions(
public val skipTypes: Set<KType>? = null,
public val useFastDoubleParser: Boolean? = null,
public val parseExperimentalUuid: Boolean? = null,
public val parseExperimentalInstant: Boolean? = null,
) {

/** For binary compatibility. */
Expand All @@ -150,6 +166,7 @@ public class ParserOptions(
skipTypes = skipTypes,
useFastDoubleParser = useFastDoubleParser,
parseExperimentalUuid = null,
parseExperimentalInstant = null,
)

/** For binary compatibility. */
Expand All @@ -170,6 +187,7 @@ public class ParserOptions(
skipTypes = null,
useFastDoubleParser = null,
parseExperimentalUuid = null,
parseExperimentalInstant = null,
)

/** For binary compatibility. */
Expand All @@ -193,6 +211,7 @@ public class ParserOptions(
skipTypes = skipTypes,
useFastDoubleParser = useFastDoubleParser,
parseExperimentalUuid = null,
parseExperimentalInstant = null,
)

/** For binary compatibility. */
Expand All @@ -214,6 +233,7 @@ public class ParserOptions(
skipTypes = skipTypes,
useFastDoubleParser = useFastDoubleParser,
parseExperimentalUuid = null,
parseExperimentalInstant = null,
)

internal fun getDateTimeFormatter(): DateTimeFormatter? =
Expand All @@ -232,6 +252,7 @@ public class ParserOptions(
skipTypes: Set<KType>? = this.skipTypes,
useFastDoubleParser: Boolean? = this.useFastDoubleParser,
parseExperimentalUuid: Boolean? = this.parseExperimentalUuid,
parseExperimentalInstant: Boolean? = this.parseExperimentalInstant,
): ParserOptions =
ParserOptions(
locale = locale,
Expand All @@ -241,6 +262,7 @@ public class ParserOptions(
skipTypes = skipTypes,
useFastDoubleParser = useFastDoubleParser,
parseExperimentalUuid = parseExperimentalUuid,
parseExperimentalInstant = parseExperimentalInstant,
)

override fun equals(other: Any?): Boolean {
Expand All @@ -256,6 +278,7 @@ public class ParserOptions(
if (nullStrings != other.nullStrings) return false
if (skipTypes != other.skipTypes) return false
if (parseExperimentalUuid != other.parseExperimentalUuid) return false
if (parseExperimentalInstant != other.parseExperimentalInstant) return false

return true
}
Expand All @@ -268,11 +291,12 @@ public class ParserOptions(
result = 31 * result + (nullStrings?.hashCode() ?: 0)
result = 31 * result + (skipTypes?.hashCode() ?: 0)
result = 31 * result + (parseExperimentalUuid?.hashCode() ?: 0)
result = 31 * result + (parseExperimentalInstant?.hashCode() ?: 0)
return result
}

override fun toString(): String =
"ParserOptions(locale=$locale, dateTimeFormatter=$dateTimeFormatter, dateTimePattern=$dateTimePattern, nullStrings=$nullStrings, skipTypes=$skipTypes, useFastDoubleParser=$useFastDoubleParser, parseExperimentalUuid=$parseExperimentalUuid)"
"ParserOptions(locale=$locale, dateTimeFormatter=$dateTimeFormatter, dateTimePattern=$dateTimePattern, nullStrings=$nullStrings, skipTypes=$skipTypes, useFastDoubleParser=$useFastDoubleParser, parseExperimentalUuid=$parseExperimentalUuid, parseExperimentalInstant=$parseExperimentalInstant)"
}

/** Tries to parse a column of strings into a column of a different type.
Expand Down
Loading