Clarify specification of Duration.parseIsoString

KT-52778


Co-authored-by: Vsevolod Tolstopyatov <qwwdfsad@gmail.com>

Merge-request: KT-MR-6556
Merged-by: Vsevolod Tolstopyatov <vsevolod.tolstopyatov@jetbrains.com>
This commit is contained in:
Vsevolod Tolstopyatov
2022-06-28 07:43:33 +00:00
committed by Space
parent d47193d36f
commit 0c8b31b9ed
2 changed files with 17 additions and 5 deletions
+16 -5
View File
@@ -401,7 +401,16 @@ public value class Duration internal constructor(private val rawValue: Long) : C
}
/**
* Parses a string that represents a duration in ISO-8601 format and returns the parsed [Duration] value.
* Parses a string that represents a duration in a restricted ISO-8601 composite representation
* and returns the parsed [Duration] value.
* Composite representation is a relaxed version of ISO-8601 duration format that supports
* negative durations and negative values of individual components.
*
* The following restrictions are imposed:
*
* - The only allowed non-time designator is days (`D`). `Y` (years), `W` (weeks), and `M` (months) are not supported.
* - Day is considered to be exactly 24 hours (24-hour clock time scale).
* - Alternative week-based representation `["P"][number]["W"]` is not supported.
*
* @throws IllegalArgumentException if the string doesn't represent a duration in ISO-8601 format.
* @sample samples.time.Durations.parseIsoString
@@ -418,7 +427,7 @@ public value class Duration internal constructor(private val rawValue: Long) : C
*
* The following formats are accepted:
*
* - ISO-8601 Duration format, e.g. `P1DT2H3M4.058S`, see [toIsoString] and [parseIsoString].
* - Restricted ISO-8601 duration composite representation, e.g. `P1DT2H3M4.058S`, see [toIsoString] and [parseIsoString].
* - The format of string returned by the default [Duration.toString] and `toString` in a specific unit,
* e.g. `10s`, `1h 30m` or `-(1h 30m)`.
* @sample samples.time.Durations.parse
@@ -430,8 +439,10 @@ public value class Duration internal constructor(private val rawValue: Long) : C
}
/**
* Parses a string that represents a duration in ISO-8601 format and returns the parsed [Duration] value,
* or `null` if the string doesn't represent a duration in ISO-8601 format.
* Parses a string that represents a duration in restricted ISO-8601 composite representation
* and returns the parsed [Duration] value or `null` if the string doesn't represent a duration in the format
* acceptable by [parseIsoString].
*
* @sample samples.time.Durations.parseIsoString
*/
public fun parseIsoStringOrNull(value: String): Duration? = try {
@@ -1460,4 +1471,4 @@ private fun durationOfMillisNormalized(millis: Long) =
internal expect val durationAssertionsEnabled: Boolean
internal expect fun formatToExactDecimals(value: Double, decimals: Int): String
internal expect fun formatUpToDecimals(value: Double, decimals: Int): String
internal expect fun formatUpToDecimals(value: Double, decimals: Int): String