- 
                Notifications
    You must be signed in to change notification settings 
- Fork 123
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
              2d57be0
              6847e0e
              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 | 
|---|---|---|
|  | @@ -194,6 +194,25 @@ public expect class LocalDateTime : Comparable<LocalDateTime> { | |
| * @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.Formats.iso | ||
| */ | ||
| public val ISO: DateTimeFormat<LocalDateTime> | ||
|  | ||
| /** | ||
| * ISO 8601 basic format. | ||
| * | ||
| * Examples of datetime in ISO 8601 format: | ||
| * - `20200830T1843` | ||
| * - `+120200830T184300` | ||
| * - `00000830T184300.5` | ||
| * - `-00010830T184300.123456789` | ||
| * | ||
| * When formatting, seconds always included. | ||
| * Fractional parts of the second are included if non-zero. | ||
| * | ||
| * See ISO-8601-1:2019, 5.4.2.1a), the version without the offset, together with | ||
|         
                  dkhalanskyjb marked this conversation as resolved.
              Show resolved
            Hide resolved | ||
| * [LocalDate.Formats.ISO_BASIC] and [LocalTime.Formats.ISO_BASIC]. | ||
| * | ||
| * @sample kotlinx.datetime.test.samples.LocalDateTimeSamples.Formats.basicIso | ||
| 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. 
 | ||
| */ | ||
| public val ISO_BASIC: DateTimeFormat<LocalDateTime> | ||
| } | ||
|  | ||
| /** | ||
|  | ||
| 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 | 
|---|---|---|
|  | @@ -224,6 +224,41 @@ class LocalDateTimeFormatTest { | |
| test(dateTimes, LocalDateTime.Formats.ISO) | ||
| } | ||
|  | ||
| @Test | ||
| fun testBasicIso() { | ||
| 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 the corresponding test for  | ||
| val dateTimes = buildMap<LocalDateTime, Pair<String, Set<String>>> { | ||
| put(LocalDateTime(2008, 7, 5, 0, 0, 0, 0), ("20080705T000000" to setOf("20080705t000000"))) | ||
| 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 test the scenarios of parsing a string which does not include the seconds. | ||
| put(LocalDateTime(2007, 12, 31, 1, 0, 0, 0), ("20071231T010000" to setOf("20071231t010000"))) | ||
| put(LocalDateTime(999, 11, 30, 23, 0, 0, 0), ("09991130T230000" to setOf())) | ||
| put(LocalDateTime(-1, 1, 2, 0, 1, 0, 0), ("-00010102T000100" to setOf())) | ||
| put(LocalDateTime(9999, 10, 31, 12, 30, 0, 0), ("99991031T123000" to setOf())) | ||
| put(LocalDateTime(-9999, 9, 30, 23, 59, 0, 0), ("-99990930T235900" to setOf())) | ||
| put(LocalDateTime(10000, 8, 1, 0, 0, 1, 0), ("+100000801T000001" to setOf())) | ||
| put(LocalDateTime(-10000, 7, 1, 0, 0, 59, 0), ("-100000701T000059" to setOf())) | ||
| put(LocalDateTime(123456, 6, 1, 13, 44, 0, 0), ("+1234560601T134400" to setOf())) | ||
| put(LocalDateTime(-123456, 5, 1, 13, 44, 0, 0), ("-1234560501T134400" to setOf())) | ||
| put(LocalDateTime(123456, 6, 1, 0, 0, 0, 100000000), ("+1234560601T000000.1" to setOf("+1234560601T000000.10", "+1234560601T000000.100"))) | ||
| put(LocalDateTime(-123456, 5, 1, 0, 0, 0, 10000000), ("-1234560501T000000.01" to setOf("-1234560501T000000.010"))) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 1000000), ("20220102T000000.001" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 100000), ("20220102T000000.0001" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 10000), ("20220102T000000.00001" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 1000), ("20220102T000000.000001" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 100), ("20220102T000000.0000001" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 10), ("20220102T000000.00000001" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 1), ("20220102T000000.000000001" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 999999999), ("20220102T000000.999999999" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 99999999), ("20220102T000000.099999999" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 9999999), ("20220102T000000.009999999" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 999999), ("20220102T000000.000999999" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 99999), ("20220102T000000.000099999" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 9999), ("20220102T000000.000009999" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 999), ("20220102T000000.000000999" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 99), ("20220102T000000.000000099" to setOf())) | ||
| put(LocalDateTime(2022, 1, 2, 0, 0, 0, 9), ("20220102T000000.000000009" to setOf())) | ||
| } | ||
| test(dateTimes, LocalDateTime.Formats.ISO_BASIC) | ||
| } | ||
|  | ||
| @Test | ||
| fun testDoc() { | ||
| val dateTime = LocalDateTime(2020, 8, 30, 18, 43, 13, 0) | ||
|  | ||
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.