time 0.3.47

Date and time library. Fully interoperable with the standard library. Mostly compatible with #![no_std].
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
//! Various modifiers for components.

use core::num::NonZero;

/// Generate the provided code if and only if `pub` is present.
macro_rules! if_pub {
    (pub $(#[$attr:meta])*; $($x:tt)*) => {
        $(#[$attr])*
        ///
        /// This function exists since [`Default::default()`] cannot be used in a `const` context.
        /// It may be removed once that becomes possible. As the [`Default`] trait is in the
        /// prelude, removing this function in the future will not cause any resolution failures for
        /// the overwhelming majority of users; only users who use `#![no_implicit_prelude]` will be
        /// affected. As such it will not be considered a breaking change.
        $($x)*
    };
    ($($_:tt)*) => {};
}

/// Implement `Default` for the given type. This also generates an inherent implementation of a
/// `default` method that is `const fn`, permitting the default value to be used in const contexts.
// Every modifier should use this macro rather than a derived `Default`.
macro_rules! impl_const_default {
    ($($(#[$doc:meta])* $(@$pub:ident)? $type:ty => $default:expr;)*) => {$(
        impl $type {
            if_pub! {
                $($pub)?
                $(#[$doc])*;
                #[inline]
                pub const fn default() -> Self {
                    $default
                }
            }
        }

        $(#[$doc])*
        impl Default for $type {
            #[inline]
            fn default() -> Self {
                $default
            }
        }
    )*};
}

// Keep this first so that it's shown at the top of documentation.
impl_const_default! {
    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
    @pub Day => Self { padding: Padding::Zero };
    /// Creates a modifier that indicates the value uses the
    /// [`Numerical`](Self::Numerical) representation.
    MonthRepr => Self::Numerical;
    /// Creates an instance of this type that indicates the value uses the
    /// [`Numerical`](MonthRepr::Numerical) representation, is [padded with zeroes](Padding::Zero),
    /// and is case-sensitive when parsing.
    @pub Month => Self {
        padding: Padding::Zero,
        repr: MonthRepr::Numerical,
        case_sensitive: true,
    };
    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
    @pub Ordinal => Self { padding: Padding::Zero };
    /// Creates a modifier that indicates the value uses the [`Long`](Self::Long) representation.
    WeekdayRepr => Self::Long;
    /// Creates a modifier that indicates the value uses the [`Long`](WeekdayRepr::Long)
    /// representation and is case-sensitive when parsing. If the representation is changed to a
    /// numerical one, the instance defaults to one-based indexing.
    @pub Weekday => Self {
        repr: WeekdayRepr::Long,
        one_indexed: true,
        case_sensitive: true,
    };
    /// Creates a modifier that indicates that the value uses the [`Iso`](Self::Iso) representation.
    WeekNumberRepr => Self::Iso;
    /// Creates a modifier that indicates that the value is [padded with zeroes](Padding::Zero)
            /// and uses the [`Iso`](WeekNumberRepr::Iso) representation.
    @pub WeekNumber => Self {
        padding: Padding::Zero,
        repr: WeekNumberRepr::Iso,
    };
    /// Creates a modifier that indicates the value uses the [`Full`](Self::Full) representation.
    YearRepr => Self::Full;
    /// Creates a modifier that indicates the value uses the [`Extended`](Self::Extended) range.
    YearRange => Self::Extended;
    /// Creates a modifier that indicates the value uses the [`Full`](YearRepr::Full)
    /// representation, is [padded with zeroes](Padding::Zero), uses the Gregorian calendar as its
    /// base, and only includes the year's sign if necessary.
    @pub Year => Self {
        padding: Padding::Zero,
        repr: YearRepr::Full,
        range: YearRange::Extended,
        iso_week_based: false,
        sign_is_mandatory: false,
    };
    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero) and
    /// has the 24-hour representation.
    @pub Hour => Self {
        padding: Padding::Zero,
        is_12_hour_clock: false,
    };
    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
    @pub Minute => Self { padding: Padding::Zero };
    /// Creates a modifier that indicates the value uses the upper-case representation and is
    /// case-sensitive when parsing.
    @pub Period => Self {
        is_uppercase: true,
        case_sensitive: true,
    };
    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
    @pub Second => Self { padding: Padding::Zero };
    /// Creates a modifier that indicates the stringified value contains [one or more
    /// digits](Self::OneOrMore).
    SubsecondDigits => Self::OneOrMore;
    /// Creates a modifier that indicates the stringified value contains [one or more
    /// digits](SubsecondDigits::OneOrMore).
    @pub Subsecond => Self { digits: SubsecondDigits::OneOrMore };
    /// Creates a modifier that indicates the value only uses a sign for negative values and is
    /// [padded with zeroes](Padding::Zero).
    @pub OffsetHour => Self {
        sign_is_mandatory: false,
        padding: Padding::Zero,
    };
    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
    @pub OffsetMinute => Self { padding: Padding::Zero };
    /// Creates a modifier that indicates the value is [padded with zeroes](Padding::Zero).
    @pub OffsetSecond => Self { padding: Padding::Zero };
    /// Creates a modifier that indicates the value is [padded with zeroes](Self::Zero).
    Padding => Self::Zero;
    /// Creates a modifier that indicates the value represents the [number of seconds](Self::Second)
    /// since the Unix epoch.
    UnixTimestampPrecision => Self::Second;
    /// Creates a modifier that indicates the value represents the [number of
    /// seconds](UnixTimestampPrecision::Second) since the Unix epoch. The sign is not mandatory.
    @pub UnixTimestamp => Self {
        precision: UnixTimestampPrecision::Second,
        sign_is_mandatory: false,
    };
    /// Indicate that any trailing characters after the end of input are prohibited and will cause
    /// an error when used with `parse`.
    TrailingInput => Self::Prohibit;
    /// Creates a modifier used to represent the end of input, not allowing any trailing input (i.e.
    /// the input must be fully consumed).
    @pub End => Self { trailing_input: TrailingInput::Prohibit };
}

/// Day of the month.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Day {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
}

impl Day {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding }
    }
}

/// The representation of a month.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MonthRepr {
    /// The number of the month (January is 1, December is 12).
    Numerical,
    /// The long form of the month name (e.g. "January").
    Long,
    /// The short form of the month name (e.g. "Jan").
    Short,
}

/// Month of the year.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Month {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
    /// What form of representation should be used?
    pub repr: MonthRepr,
    /// Is the value case sensitive when parsing?
    pub case_sensitive: bool,
}

impl Month {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding, ..self }
    }

    /// Set the manner in which the month is represented.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_repr(self, repr: MonthRepr) -> Self {
        Self { repr, ..self }
    }

    /// Set whether the value is case sensitive when parsing.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
        Self {
            case_sensitive,
            ..self
        }
    }
}

/// Ordinal day of the year.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Ordinal {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
}

impl Ordinal {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding }
    }
}

/// The representation used for the day of the week.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WeekdayRepr {
    /// The short form of the weekday (e.g. "Mon").
    Short,
    /// The long form of the weekday (e.g. "Monday").
    Long,
    /// A numerical representation using Sunday as the first day of the week.
    ///
    /// Sunday is either 0 or 1, depending on the other modifier's value.
    Sunday,
    /// A numerical representation using Monday as the first day of the week.
    ///
    /// Monday is either 0 or 1, depending on the other modifier's value.
    Monday,
}

/// Day of the week.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Weekday {
    /// What form of representation should be used?
    pub repr: WeekdayRepr,
    /// When using a numerical representation, should it be zero or one-indexed?
    pub one_indexed: bool,
    /// Is the value case sensitive when parsing?
    pub case_sensitive: bool,
}

impl Weekday {
    /// Set the manner in which the weekday is represented.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_repr(self, repr: WeekdayRepr) -> Self {
        Self { repr, ..self }
    }

    /// Set whether the value is one-indexed when using a numerical representation.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_one_indexed(self, one_indexed: bool) -> Self {
        Self {
            one_indexed,
            ..self
        }
    }

    /// Set whether the value is case sensitive when parsing.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
        Self {
            case_sensitive,
            ..self
        }
    }
}

/// The representation used for the week number.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WeekNumberRepr {
    /// Week 1 is the week that contains January 4.
    Iso,
    /// Week 1 begins on the first Sunday of the calendar year.
    Sunday,
    /// Week 1 begins on the first Monday of the calendar year.
    Monday,
}

/// Week within the year.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct WeekNumber {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
    /// What kind of representation should be used?
    pub repr: WeekNumberRepr,
}

impl WeekNumber {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding, ..self }
    }

    /// Set the manner in which the week number is represented.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_repr(self, repr: WeekNumberRepr) -> Self {
        Self { repr, ..self }
    }
}

/// The representation used for a year value.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum YearRepr {
    /// The full value of the year.
    Full,
    /// All digits except the last two. Includes the sign, if any.
    Century,
    /// Only the last two digits of the year.
    LastTwo,
}

/// The range of years that are supported.
///
/// This modifier has no effect when the year repr is [`LastTwo`](YearRepr::LastTwo).
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum YearRange {
    /// Years between -9999 and 9999 are supported.
    Standard,
    /// Years between -999_999 and 999_999 are supported, with the sign being required if the year
    /// contains more than four digits.
    ///
    /// If the `large-dates` feature is not enabled, this variant is equivalent to `Standard`.
    Extended,
}

/// Year of the date.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Year {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
    /// What kind of representation should be used?
    pub repr: YearRepr,
    /// What range of years is supported?
    pub range: YearRange,
    /// Whether the value is based on the ISO week number or the Gregorian calendar.
    pub iso_week_based: bool,
    /// Whether the `+` sign is present when a positive year contains fewer than five digits.
    pub sign_is_mandatory: bool,
}

impl Year {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding, ..self }
    }

    /// Set the manner in which the year is represented.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_repr(self, repr: YearRepr) -> Self {
        Self { repr, ..self }
    }

    /// Set the range of years that are supported.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_range(self, range: YearRange) -> Self {
        Self { range, ..self }
    }

    /// Set whether the year is based on the ISO week number.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_iso_week_based(self, iso_week_based: bool) -> Self {
        Self {
            iso_week_based,
            ..self
        }
    }

    /// Set whether the `+` sign is mandatory for positive years with fewer than five digits.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
        Self {
            sign_is_mandatory,
            ..self
        }
    }
}

/// Hour of the day.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Hour {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
    /// Is the hour displayed using a 12 or 24-hour clock?
    pub is_12_hour_clock: bool,
}

impl Hour {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding, ..self }
    }

    /// Set whether the hour uses a 12-hour clock.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_is_12_hour_clock(self, is_12_hour_clock: bool) -> Self {
        Self {
            is_12_hour_clock,
            ..self
        }
    }
}

/// Minute within the hour.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Minute {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
}

impl Minute {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding }
    }
}

/// AM/PM part of the time.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Period {
    /// Is the period uppercase or lowercase?
    pub is_uppercase: bool,
    /// Is the value case sensitive when parsing?
    ///
    /// Note that when `false`, the `is_uppercase` field has no effect on parsing behavior.
    pub case_sensitive: bool,
}

impl Period {
    /// Set whether the period is uppercase.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_is_uppercase(self, is_uppercase: bool) -> Self {
        Self {
            is_uppercase,
            ..self
        }
    }

    /// Set whether the value is case sensitive when parsing.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_case_sensitive(self, case_sensitive: bool) -> Self {
        Self {
            case_sensitive,
            ..self
        }
    }
}

/// Second within the minute.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Second {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
}

impl Second {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding }
    }
}

/// The number of digits present in a subsecond representation.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum SubsecondDigits {
    /// Exactly one digit.
    One,
    /// Exactly two digits.
    Two,
    /// Exactly three digits.
    Three,
    /// Exactly four digits.
    Four,
    /// Exactly five digits.
    Five,
    /// Exactly six digits.
    Six,
    /// Exactly seven digits.
    Seven,
    /// Exactly eight digits.
    Eight,
    /// Exactly nine digits.
    Nine,
    /// Any number of digits (up to nine) that is at least one. When formatting, the minimum digits
    /// necessary will be used.
    OneOrMore,
}

/// Subsecond within the second.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Subsecond {
    /// How many digits are present in the component?
    pub digits: SubsecondDigits,
}

impl Subsecond {
    /// Set the number of digits present in the subsecond representation.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_digits(self, digits: SubsecondDigits) -> Self {
        Self { digits }
    }
}

/// Hour of the UTC offset.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OffsetHour {
    /// Whether the `+` sign is present on positive values.
    pub sign_is_mandatory: bool,
    /// The padding to obtain the minimum width.
    pub padding: Padding,
}

impl OffsetHour {
    /// Set whether the `+` sign is mandatory for positive values.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
        Self {
            sign_is_mandatory,
            ..self
        }
    }

    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding, ..self }
    }
}

/// Minute within the hour of the UTC offset.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OffsetMinute {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
}

impl OffsetMinute {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding }
    }
}

/// Second within the minute of the UTC offset.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct OffsetSecond {
    /// The padding to obtain the minimum width.
    pub padding: Padding,
}

impl OffsetSecond {
    /// Set the padding type.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_padding(self, padding: Padding) -> Self {
        Self { padding }
    }
}

/// Type of padding to ensure a minimum width.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Padding {
    /// A space character (` `) should be used as padding.
    Space,
    /// A zero character (`0`) should be used as padding.
    Zero,
    /// There is no padding. This can result in a width below the otherwise minimum number of
    /// characters.
    None,
}

/// Ignore some number of bytes.
///
/// This has no effect when formatting.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Ignore {
    /// The number of bytes to ignore.
    pub count: NonZero<u16>,
}

// Needed as `Default` is deliberately not implemented for `Ignore`. The number of bytes to ignore
// must be explicitly provided.
impl Ignore {
    /// Create an instance of `Ignore` with the provided number of bytes to ignore.
    #[inline]
    pub const fn count(count: NonZero<u16>) -> Self {
        Self { count }
    }

    /// Set the number of bytes to ignore.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_count(self, count: NonZero<u16>) -> Self {
        Self { count }
    }
}

/// The precision of a Unix timestamp.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum UnixTimestampPrecision {
    /// Seconds since the Unix epoch.
    Second,
    /// Milliseconds since the Unix epoch.
    Millisecond,
    /// Microseconds since the Unix epoch.
    Microsecond,
    /// Nanoseconds since the Unix epoch.
    Nanosecond,
}

/// A Unix timestamp.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct UnixTimestamp {
    /// The precision of the timestamp.
    pub precision: UnixTimestampPrecision,
    /// Whether the `+` sign must be present for a non-negative timestamp.
    pub sign_is_mandatory: bool,
}

impl UnixTimestamp {
    /// Set the precision of the timestamp.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_precision(self, precision: UnixTimestampPrecision) -> Self {
        Self { precision, ..self }
    }

    /// Set whether the `+` sign is mandatory for non-negative timestamps.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_sign_is_mandatory(self, sign_is_mandatory: bool) -> Self {
        Self {
            sign_is_mandatory,
            ..self
        }
    }
}

/// Whether trailing input after the declared end is permitted.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum TrailingInput {
    /// Trailing input is not permitted and will cause an error.
    Prohibit,
    /// Trailing input is permitted but discarded.
    Discard,
}

/// The end of input.
#[non_exhaustive]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct End {
    /// How to handle any input after this component.
    pub(crate) trailing_input: TrailingInput,
}

impl End {
    /// Set how to handle any input after this component.
    #[inline]
    #[must_use = "this returns the result of the operation, without modifying the original"]
    pub const fn with_trailing_input(self, trailing_input: TrailingInput) -> Self {
        Self {
            trailing_input,
            ..self
        }
    }
}