|
30 | 30 | import java.time.temporal.TemporalQuery; |
31 | 31 | import java.time.temporal.WeekFields; |
32 | 32 | import java.util.Locale; |
| 33 | +import java.util.Set; |
33 | 34 | import java.util.stream.Stream; |
34 | 35 |
|
35 | 36 | import static java.time.temporal.ChronoField.DAY_OF_MONTH; |
@@ -132,71 +133,15 @@ private static DateFormatter newDateFormatter(String format, DateTimeFormatter p |
132 | 133 | .toFormatter(Locale.ROOT) |
133 | 134 | .withResolverStyle(ResolverStyle.STRICT); |
134 | 135 |
|
135 | | - private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_FORMATTER = new DateTimeFormatterBuilder().append( |
136 | | - STRICT_YEAR_MONTH_DAY_FORMATTER |
137 | | - ) |
138 | | - .optionalStart() |
139 | | - .appendLiteral('T') |
140 | | - .optionalStart() |
141 | | - .appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE) |
142 | | - .optionalStart() |
143 | | - .appendLiteral(':') |
144 | | - .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) |
145 | | - .optionalStart() |
146 | | - .appendLiteral(':') |
147 | | - .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) |
148 | | - .optionalStart() |
149 | | - .appendFraction(NANO_OF_SECOND, 1, 9, true) |
150 | | - .optionalEnd() |
151 | | - .optionalStart() |
152 | | - .appendLiteral(',') |
153 | | - .appendFraction(NANO_OF_SECOND, 1, 9, false) |
154 | | - .optionalEnd() |
155 | | - .optionalEnd() |
156 | | - .optionalEnd() |
157 | | - .optionalStart() |
158 | | - .appendZoneOrOffsetId() |
159 | | - .optionalEnd() |
160 | | - .optionalStart() |
161 | | - .append(TIME_ZONE_FORMATTER_NO_COLON) |
162 | | - .optionalEnd() |
163 | | - .optionalEnd() |
164 | | - .optionalEnd() |
165 | | - .toFormatter(Locale.ROOT) |
166 | | - .withResolverStyle(ResolverStyle.STRICT); |
167 | | - |
168 | 136 | /** |
169 | 137 | * Returns a generic ISO datetime parser where the date is mandatory and the time is optional. |
170 | 138 | */ |
171 | | - private static final DateFormatter STRICT_DATE_OPTIONAL_TIME = newDateFormatter( |
| 139 | + private static final DateFormatter STRICT_DATE_OPTIONAL_TIME = new JavaDateFormatter( |
172 | 140 | "strict_date_optional_time", |
173 | | - STRICT_DATE_OPTIONAL_TIME_PRINTER, |
174 | | - STRICT_DATE_OPTIONAL_TIME_FORMATTER |
| 141 | + new JavaTimeDateTimePrinter(STRICT_DATE_OPTIONAL_TIME_PRINTER), |
| 142 | + new Iso8601DateTimeParser(Set.of(), false).withLocale(Locale.ROOT) |
175 | 143 | ); |
176 | 144 |
|
177 | | - private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_FORMATTER_WITH_NANOS = new DateTimeFormatterBuilder().append( |
178 | | - STRICT_YEAR_MONTH_DAY_FORMATTER |
179 | | - ) |
180 | | - .optionalStart() |
181 | | - .appendLiteral('T') |
182 | | - .append(STRICT_HOUR_MINUTE_SECOND_FORMATTER) |
183 | | - .optionalStart() |
184 | | - .appendFraction(NANO_OF_SECOND, 1, 9, true) |
185 | | - .optionalEnd() |
186 | | - .optionalStart() |
187 | | - .appendLiteral(',') |
188 | | - .appendFraction(NANO_OF_SECOND, 1, 9, false) |
189 | | - .optionalEnd() |
190 | | - .optionalStart() |
191 | | - .appendZoneOrOffsetId() |
192 | | - .optionalEnd() |
193 | | - .optionalStart() |
194 | | - .append(TIME_ZONE_FORMATTER_NO_COLON) |
195 | | - .optionalEnd() |
196 | | - .optionalEnd() |
197 | | - .toFormatter(Locale.ROOT) |
198 | | - .withResolverStyle(ResolverStyle.STRICT); |
199 | | - |
200 | 145 | private static final DateTimeFormatter STRICT_DATE_OPTIONAL_TIME_PRINTER_NANOS = new DateTimeFormatterBuilder().append( |
201 | 146 | STRICT_YEAR_MONTH_DAY_PRINTER |
202 | 147 | ) |
@@ -224,50 +169,21 @@ private static DateFormatter newDateFormatter(String format, DateTimeFormatter p |
224 | 169 | /** |
225 | 170 | * Returns a generic ISO datetime parser where the date is mandatory and the time is optional with nanosecond resolution. |
226 | 171 | */ |
227 | | - private static final DateFormatter STRICT_DATE_OPTIONAL_TIME_NANOS = newDateFormatter( |
| 172 | + private static final DateFormatter STRICT_DATE_OPTIONAL_TIME_NANOS = new JavaDateFormatter( |
228 | 173 | "strict_date_optional_time_nanos", |
229 | | - STRICT_DATE_OPTIONAL_TIME_PRINTER_NANOS, |
230 | | - STRICT_DATE_OPTIONAL_TIME_FORMATTER_WITH_NANOS |
| 174 | + new JavaTimeDateTimePrinter(STRICT_DATE_OPTIONAL_TIME_PRINTER_NANOS), |
| 175 | + new Iso8601DateTimeParser(Set.of(HOUR_OF_DAY, MINUTE_OF_HOUR, SECOND_OF_MINUTE), true).withLocale(Locale.ROOT) |
231 | 176 | ); |
232 | 177 |
|
233 | 178 | /** |
234 | 179 | * Returns a ISO 8601 compatible date time formatter and parser. |
235 | 180 | * This is not fully compatible to the existing spec, which would require far more edge cases, but merely compatible with the |
236 | 181 | * existing legacy joda time ISO date formatter |
237 | 182 | */ |
238 | | - private static final DateFormatter ISO_8601 = newDateFormatter( |
| 183 | + private static final DateFormatter ISO_8601 = new JavaDateFormatter( |
239 | 184 | "iso8601", |
240 | | - STRICT_DATE_OPTIONAL_TIME_PRINTER, |
241 | | - new DateTimeFormatterBuilder().append(STRICT_YEAR_MONTH_DAY_FORMATTER) |
242 | | - .optionalStart() |
243 | | - .appendLiteral('T') |
244 | | - .optionalStart() |
245 | | - .appendValue(HOUR_OF_DAY, 2, 2, SignStyle.NOT_NEGATIVE) |
246 | | - .optionalStart() |
247 | | - .appendLiteral(':') |
248 | | - .appendValue(MINUTE_OF_HOUR, 2, 2, SignStyle.NOT_NEGATIVE) |
249 | | - .optionalStart() |
250 | | - .appendLiteral(':') |
251 | | - .appendValue(SECOND_OF_MINUTE, 2, 2, SignStyle.NOT_NEGATIVE) |
252 | | - .optionalStart() |
253 | | - .appendFraction(NANO_OF_SECOND, 1, 9, true) |
254 | | - .optionalEnd() |
255 | | - .optionalStart() |
256 | | - .appendLiteral(",") |
257 | | - .appendFraction(NANO_OF_SECOND, 1, 9, false) |
258 | | - .optionalEnd() |
259 | | - .optionalEnd() |
260 | | - .optionalEnd() |
261 | | - .optionalEnd() |
262 | | - .optionalStart() |
263 | | - .appendZoneOrOffsetId() |
264 | | - .optionalEnd() |
265 | | - .optionalStart() |
266 | | - .append(TIME_ZONE_FORMATTER_NO_COLON) |
267 | | - .optionalEnd() |
268 | | - .optionalEnd() |
269 | | - .toFormatter(Locale.ROOT) |
270 | | - .withResolverStyle(ResolverStyle.STRICT) |
| 185 | + new JavaTimeDateTimePrinter(STRICT_DATE_OPTIONAL_TIME_PRINTER), |
| 186 | + new Iso8601DateTimeParser(Set.of(), false).withLocale(Locale.ROOT) |
271 | 187 | ); |
272 | 188 |
|
273 | 189 | ///////////////////////////////////////// |
|
0 commit comments