1use core::num::NonZero;
4
5macro_rules! if_pub {
7 (pub $(#[$attr:meta])*; $($x:tt)*) => {
8 $(#[$attr])*
9 $($x)*
16 };
17 ($($_:tt)*) => {};
18}
19
20macro_rules! impl_const_default {
24 ($($(#[$doc:meta])* $(@$pub:ident)? $type:ty => $default:expr;)*) => {$(
25 impl $type {
26 if_pub! {
27 $($pub)?
28 $(#[$doc])*;
29 #[inline]
30 pub const fn default() -> Self {
31 $default
32 }
33 }
34 }
35
36 $(#[$doc])*
37 impl Default for $type {
38 #[inline]
39 fn default() -> Self {
40 $default
41 }
42 }
43 )*};
44}
45
46impl_const_default! {
48 @pub Day => Self { padding: Padding::Zero };
50 MonthRepr => Self::Numerical;
53 @pub Month => Self {
57 padding: Padding::Zero,
58 repr: MonthRepr::Numerical,
59 case_sensitive: true,
60 };
61 @pub Ordinal => Self { padding: Padding::Zero };
63 WeekdayRepr => Self::Long;
65 @pub Weekday => Self {
69 repr: WeekdayRepr::Long,
70 one_indexed: true,
71 case_sensitive: true,
72 };
73 WeekNumberRepr => Self::Iso;
75 @pub WeekNumber => Self {
78 padding: Padding::Zero,
79 repr: WeekNumberRepr::Iso,
80 };
81 YearRepr => Self::Full;
83 YearRange => Self::Extended;
85 @pub Year => Self {
89 padding: Padding::Zero,
90 repr: YearRepr::Full,
91 range: YearRange::Extended,
92 iso_week_based: false,
93 sign_is_mandatory: false,
94 };
95 @pub Hour => Self {
98 padding: Padding::Zero,
99 is_12_hour_clock: false,
100 };
101 @pub Minute => Self { padding: Padding::Zero };
103 @pub Period => Self {
106 is_uppercase: true,
107 case_sensitive: true,
108 };
109 @pub Second => Self { padding: Padding::Zero };
111 SubsecondDigits => Self::OneOrMore;
114 @pub Subsecond => Self { digits: SubsecondDigits::OneOrMore };
117 @pub OffsetHour => Self {
120 sign_is_mandatory: false,
121 padding: Padding::Zero,
122 };
123 @pub OffsetMinute => Self { padding: Padding::Zero };
125 @pub OffsetSecond => Self { padding: Padding::Zero };
127 Padding => Self::Zero;
129 UnixTimestampPrecision => Self::Second;
132 @pub UnixTimestamp => Self {
135 precision: UnixTimestampPrecision::Second,
136 sign_is_mandatory: false,
137 };
138 TrailingInput => Self::Prohibit;
141 @pub End => Self { trailing_input: TrailingInput::Prohibit };
144}
145
146#[non_exhaustive]
148#[derive(Debug, Clone, Copy, PartialEq, Eq)]
149pub struct Day {
150 pub padding: Padding,
152}
153
154impl Day {
155 #[inline]
157 #[must_use = "this returns the result of the operation, without modifying the original"]
158 pub const fn with_padding(self, padding: Padding) -> Self {
159 Self { padding }
160 }
161}
162
163#[non_exhaustive]
165#[derive(Debug, Clone, Copy, PartialEq, Eq)]
166pub enum MonthRepr {
167 Numerical,
169 Long,
171 Short,
173}
174
175#[non_exhaustive]
177#[derive(Debug, Clone, Copy, PartialEq, Eq)]
178pub struct Month {
179 pub padding: Padding,
181 pub repr: MonthRepr,
183 pub case_sensitive: bool,
185}
186
187impl Month {
188 #[inline]
190 #[must_use = "this returns the result of the operation, without modifying the original"]
191 pub const fn with_padding(self, padding: Padding) -> Self {
192 Self { padding, ..self }
193 }
194
195 #[inline]
197 #[must_use = "this returns the result of the operation, without modifying the original"]
198 pub const fn with_repr(self, repr: MonthRepr) -> Self {
199 Self { repr, ..self }
200 }
201
202 #[inline]
204 #[must_use = "this returns the result of the operation, without modifying the original"]
205 pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
206 Self {
207 case_sensitive,
208 ..self
209 }
210 }
211}
212
213#[non_exhaustive]
215#[derive(Debug, Clone, Copy, PartialEq, Eq)]
216pub struct Ordinal {
217 pub padding: Padding,
219}
220
221impl Ordinal {
222 #[inline]
224 #[must_use = "this returns the result of the operation, without modifying the original"]
225 pub const fn with_padding(self, padding: Padding) -> Self {
226 Self { padding }
227 }
228}
229
230#[non_exhaustive]
232#[derive(Debug, Clone, Copy, PartialEq, Eq)]
233pub enum WeekdayRepr {
234 Short,
236 Long,
238 Sunday,
242 Monday,
246}
247
248#[non_exhaustive]
250#[derive(Debug, Clone, Copy, PartialEq, Eq)]
251pub struct Weekday {
252 pub repr: WeekdayRepr,
254 pub one_indexed: bool,
256 pub case_sensitive: bool,
258}
259
260impl Weekday {
261 #[inline]
263 #[must_use = "this returns the result of the operation, without modifying the original"]
264 pub const fn with_repr(self, repr: WeekdayRepr) -> Self {
265 Self { repr, ..self }
266 }
267
268 #[inline]
270 #[must_use = "this returns the result of the operation, without modifying the original"]
271 pub const fn with_one_indexed(self, one_indexed: bool) -> Self {
272 Self {
273 one_indexed,
274 ..self
275 }
276 }
277
278 #[inline]
280 #[must_use = "this returns the result of the operation, without modifying the original"]
281 pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
282 Self {
283 case_sensitive,
284 ..self
285 }
286 }
287}
288
289#[non_exhaustive]
291#[derive(Debug, Clone, Copy, PartialEq, Eq)]
292pub enum WeekNumberRepr {
293 Iso,
295 Sunday,
297 Monday,
299}
300
301#[non_exhaustive]
303#[derive(Debug, Clone, Copy, PartialEq, Eq)]
304pub struct WeekNumber {
305 pub padding: Padding,
307 pub repr: WeekNumberRepr,
309}
310
311impl WeekNumber {
312 #[inline]
314 #[must_use = "this returns the result of the operation, without modifying the original"]
315 pub const fn with_padding(self, padding: Padding) -> Self {
316 Self { padding, ..self }
317 }
318
319 #[inline]
321 #[must_use = "this returns the result of the operation, without modifying the original"]
322 pub const fn with_repr(self, repr: WeekNumberRepr) -> Self {
323 Self { repr, ..self }
324 }
325}
326
327#[non_exhaustive]
329#[derive(Debug, Clone, Copy, PartialEq, Eq)]
330pub enum YearRepr {
331 Full,
333 Century,
335 LastTwo,
337}
338
339#[non_exhaustive]
343#[derive(Debug, Clone, Copy, PartialEq, Eq)]
344pub enum YearRange {
345 Standard,
347 Extended,
352}
353
354#[non_exhaustive]
356#[derive(Debug, Clone, Copy, PartialEq, Eq)]
357pub struct Year {
358 pub padding: Padding,
360 pub repr: YearRepr,
362 pub range: YearRange,
364 pub iso_week_based: bool,
366 pub sign_is_mandatory: bool,
368}
369
370impl Year {
371 #[inline]
373 #[must_use = "this returns the result of the operation, without modifying the original"]
374 pub const fn with_padding(self, padding: Padding) -> Self {
375 Self { padding, ..self }
376 }
377
378 #[inline]
380 #[must_use = "this returns the result of the operation, without modifying the original"]
381 pub const fn with_repr(self, repr: YearRepr) -> Self {
382 Self { repr, ..self }
383 }
384
385 #[inline]
387 #[must_use = "this returns the result of the operation, without modifying the original"]
388 pub const fn with_range(self, range: YearRange) -> Self {
389 Self { range, ..self }
390 }
391
392 #[inline]
394 #[must_use = "this returns the result of the operation, without modifying the original"]
395 pub const fn with_iso_week_based(self, iso_week_based: bool) -> Self {
396 Self {
397 iso_week_based,
398 ..self
399 }
400 }
401
402 #[inline]
404 #[must_use = "this returns the result of the operation, without modifying the original"]
405 pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
406 Self {
407 sign_is_mandatory,
408 ..self
409 }
410 }
411}
412
413#[non_exhaustive]
415#[derive(Debug, Clone, Copy, PartialEq, Eq)]
416pub struct Hour {
417 pub padding: Padding,
419 pub is_12_hour_clock: bool,
421}
422
423impl Hour {
424 #[inline]
426 #[must_use = "this returns the result of the operation, without modifying the original"]
427 pub const fn with_padding(self, padding: Padding) -> Self {
428 Self { padding, ..self }
429 }
430
431 #[inline]
433 #[must_use = "this returns the result of the operation, without modifying the original"]
434 pub const fn with_is_12_hour_clock(self, is_12_hour_clock: bool) -> Self {
435 Self {
436 is_12_hour_clock,
437 ..self
438 }
439 }
440}
441
442#[non_exhaustive]
444#[derive(Debug, Clone, Copy, PartialEq, Eq)]
445pub struct Minute {
446 pub padding: Padding,
448}
449
450impl Minute {
451 #[inline]
453 #[must_use = "this returns the result of the operation, without modifying the original"]
454 pub const fn with_padding(self, padding: Padding) -> Self {
455 Self { padding }
456 }
457}
458
459#[non_exhaustive]
461#[derive(Debug, Clone, Copy, PartialEq, Eq)]
462pub struct Period {
463 pub is_uppercase: bool,
465 pub case_sensitive: bool,
469}
470
471impl Period {
472 #[inline]
474 #[must_use = "this returns the result of the operation, without modifying the original"]
475 pub const fn with_is_uppercase(self, is_uppercase: bool) -> Self {
476 Self {
477 is_uppercase,
478 ..self
479 }
480 }
481
482 #[inline]
484 #[must_use = "this returns the result of the operation, without modifying the original"]
485 pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
486 Self {
487 case_sensitive,
488 ..self
489 }
490 }
491}
492
493#[non_exhaustive]
495#[derive(Debug, Clone, Copy, PartialEq, Eq)]
496pub struct Second {
497 pub padding: Padding,
499}
500
501impl Second {
502 #[inline]
504 #[must_use = "this returns the result of the operation, without modifying the original"]
505 pub const fn with_padding(self, padding: Padding) -> Self {
506 Self { padding }
507 }
508}
509
510#[non_exhaustive]
512#[derive(Debug, Clone, Copy, PartialEq, Eq)]
513pub enum SubsecondDigits {
514 One,
516 Two,
518 Three,
520 Four,
522 Five,
524 Six,
526 Seven,
528 Eight,
530 Nine,
532 OneOrMore,
535}
536
537#[non_exhaustive]
539#[derive(Debug, Clone, Copy, PartialEq, Eq)]
540pub struct Subsecond {
541 pub digits: SubsecondDigits,
543}
544
545impl Subsecond {
546 #[inline]
548 #[must_use = "this returns the result of the operation, without modifying the original"]
549 pub const fn with_digits(self, digits: SubsecondDigits) -> Self {
550 Self { digits }
551 }
552}
553
554#[non_exhaustive]
556#[derive(Debug, Clone, Copy, PartialEq, Eq)]
557pub struct OffsetHour {
558 pub sign_is_mandatory: bool,
560 pub padding: Padding,
562}
563
564impl OffsetHour {
565 #[inline]
567 #[must_use = "this returns the result of the operation, without modifying the original"]
568 pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
569 Self {
570 sign_is_mandatory,
571 ..self
572 }
573 }
574
575 #[inline]
577 #[must_use = "this returns the result of the operation, without modifying the original"]
578 pub const fn with_padding(self, padding: Padding) -> Self {
579 Self { padding, ..self }
580 }
581}
582
583#[non_exhaustive]
585#[derive(Debug, Clone, Copy, PartialEq, Eq)]
586pub struct OffsetMinute {
587 pub padding: Padding,
589}
590
591impl OffsetMinute {
592 #[inline]
594 #[must_use = "this returns the result of the operation, without modifying the original"]
595 pub const fn with_padding(self, padding: Padding) -> Self {
596 Self { padding }
597 }
598}
599
600#[non_exhaustive]
602#[derive(Debug, Clone, Copy, PartialEq, Eq)]
603pub struct OffsetSecond {
604 pub padding: Padding,
606}
607
608impl OffsetSecond {
609 #[inline]
611 #[must_use = "this returns the result of the operation, without modifying the original"]
612 pub const fn with_padding(self, padding: Padding) -> Self {
613 Self { padding }
614 }
615}
616
617#[non_exhaustive]
619#[derive(Debug, Clone, Copy, PartialEq, Eq)]
620pub enum Padding {
621 Space,
623 Zero,
625 None,
628}
629
630#[non_exhaustive]
634#[derive(Debug, Clone, Copy, PartialEq, Eq)]
635pub struct Ignore {
636 pub count: NonZero<u16>,
638}
639
640impl Ignore {
643 #[inline]
645 pub const fn count(count: NonZero<u16>) -> Self {
646 Self { count }
647 }
648
649 #[inline]
651 #[must_use = "this returns the result of the operation, without modifying the original"]
652 pub const fn with_count(self, count: NonZero<u16>) -> Self {
653 Self { count }
654 }
655}
656
657#[non_exhaustive]
659#[derive(Debug, Clone, Copy, PartialEq, Eq)]
660pub enum UnixTimestampPrecision {
661 Second,
663 Millisecond,
665 Microsecond,
667 Nanosecond,
669}
670
671#[non_exhaustive]
673#[derive(Debug, Clone, Copy, PartialEq, Eq)]
674pub struct UnixTimestamp {
675 pub precision: UnixTimestampPrecision,
677 pub sign_is_mandatory: bool,
679}
680
681impl UnixTimestamp {
682 #[inline]
684 #[must_use = "this returns the result of the operation, without modifying the original"]
685 pub const fn with_precision(self, precision: UnixTimestampPrecision) -> Self {
686 Self { precision, ..self }
687 }
688
689 #[inline]
691 #[must_use = "this returns the result of the operation, without modifying the original"]
692 pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
693 Self {
694 sign_is_mandatory,
695 ..self
696 }
697 }
698}
699
700#[derive(Debug, Clone, Copy, PartialEq, Eq)]
702pub enum TrailingInput {
703 Prohibit,
705 Discard,
707}
708
709#[non_exhaustive]
711#[derive(Debug, Clone, Copy, PartialEq, Eq)]
712pub struct End {
713 pub(crate) trailing_input: TrailingInput,
715}
716
717impl End {
718 #[inline]
720 #[must_use = "this returns the result of the operation, without modifying the original"]
721 pub const fn with_trailing_input(self, trailing_input: TrailingInput) -> Self {
722 Self {
723 trailing_input,
724 ..self
725 }
726 }
727}