@@ -184,127 +184,40 @@ fn decode_datetime_from_text(value: &str) -> Option<PrimitiveDateTime> {
184184}
185185
186186mod formats {
187- use time:: format_description:: { modifier, Component :: * , FormatItem , FormatItem :: * } ;
188-
189- const YEAR : FormatItem < ' _ > = Component ( Year ( {
190- let mut value = modifier:: Year :: default ( ) ;
191- value. padding = modifier:: Padding :: Zero ;
192- value. repr = modifier:: YearRepr :: Full ;
193- value. iso_week_based = false ;
194- value. sign_is_mandatory = false ;
195- value
196- } ) ) ;
197-
198- const MONTH : FormatItem < ' _ > = Component ( Month ( {
199- let mut value = modifier:: Month :: default ( ) ;
200- value. padding = modifier:: Padding :: Zero ;
201- value. repr = modifier:: MonthRepr :: Numerical ;
202- value. case_sensitive = true ;
203- value
204- } ) ) ;
205-
206- const DAY : FormatItem < ' _ > = Component ( Day ( {
207- let mut value = modifier:: Day :: default ( ) ;
208- value. padding = modifier:: Padding :: Zero ;
209- value
210- } ) ) ;
211-
212- const HOUR : FormatItem < ' _ > = Component ( Hour ( {
213- let mut value = modifier:: Hour :: default ( ) ;
214- value. padding = modifier:: Padding :: Zero ;
215- value. is_12_hour_clock = false ;
216- value
217- } ) ) ;
218-
219- const MINUTE : FormatItem < ' _ > = Component ( Minute ( {
220- let mut value = modifier:: Minute :: default ( ) ;
221- value. padding = modifier:: Padding :: Zero ;
222- value
223- } ) ) ;
224-
225- const SECOND : FormatItem < ' _ > = Component ( Second ( {
226- let mut value = modifier:: Second :: default ( ) ;
227- value. padding = modifier:: Padding :: Zero ;
228- value
229- } ) ) ;
230-
231- const SUBSECOND : FormatItem < ' _ > = Component ( Subsecond ( {
232- let mut value = modifier:: Subsecond :: default ( ) ;
233- value. digits = modifier:: SubsecondDigits :: OneOrMore ;
234- value
235- } ) ) ;
236-
237- const OFFSET_HOUR : FormatItem < ' _ > = Component ( OffsetHour ( {
238- let mut value = modifier:: OffsetHour :: default ( ) ;
239- value. sign_is_mandatory = true ;
240- value. padding = modifier:: Padding :: Zero ;
241- value
242- } ) ) ;
243-
244- const OFFSET_MINUTE : FormatItem < ' _ > = Component ( OffsetMinute ( {
245- let mut value = modifier:: OffsetMinute :: default ( ) ;
246- value. padding = modifier:: Padding :: Zero ;
247- value
248- } ) ) ;
249-
250- pub ( super ) const OFFSET_DATE_TIME : & [ FormatItem < ' _ > ] = {
251- & [
252- YEAR ,
253- Literal ( b"-" ) ,
254- MONTH ,
255- Literal ( b"-" ) ,
256- DAY ,
257- Optional ( & Literal ( b" " ) ) ,
258- Optional ( & Literal ( b"T" ) ) ,
259- HOUR ,
260- Literal ( b":" ) ,
261- MINUTE ,
262- Optional ( & Literal ( b":" ) ) ,
263- Optional ( & SECOND ) ,
264- Optional ( & Literal ( b"." ) ) ,
265- Optional ( & SUBSECOND ) ,
266- Optional ( & Literal ( b" " ) ) ,
267- Optional ( & OFFSET_HOUR ) ,
268- Optional ( & Literal ( b":" ) ) ,
269- Optional ( & OFFSET_MINUTE ) ,
270- ]
271- } ;
187+ use time:: format_description:: { FormatItem , FormatItem :: Compound , FormatItem :: Optional } ;
188+ use time:: macros:: format_description as fd;
189+
190+ // Let time's macro select the component representation for the installed version.
191+ pub ( super ) const OFFSET_DATE_TIME : & [ FormatItem < ' _ > ] = & [
192+ Compound ( fd ! ( "[year]-[month]-[day]" ) ) ,
193+ Optional ( & Compound ( fd ! ( " " ) ) ) ,
194+ Optional ( & Compound ( fd ! ( "T" ) ) ) ,
195+ Compound ( fd ! ( "[hour]:[minute]" ) ) ,
196+ Optional ( & Compound ( fd ! ( ":" ) ) ) ,
197+ Optional ( & Compound ( fd ! ( "[second]" ) ) ) ,
198+ Optional ( & Compound ( fd ! ( "." ) ) ) ,
199+ Optional ( & Compound ( fd ! ( "[subsecond]" ) ) ) ,
200+ Optional ( & Compound ( fd ! ( " " ) ) ) ,
201+ Optional ( & Compound ( fd ! ( "[offset_hour sign:mandatory]" ) ) ) ,
202+ Optional ( & Compound ( fd ! ( ":" ) ) ) ,
203+ Optional ( & Compound ( fd ! ( "[offset_minute]" ) ) ) ,
204+ ] ;
272205
273- pub ( super ) const PRIMITIVE_DATE_TIME_SPACE_SEPARATED : & [ FormatItem < ' _ > ] = {
274- & [
275- YEAR ,
276- Literal ( b"-" ) ,
277- MONTH ,
278- Literal ( b"-" ) ,
279- DAY ,
280- Literal ( b" " ) ,
281- HOUR ,
282- Literal ( b":" ) ,
283- MINUTE ,
284- Optional ( & Literal ( b":" ) ) ,
285- Optional ( & SECOND ) ,
286- Optional ( & Literal ( b"." ) ) ,
287- Optional ( & SUBSECOND ) ,
288- Optional ( & Literal ( b"Z" ) ) ,
289- ]
290- } ;
206+ pub ( super ) const PRIMITIVE_DATE_TIME_SPACE_SEPARATED : & [ FormatItem < ' _ > ] = & [
207+ Compound ( fd ! ( "[year]-[month]-[day] [hour]:[minute]" ) ) ,
208+ Optional ( & Compound ( fd ! ( ":" ) ) ) ,
209+ Optional ( & Compound ( fd ! ( "[second]" ) ) ) ,
210+ Optional ( & Compound ( fd ! ( "." ) ) ) ,
211+ Optional ( & Compound ( fd ! ( "[subsecond]" ) ) ) ,
212+ Optional ( & Compound ( fd ! ( "Z" ) ) ) ,
213+ ] ;
291214
292- pub ( super ) const PRIMITIVE_DATE_TIME_T_SEPARATED : & [ FormatItem < ' _ > ] = {
293- & [
294- YEAR ,
295- Literal ( b"-" ) ,
296- MONTH ,
297- Literal ( b"-" ) ,
298- DAY ,
299- Literal ( b"T" ) ,
300- HOUR ,
301- Literal ( b":" ) ,
302- MINUTE ,
303- Optional ( & Literal ( b":" ) ) ,
304- Optional ( & SECOND ) ,
305- Optional ( & Literal ( b"." ) ) ,
306- Optional ( & SUBSECOND ) ,
307- Optional ( & Literal ( b"Z" ) ) ,
308- ]
309- } ;
215+ pub ( super ) const PRIMITIVE_DATE_TIME_T_SEPARATED : & [ FormatItem < ' _ > ] = & [
216+ Compound ( fd ! ( "[year]-[month]-[day]T[hour]:[minute]" ) ) ,
217+ Optional ( & Compound ( fd ! ( ":" ) ) ) ,
218+ Optional ( & Compound ( fd ! ( "[second]" ) ) ) ,
219+ Optional ( & Compound ( fd ! ( "." ) ) ) ,
220+ Optional ( & Compound ( fd ! ( "[subsecond]" ) ) ) ,
221+ Optional ( & Compound ( fd ! ( "Z" ) ) ) ,
222+ ] ;
310223}
0 commit comments