|
7 | 7 |
|
8 | 8 | package kotlinx.datetime |
9 | 9 |
|
10 | | -import kotlinx.datetime.format.DateTimeComponents |
11 | | -import kotlinx.datetime.format.DayOfWeekNames |
12 | | -import kotlinx.datetime.format.ISO_DATE |
13 | | -import kotlinx.datetime.format.MonthNames |
14 | | -import kotlinx.datetime.format.Padding |
15 | | -import kotlinx.datetime.format.alternativeParsing |
16 | | -import kotlinx.datetime.format.char |
17 | | -import kotlinx.datetime.format.optional |
| 10 | +import kotlinx.datetime.format.* |
18 | 11 | import org.openjdk.jmh.annotations.* |
19 | 12 | import org.openjdk.jmh.infra.Blackhole |
20 | 13 | import java.util.concurrent.* |
@@ -90,7 +83,40 @@ open class CommonFormats { |
90 | 83 |
|
91 | 84 | @Benchmark |
92 | 85 | fun buildRfc1123DateTimeFormat(blackhole: Blackhole) { |
93 | | - val format = DateTimeComponents.Formats.RFC_1123 |
| 86 | + val format = DateTimeComponents.Format { |
| 87 | + alternativeParsing({ |
| 88 | + // the day of week may be missing |
| 89 | + }) { |
| 90 | + dayOfWeek(DayOfWeekNames.ENGLISH_ABBREVIATED) |
| 91 | + chars(", ") |
| 92 | + } |
| 93 | + day(Padding.NONE) |
| 94 | + char(' ') |
| 95 | + monthName(MonthNames.ENGLISH_ABBREVIATED) |
| 96 | + char(' ') |
| 97 | + year() |
| 98 | + char(' ') |
| 99 | + hour() |
| 100 | + char(':') |
| 101 | + minute() |
| 102 | + optional { |
| 103 | + char(':') |
| 104 | + second() |
| 105 | + } |
| 106 | + chars(" ") |
| 107 | + alternativeParsing({ |
| 108 | + chars("UT") |
| 109 | + }, { |
| 110 | + chars("Z") |
| 111 | + }) { |
| 112 | + optional("GMT") { |
| 113 | + offset(UtcOffset.Format { |
| 114 | + offsetHours() |
| 115 | + offsetMinutesOfHour() |
| 116 | + }) |
| 117 | + } |
| 118 | + } |
| 119 | + } |
94 | 120 | blackhole.consume(format) |
95 | 121 | } |
96 | 122 |
|
@@ -121,7 +147,19 @@ open class CommonFormats { |
121 | 147 | alternativeParsing({ |
122 | 148 | offsetHours() |
123 | 149 | }) { |
124 | | - offset(UtcOffset.Formats.ISO) |
| 150 | + offset(UtcOffset.Format { |
| 151 | + alternativeParsing({ chars("z") }) { |
| 152 | + optional("Z") { |
| 153 | + offsetHours() |
| 154 | + char(':') |
| 155 | + offsetMinutesOfHour() |
| 156 | + optional { |
| 157 | + char(':') |
| 158 | + offsetSecondsOfMinute() |
| 159 | + } |
| 160 | + } |
| 161 | + } |
| 162 | + }) |
125 | 163 | } |
126 | 164 | } |
127 | 165 | blackhole.consume(format) |
|
0 commit comments