-
Notifications
You must be signed in to change notification settings - Fork 110
Added LocalTime.Formats.ISO_BASIC (ISO 8601 basic format) #518
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
base: master
Are you sure you want to change the base?
Changes from all commits
c8e2757
cca454f
8d17ebb
8cddb49
76a093a
bae2c6e
8075aa0
8177fe6
a403817
deefb8d
e2e0455
9b19750
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -197,6 +197,19 @@ public expect class LocalTime : Comparable<LocalTime> { | |
* [kotlinx.datetime.format.DateTimeFormat] for [LocalTime] values. | ||
*/ | ||
public object Formats { | ||
/** | ||
* ISO 8601 basic format. | ||
* | ||
* Examples: `T1234`, `T123456`, `T123456.789`, `T123456.1234`. | ||
* | ||
* When formatting, seconds are always included, even if they are zero. | ||
* Fractional parts of the second are included if non-zero. | ||
* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
* @see LocalDateTime.Formats.ISO_BASIC | ||
* @sample kotlinx.datetime.test.samples.LocalTimeSamples.Formats.isoBasic | ||
*/ | ||
public val ISO_BASIC: DateTimeFormat<LocalTime> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please also add tests. Examples: |
||
|
||
/** | ||
* ISO 8601 extended format. | ||
* | ||
|
@@ -215,6 +228,7 @@ public expect class LocalTime : Comparable<LocalTime> { | |
* We *forbid* using the time designator `T` to allow for a predictable composition of formats: | ||
* see the note at the end of rule 5.3.5. | ||
* | ||
* @see LocalDateTime.Formats.ISO | ||
* @sample kotlinx.datetime.test.samples.LocalTimeSamples.Formats.iso | ||
*/ | ||
public val ISO: DateTimeFormat<LocalTime> | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -279,6 +279,25 @@ internal class LocalTimeFormat(override val actualFormat: CachedFormatStructure< | |||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
// these are constants so that the formats are not recreated every time they are used | ||||||||||||||||||||||||||
internal val ISO_TIME_BASIC by lazy { | ||||||||||||||||||||||||||
LocalTimeFormat.build { | ||||||||||||||||||||||||||
alternativeParsing({ char('t') }) { char('T') } | ||||||||||||||||||||||||||
hour() | ||||||||||||||||||||||||||
minute() | ||||||||||||||||||||||||||
alternativeParsing({ | ||||||||||||||||||||||||||
// intentionally empty | ||||||||||||||||||||||||||
}) { | ||||||||||||||||||||||||||
optional { | ||||||||||||||||||||||||||
second() | ||||||||||||||||||||||||||
optional { | ||||||||||||||||||||||||||
char('.') | ||||||||||||||||||||||||||
secondFraction(1, 9) | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
Comment on lines
+290
to
+296
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now that I look at it, it's inconsistent to optionally omit seconds here on formatting.
Suggested change
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
internal val ISO_TIME by lazy { | ||||||||||||||||||||||||||
LocalTimeFormat.build { | ||||||||||||||||||||||||||
hour() | ||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In particular, this is no longer true if we sometimes omit seconds.