Skip to main content

jiff/error/fmt/
strtime.rs

1use crate::{civil::Weekday, error, tz::Offset, util::escape};
2
3#[derive(#[automatically_derived]impl ::core::clone::Clone for Error {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        match self {
            Self::ColonCount { directive: __self_0 } =>
                Error::ColonCount {
                    directive: ::core::clone::Clone::clone(__self_0),
                },
            Self::DirectiveFailure { directive: __self_0, colons: __self_1 }
                =>
                Error::DirectiveFailure {
                    directive: ::core::clone::Clone::clone(__self_0),
                    colons: ::core::clone::Clone::clone(__self_1),
                },
            Self::DirectiveFailureDot { directive: __self_0 } =>
                Error::DirectiveFailureDot {
                    directive: ::core::clone::Clone::clone(__self_0),
                },
            Self::ExpectedDirectiveAfterColons =>
                Error::ExpectedDirectiveAfterColons,
            Self::ExpectedDirectiveAfterFlag { flag: __self_0 } =>
                Error::ExpectedDirectiveAfterFlag {
                    flag: ::core::clone::Clone::clone(__self_0),
                },
            Self::ExpectedDirectiveAfterWidth =>
                Error::ExpectedDirectiveAfterWidth,
            Self::FailedStrftime => Error::FailedStrftime,
            Self::FailedStrptime => Error::FailedStrptime,
            Self::FailedWidth => Error::FailedWidth,
            Self::InvalidDate => Error::InvalidDate,
            Self::InvalidISOWeekDate => Error::InvalidISOWeekDate,
            Self::InvalidWeekdayMonday { got: __self_0 } =>
                Error::InvalidWeekdayMonday {
                    got: ::core::clone::Clone::clone(__self_0),
                },
            Self::InvalidWeekdaySunday { got: __self_0 } =>
                Error::InvalidWeekdaySunday {
                    got: ::core::clone::Clone::clone(__self_0),
                },
            Self::MismatchOffset { parsed: __self_0, got: __self_1 } =>
                Error::MismatchOffset {
                    parsed: ::core::clone::Clone::clone(__self_0),
                    got: ::core::clone::Clone::clone(__self_1),
                },
            Self::MismatchWeekday { parsed: __self_0, got: __self_1 } =>
                Error::MismatchWeekday {
                    parsed: ::core::clone::Clone::clone(__self_0),
                    got: ::core::clone::Clone::clone(__self_1),
                },
            Self::MissingTimeHourForFractional =>
                Error::MissingTimeHourForFractional,
            Self::MissingTimeHourForMinute => Error::MissingTimeHourForMinute,
            Self::MissingTimeHourForSecond => Error::MissingTimeHourForSecond,
            Self::MissingTimeMinuteForFractional =>
                Error::MissingTimeMinuteForFractional,
            Self::MissingTimeMinuteForSecond =>
                Error::MissingTimeMinuteForSecond,
            Self::MissingTimeSecondForFractional =>
                Error::MissingTimeSecondForFractional,
            Self::RangeTimestamp => Error::RangeTimestamp,
            Self::RangeWidth => Error::RangeWidth,
            Self::RequiredDateForDateTime => Error::RequiredDateForDateTime,
            Self::RequiredDateTimeForTimestamp =>
                Error::RequiredDateTimeForTimestamp,
            Self::RequiredDateTimeForZonedDateTime =>
                Error::RequiredDateTimeForZonedDateTime,
            Self::RequiredOffsetForTimestamp =>
                Error::RequiredOffsetForTimestamp,
            Self::RequiredSomeDayForDate => Error::RequiredSomeDayForDate,
            Self::RequiredTimeForDateTime => Error::RequiredTimeForDateTime,
            Self::RequiredYearForDate => Error::RequiredYearForDate,
            Self::UnconsumedStrptime { remaining: __self_0 } =>
                Error::UnconsumedStrptime {
                    remaining: ::core::clone::Clone::clone(__self_0),
                },
            Self::UnexpectedEndAfterDot => Error::UnexpectedEndAfterDot,
            Self::UnexpectedEndAfterPercent =>
                Error::UnexpectedEndAfterPercent,
            Self::UnknownDirectiveAfterDot { directive: __self_0 } =>
                Error::UnknownDirectiveAfterDot {
                    directive: ::core::clone::Clone::clone(__self_0),
                },
            Self::UnknownDirective { directive: __self_0 } =>
                Error::UnknownDirective {
                    directive: ::core::clone::Clone::clone(__self_0),
                },
            Self::ZonedDateTimeOffsetOrTz => Error::ZonedDateTimeOffsetOrTz,
        }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for Error {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::ColonCount { directive: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "ColonCount directive", &__self_0),
            Self::DirectiveFailure { directive: __self_0, colons: __self_1 }
                =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "DirectiveFailure directive colons", __self_0, &__self_1),
            Self::DirectiveFailureDot { directive: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "DirectiveFailureDot directive", &__self_0),
            Self::ExpectedDirectiveAfterColons =>
                ::core::fmt::Formatter::write_str(f,
                    "ExpectedDirectiveAfterColons"),
            Self::ExpectedDirectiveAfterFlag { flag: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "ExpectedDirectiveAfterFlag flag", &__self_0),
            Self::ExpectedDirectiveAfterWidth =>
                ::core::fmt::Formatter::write_str(f,
                    "ExpectedDirectiveAfterWidth"),
            Self::FailedStrftime =>
                ::core::fmt::Formatter::write_str(f, "FailedStrftime"),
            Self::FailedStrptime =>
                ::core::fmt::Formatter::write_str(f, "FailedStrptime"),
            Self::FailedWidth =>
                ::core::fmt::Formatter::write_str(f, "FailedWidth"),
            Self::InvalidDate =>
                ::core::fmt::Formatter::write_str(f, "InvalidDate"),
            Self::InvalidISOWeekDate =>
                ::core::fmt::Formatter::write_str(f, "InvalidISOWeekDate"),
            Self::InvalidWeekdayMonday { got: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "InvalidWeekdayMonday got", &__self_0),
            Self::InvalidWeekdaySunday { got: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "InvalidWeekdaySunday got", &__self_0),
            Self::MismatchOffset { parsed: __self_0, got: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "MismatchOffset parsed got", __self_0, &__self_1),
            Self::MismatchWeekday { parsed: __self_0, got: __self_1 } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "MismatchWeekday parsed got", __self_0, &__self_1),
            Self::MissingTimeHourForFractional =>
                ::core::fmt::Formatter::write_str(f,
                    "MissingTimeHourForFractional"),
            Self::MissingTimeHourForMinute =>
                ::core::fmt::Formatter::write_str(f,
                    "MissingTimeHourForMinute"),
            Self::MissingTimeHourForSecond =>
                ::core::fmt::Formatter::write_str(f,
                    "MissingTimeHourForSecond"),
            Self::MissingTimeMinuteForFractional =>
                ::core::fmt::Formatter::write_str(f,
                    "MissingTimeMinuteForFractional"),
            Self::MissingTimeMinuteForSecond =>
                ::core::fmt::Formatter::write_str(f,
                    "MissingTimeMinuteForSecond"),
            Self::MissingTimeSecondForFractional =>
                ::core::fmt::Formatter::write_str(f,
                    "MissingTimeSecondForFractional"),
            Self::RangeTimestamp =>
                ::core::fmt::Formatter::write_str(f, "RangeTimestamp"),
            Self::RangeWidth =>
                ::core::fmt::Formatter::write_str(f, "RangeWidth"),
            Self::RequiredDateForDateTime =>
                ::core::fmt::Formatter::write_str(f,
                    "RequiredDateForDateTime"),
            Self::RequiredDateTimeForTimestamp =>
                ::core::fmt::Formatter::write_str(f,
                    "RequiredDateTimeForTimestamp"),
            Self::RequiredDateTimeForZonedDateTime =>
                ::core::fmt::Formatter::write_str(f,
                    "RequiredDateTimeForZonedDateTime"),
            Self::RequiredOffsetForTimestamp =>
                ::core::fmt::Formatter::write_str(f,
                    "RequiredOffsetForTimestamp"),
            Self::RequiredSomeDayForDate =>
                ::core::fmt::Formatter::write_str(f,
                    "RequiredSomeDayForDate"),
            Self::RequiredTimeForDateTime =>
                ::core::fmt::Formatter::write_str(f,
                    "RequiredTimeForDateTime"),
            Self::RequiredYearForDate =>
                ::core::fmt::Formatter::write_str(f, "RequiredYearForDate"),
            Self::UnconsumedStrptime { remaining: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnconsumedStrptime remaining", &__self_0),
            Self::UnexpectedEndAfterDot =>
                ::core::fmt::Formatter::write_str(f, "UnexpectedEndAfterDot"),
            Self::UnexpectedEndAfterPercent =>
                ::core::fmt::Formatter::write_str(f,
                    "UnexpectedEndAfterPercent"),
            Self::UnknownDirectiveAfterDot { directive: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnknownDirectiveAfterDot directive", &__self_0),
            Self::UnknownDirective { directive: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "UnknownDirective directive", &__self_0),
            Self::ZonedDateTimeOffsetOrTz =>
                ::core::fmt::Formatter::write_str(f,
                    "ZonedDateTimeOffsetOrTz"),
        }
    }
}Debug)]
4#[cfg_attr(feature = "defmt", derive(defmt::Format))]
5pub(crate) enum Error {
6    ColonCount {
7        directive: u8,
8    },
9    DirectiveFailure {
10        directive: u8,
11        colons: u8,
12    },
13    DirectiveFailureDot {
14        directive: u8,
15    },
16    ExpectedDirectiveAfterColons,
17    ExpectedDirectiveAfterFlag {
18        flag: u8,
19    },
20    ExpectedDirectiveAfterWidth,
21    FailedStrftime,
22    FailedStrptime,
23    FailedWidth,
24    InvalidDate,
25    InvalidISOWeekDate,
26    InvalidWeekdayMonday {
27        got: Weekday,
28    },
29    InvalidWeekdaySunday {
30        got: Weekday,
31    },
32    MismatchOffset {
33        parsed: Offset,
34        got: Offset,
35    },
36    MismatchWeekday {
37        parsed: Weekday,
38        got: Weekday,
39    },
40    MissingTimeHourForFractional,
41    MissingTimeHourForMinute,
42    MissingTimeHourForSecond,
43    MissingTimeMinuteForFractional,
44    MissingTimeMinuteForSecond,
45    MissingTimeSecondForFractional,
46    RangeTimestamp,
47    RangeWidth,
48    RequiredDateForDateTime,
49    RequiredDateTimeForTimestamp,
50    RequiredDateTimeForZonedDateTime,
51    RequiredOffsetForTimestamp,
52    RequiredSomeDayForDate,
53    RequiredTimeForDateTime,
54    RequiredYearForDate,
55    UnconsumedStrptime {
56        #[cfg(feature = "alloc")]
57        #[cfg_attr(feature = "defmt", defmt(Debug2Format))]
58        remaining: alloc::boxed::Box<[u8]>,
59    },
60    UnexpectedEndAfterDot,
61    UnexpectedEndAfterPercent,
62    UnknownDirectiveAfterDot {
63        directive: u8,
64    },
65    UnknownDirective {
66        directive: u8,
67    },
68    ZonedDateTimeOffsetOrTz,
69}
70
71impl Error {
72    pub(crate) fn unconsumed(_remaining: &[u8]) -> Error {
73        Error::UnconsumedStrptime {
74            #[cfg(feature = "alloc")]
75            remaining: _remaining.into(),
76        }
77    }
78}
79
80impl error::IntoError for Error {
81    fn into_error(self) -> error::Error {
82        self.into()
83    }
84}
85
86impl From<Error> for error::Error {
87    #[cold]
88    #[inline(never)]
89    fn from(err: Error) -> error::Error {
90        error::ErrorKind::FmtStrtime(err).into()
91    }
92}
93
94impl core::fmt::Display for Error {
95    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
96        use self::Error::*;
97
98        match *self {
99            ColonCount { directive } => f.write_fmt(format_args!("invalid number of `:` in `%{0}` directive",
        escape::Byte(directive)))write!(
100                f,
101                "invalid number of `:` in `%{directive}` directive",
102                directive = escape::Byte(directive),
103            ),
104            DirectiveFailure { directive, colons } => f.write_fmt(format_args!("%{0}{1} failed",
        escape::RepeatByte { byte: b':', count: colons },
        escape::Byte(directive)))write!(
105                f,
106                "%{colons}{directive} failed",
107                colons = escape::RepeatByte { byte: b':', count: colons },
108                directive = escape::Byte(directive),
109            ),
110            DirectiveFailureDot { directive } => f.write_fmt(format_args!("%.{0} failed", escape::Byte(directive)))write!(
111                f,
112                "%.{directive} failed",
113                directive = escape::Byte(directive),
114            ),
115            ExpectedDirectiveAfterColons => f.write_str(
116                "expected to find specifier directive after colons, \
117                 but found end of format string",
118            ),
119            ExpectedDirectiveAfterFlag { flag } => f.write_fmt(format_args!("expected to find specifier directive after flag `{0}`, but found end of format string",
        escape::Byte(flag)))write!(
120                f,
121                "expected to find specifier directive after flag \
122                 `{flag}`, but found end of format string",
123                flag = escape::Byte(flag),
124            ),
125            ExpectedDirectiveAfterWidth => f.write_str(
126                "expected to find specifier directive after parsed width, \
127                 but found end of format string",
128            ),
129            FailedStrftime => f.write_str("strftime formatting failed"),
130            FailedStrptime => f.write_str("strptime parsing failed"),
131            FailedWidth => {
132                f.write_str("failed to parse conversion specifier width")
133            }
134            InvalidDate => f.write_str("invalid date"),
135            InvalidISOWeekDate => f.write_str("invalid ISO 8601 week date"),
136            InvalidWeekdayMonday { got } => f.write_fmt(format_args!("weekday `{0:?}` is not valid for Monday based week number",
        got))write!(
137                f,
138                "weekday `{got:?}` is not valid for \
139                 Monday based week number",
140            ),
141            InvalidWeekdaySunday { got } => f.write_fmt(format_args!("weekday `{0:?}` is not valid for Sunday based week number",
        got))write!(
142                f,
143                "weekday `{got:?}` is not valid for \
144                 Sunday based week number",
145            ),
146            MissingTimeHourForFractional => f.write_str(
147                "parsing format did not include hour directive, \
148                 but did include fractional second directive (cannot have \
149                 smaller time units with bigger time units missing)",
150            ),
151            MissingTimeHourForMinute => f.write_str(
152                "parsing format did not include hour directive, \
153                 but did include minute directive (cannot have \
154                 smaller time units with bigger time units missing)",
155            ),
156            MissingTimeHourForSecond => f.write_str(
157                "parsing format did not include hour directive, \
158                 but did include second directive (cannot have \
159                 smaller time units with bigger time units missing)",
160            ),
161            MissingTimeMinuteForFractional => f.write_str(
162                "parsing format did not include minute directive, \
163                 but did include fractional second directive (cannot have \
164                 smaller time units with bigger time units missing)",
165            ),
166            MissingTimeMinuteForSecond => f.write_str(
167                "parsing format did not include minute directive, \
168                 but did include second directive (cannot have \
169                 smaller time units with bigger time units missing)",
170            ),
171            MissingTimeSecondForFractional => f.write_str(
172                "parsing format did not include second directive, \
173                 but did include fractional second directive (cannot have \
174                 smaller time units with bigger time units missing)",
175            ),
176            MismatchOffset { parsed, got } => f.write_fmt(format_args!("parsed time zone offset `{0}`, but offset from timestamp and time zone is `{1}`",
        parsed, got))write!(
177                f,
178                "parsed time zone offset `{parsed}`, but \
179                 offset from timestamp and time zone is `{got}`",
180            ),
181            MismatchWeekday { parsed, got } => f.write_fmt(format_args!("parsed weekday `{0:?}` does not match weekday `{1:?}` from parsed date",
        parsed, got))write!(
182                f,
183                "parsed weekday `{parsed:?}` does not match \
184                 weekday `{got:?}` from parsed date",
185            ),
186            RangeTimestamp => f.write_str(
187                "parsed datetime and offset, \
188                 but combining them into a zoned datetime \
189                 is outside Jiff's supported timestamp range",
190            ),
191            RangeWidth => f.write_fmt(format_args!("parsed width is too big, max is {0}", u8::MAX))write!(
192                f,
193                "parsed width is too big, max is {max}",
194                max = u8::MAX
195            ),
196            RequiredDateForDateTime => {
197                f.write_str("date required to parse datetime")
198            }
199            RequiredDateTimeForTimestamp => {
200                f.write_str("datetime required to parse timestamp")
201            }
202            RequiredDateTimeForZonedDateTime => {
203                f.write_str("datetime required to parse zoned datetime")
204            }
205            RequiredOffsetForTimestamp => {
206                f.write_str("offset required to parse timestamp")
207            }
208            RequiredSomeDayForDate => f.write_str(
209                "a month/day, day-of-year or week date must be \
210                 present to create a date, but none were found",
211            ),
212            RequiredTimeForDateTime => {
213                f.write_str("time required to parse datetime")
214            }
215            RequiredYearForDate => f.write_str("year required to parse date"),
216            #[cfg(feature = "alloc")]
217            UnconsumedStrptime { ref remaining } => f.write_fmt(format_args!("strptime expects to consume the entire input, but `{0}` remains unparsed",
        escape::Bytes(remaining)))write!(
218                f,
219                "strptime expects to consume the entire input, but \
220                 `{remaining}` remains unparsed",
221                remaining = escape::Bytes(remaining),
222            ),
223            #[cfg(not(feature = "alloc"))]
224            UnconsumedStrptime {} => f.write_str(
225                "strptime expects to consume the entire input, but \
226                 there is unparsed input remaining",
227            ),
228            UnexpectedEndAfterDot => f.write_str(
229                "invalid format string, expected directive after `%.`",
230            ),
231            UnexpectedEndAfterPercent => f.write_str(
232                "invalid format string, expected byte after `%`, \
233                 but found end of format string",
234            ),
235            UnknownDirective { directive } => f.write_fmt(format_args!("found unrecognized specifier directive `{0}`",
        escape::Byte(directive)))write!(
236                f,
237                "found unrecognized specifier directive `{directive}`",
238                directive = escape::Byte(directive),
239            ),
240            UnknownDirectiveAfterDot { directive } => f.write_fmt(format_args!("found unrecognized specifier directive `{0}` following `%.`",
        escape::Byte(directive)))write!(
241                f,
242                "found unrecognized specifier directive `{directive}` \
243                 following `%.`",
244                directive = escape::Byte(directive),
245            ),
246            ZonedDateTimeOffsetOrTz => f.write_str(
247                "either offset (from `%z`) or IANA time zone identifier \
248                 (from `%Q`) is required for parsing zoned datetime",
249            ),
250        }
251    }
252}
253
254#[derive(#[automatically_derived]impl ::core::clone::Clone for ParseError {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        match self {
            Self::ExpectedAmPm => ParseError::ExpectedAmPm,
            Self::ExpectedAmPmTooShort => ParseError::ExpectedAmPmTooShort,
            Self::ExpectedIanaTz => ParseError::ExpectedIanaTz,
            Self::ExpectedIanaTzEndOfInput =>
                ParseError::ExpectedIanaTzEndOfInput,
            Self::ExpectedMonthAbbreviation =>
                ParseError::ExpectedMonthAbbreviation,
            Self::ExpectedMonthAbbreviationTooShort =>
                ParseError::ExpectedMonthAbbreviationTooShort,
            Self::ExpectedWeekdayAbbreviation =>
                ParseError::ExpectedWeekdayAbbreviation,
            Self::ExpectedWeekdayAbbreviationTooShort =>
                ParseError::ExpectedWeekdayAbbreviationTooShort,
            Self::ExpectedChoice { available: __self_0 } =>
                ParseError::ExpectedChoice {
                    available: ::core::clone::Clone::clone(__self_0),
                },
            Self::ExpectedFractionalDigit =>
                ParseError::ExpectedFractionalDigit,
            Self::ExpectedMatchLiteralByte { expected: __self_0, got: __self_1
                } =>
                ParseError::ExpectedMatchLiteralByte {
                    expected: ::core::clone::Clone::clone(__self_0),
                    got: ::core::clone::Clone::clone(__self_1),
                },
            Self::ExpectedMatchLiteralEndOfInput { expected: __self_0 } =>
                ParseError::ExpectedMatchLiteralEndOfInput {
                    expected: ::core::clone::Clone::clone(__self_0),
                },
            Self::ExpectedNonEmpty { directive: __self_0 } =>
                ParseError::ExpectedNonEmpty {
                    directive: ::core::clone::Clone::clone(__self_0),
                },
            Self::NotAllowedLocaleClockTime =>
                ParseError::NotAllowedLocaleClockTime,
            Self::NotAllowedLocaleDate => ParseError::NotAllowedLocaleDate,
            Self::NotAllowedLocaleDateAndTime =>
                ParseError::NotAllowedLocaleDateAndTime,
            Self::NotAllowedLocaleTwelveHourClockTime =>
                ParseError::NotAllowedLocaleTwelveHourClockTime,
            Self::NotAllowedTimeZoneAbbreviation =>
                ParseError::NotAllowedTimeZoneAbbreviation,
            Self::ParseDay => ParseError::ParseDay,
            Self::ParseDayOfYear => ParseError::ParseDayOfYear,
            Self::ParseCentury => ParseError::ParseCentury,
            Self::ParseFractionalSeconds =>
                ParseError::ParseFractionalSeconds,
            Self::ParseHour => ParseError::ParseHour,
            Self::ParseIsoWeekNumber => ParseError::ParseIsoWeekNumber,
            Self::ParseIsoWeekYear => ParseError::ParseIsoWeekYear,
            Self::ParseIsoWeekYearTwoDigit =>
                ParseError::ParseIsoWeekYearTwoDigit,
            Self::ParseMinute => ParseError::ParseMinute,
            Self::ParseMondayWeekNumber => ParseError::ParseMondayWeekNumber,
            Self::ParseMonth => ParseError::ParseMonth,
            Self::ParseSecond => ParseError::ParseSecond,
            Self::ParseSundayWeekNumber => ParseError::ParseSundayWeekNumber,
            Self::ParseTimestamp => ParseError::ParseTimestamp,
            Self::ParseWeekdayNumber => ParseError::ParseWeekdayNumber,
            Self::ParseYear => ParseError::ParseYear,
            Self::ParseYearTwoDigit => ParseError::ParseYearTwoDigit,
            Self::UnknownMonthName => ParseError::UnknownMonthName,
            Self::UnknownWeekdayAbbreviation =>
                ParseError::UnknownWeekdayAbbreviation,
        }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for ParseError {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::ExpectedAmPm =>
                ::core::fmt::Formatter::write_str(f, "ExpectedAmPm"),
            Self::ExpectedAmPmTooShort =>
                ::core::fmt::Formatter::write_str(f, "ExpectedAmPmTooShort"),
            Self::ExpectedIanaTz =>
                ::core::fmt::Formatter::write_str(f, "ExpectedIanaTz"),
            Self::ExpectedIanaTzEndOfInput =>
                ::core::fmt::Formatter::write_str(f,
                    "ExpectedIanaTzEndOfInput"),
            Self::ExpectedMonthAbbreviation =>
                ::core::fmt::Formatter::write_str(f,
                    "ExpectedMonthAbbreviation"),
            Self::ExpectedMonthAbbreviationTooShort =>
                ::core::fmt::Formatter::write_str(f,
                    "ExpectedMonthAbbreviationTooShort"),
            Self::ExpectedWeekdayAbbreviation =>
                ::core::fmt::Formatter::write_str(f,
                    "ExpectedWeekdayAbbreviation"),
            Self::ExpectedWeekdayAbbreviationTooShort =>
                ::core::fmt::Formatter::write_str(f,
                    "ExpectedWeekdayAbbreviationTooShort"),
            Self::ExpectedChoice { available: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "ExpectedChoice available", &__self_0),
            Self::ExpectedFractionalDigit =>
                ::core::fmt::Formatter::write_str(f,
                    "ExpectedFractionalDigit"),
            Self::ExpectedMatchLiteralByte { expected: __self_0, got: __self_1
                } =>
                ::core::fmt::Formatter::debug_struct_field2_finish(f,
                    "ExpectedMatchLiteralByte expected got", __self_0,
                    &__self_1),
            Self::ExpectedMatchLiteralEndOfInput { expected: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "ExpectedMatchLiteralEndOfInput expected", &__self_0),
            Self::ExpectedNonEmpty { directive: __self_0 } =>
                ::core::fmt::Formatter::debug_struct_field1_finish(f,
                    "ExpectedNonEmpty directive", &__self_0),
            Self::NotAllowedLocaleClockTime =>
                ::core::fmt::Formatter::write_str(f,
                    "NotAllowedLocaleClockTime"),
            Self::NotAllowedLocaleDate =>
                ::core::fmt::Formatter::write_str(f, "NotAllowedLocaleDate"),
            Self::NotAllowedLocaleDateAndTime =>
                ::core::fmt::Formatter::write_str(f,
                    "NotAllowedLocaleDateAndTime"),
            Self::NotAllowedLocaleTwelveHourClockTime =>
                ::core::fmt::Formatter::write_str(f,
                    "NotAllowedLocaleTwelveHourClockTime"),
            Self::NotAllowedTimeZoneAbbreviation =>
                ::core::fmt::Formatter::write_str(f,
                    "NotAllowedTimeZoneAbbreviation"),
            Self::ParseDay =>
                ::core::fmt::Formatter::write_str(f, "ParseDay"),
            Self::ParseDayOfYear =>
                ::core::fmt::Formatter::write_str(f, "ParseDayOfYear"),
            Self::ParseCentury =>
                ::core::fmt::Formatter::write_str(f, "ParseCentury"),
            Self::ParseFractionalSeconds =>
                ::core::fmt::Formatter::write_str(f,
                    "ParseFractionalSeconds"),
            Self::ParseHour =>
                ::core::fmt::Formatter::write_str(f, "ParseHour"),
            Self::ParseIsoWeekNumber =>
                ::core::fmt::Formatter::write_str(f, "ParseIsoWeekNumber"),
            Self::ParseIsoWeekYear =>
                ::core::fmt::Formatter::write_str(f, "ParseIsoWeekYear"),
            Self::ParseIsoWeekYearTwoDigit =>
                ::core::fmt::Formatter::write_str(f,
                    "ParseIsoWeekYearTwoDigit"),
            Self::ParseMinute =>
                ::core::fmt::Formatter::write_str(f, "ParseMinute"),
            Self::ParseMondayWeekNumber =>
                ::core::fmt::Formatter::write_str(f, "ParseMondayWeekNumber"),
            Self::ParseMonth =>
                ::core::fmt::Formatter::write_str(f, "ParseMonth"),
            Self::ParseSecond =>
                ::core::fmt::Formatter::write_str(f, "ParseSecond"),
            Self::ParseSundayWeekNumber =>
                ::core::fmt::Formatter::write_str(f, "ParseSundayWeekNumber"),
            Self::ParseTimestamp =>
                ::core::fmt::Formatter::write_str(f, "ParseTimestamp"),
            Self::ParseWeekdayNumber =>
                ::core::fmt::Formatter::write_str(f, "ParseWeekdayNumber"),
            Self::ParseYear =>
                ::core::fmt::Formatter::write_str(f, "ParseYear"),
            Self::ParseYearTwoDigit =>
                ::core::fmt::Formatter::write_str(f, "ParseYearTwoDigit"),
            Self::UnknownMonthName =>
                ::core::fmt::Formatter::write_str(f, "UnknownMonthName"),
            Self::UnknownWeekdayAbbreviation =>
                ::core::fmt::Formatter::write_str(f,
                    "UnknownWeekdayAbbreviation"),
        }
    }
}Debug)]
255#[cfg_attr(feature = "defmt", derive(defmt::Format))]
256pub(crate) enum ParseError {
257    ExpectedAmPm,
258    ExpectedAmPmTooShort,
259    ExpectedIanaTz,
260    ExpectedIanaTzEndOfInput,
261    ExpectedMonthAbbreviation,
262    ExpectedMonthAbbreviationTooShort,
263    ExpectedWeekdayAbbreviation,
264    ExpectedWeekdayAbbreviationTooShort,
265    ExpectedChoice {
266        available: &'static [&'static [u8]],
267    },
268    ExpectedFractionalDigit,
269    ExpectedMatchLiteralByte {
270        expected: u8,
271        got: u8,
272    },
273    ExpectedMatchLiteralEndOfInput {
274        expected: u8,
275    },
276    ExpectedNonEmpty {
277        directive: u8,
278    },
279    #[cfg(not(feature = "alloc"))]
280    NotAllowedAlloc {
281        directive: u8,
282        colons: u8,
283    },
284    NotAllowedLocaleClockTime,
285    NotAllowedLocaleDate,
286    NotAllowedLocaleDateAndTime,
287    NotAllowedLocaleTwelveHourClockTime,
288    NotAllowedTimeZoneAbbreviation,
289    ParseDay,
290    ParseDayOfYear,
291    ParseCentury,
292    ParseFractionalSeconds,
293    ParseHour,
294    ParseIsoWeekNumber,
295    ParseIsoWeekYear,
296    ParseIsoWeekYearTwoDigit,
297    ParseMinute,
298    ParseMondayWeekNumber,
299    ParseMonth,
300    ParseSecond,
301    ParseSundayWeekNumber,
302    ParseTimestamp,
303    ParseWeekdayNumber,
304    ParseYear,
305    ParseYearTwoDigit,
306    UnknownMonthName,
307    UnknownWeekdayAbbreviation,
308}
309
310impl error::IntoError for ParseError {
311    fn into_error(self) -> error::Error {
312        self.into()
313    }
314}
315
316impl From<ParseError> for error::Error {
317    #[cold]
318    #[inline(never)]
319    fn from(err: ParseError) -> error::Error {
320        error::ErrorKind::FmtStrtimeParse(err).into()
321    }
322}
323
324impl core::fmt::Display for ParseError {
325    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
326        use self::ParseError::*;
327
328        match *self {
329            ExpectedAmPm => f.write_str("expected to find `AM` or `PM`"),
330            ExpectedAmPmTooShort => f.write_str(
331                "expected to find `AM` or `PM`, \
332                 but the remaining input is too short \
333                 to contain one",
334            ),
335            ExpectedIanaTz => f.write_str(
336                "expected to find the start of an IANA time zone \
337                 identifier name or component",
338            ),
339            ExpectedIanaTzEndOfInput => f.write_str(
340                "expected to find the start of an IANA time zone \
341                 identifier name or component, \
342                 but found end of input instead",
343            ),
344            ExpectedMonthAbbreviation => {
345                f.write_str("expected to find month name abbreviation")
346            }
347            ExpectedMonthAbbreviationTooShort => f.write_str(
348                "expected to find month name abbreviation, \
349                 but the remaining input is too short \
350                 to contain one",
351            ),
352            ExpectedWeekdayAbbreviation => {
353                f.write_str("expected to find weekday abbreviation")
354            }
355            ExpectedWeekdayAbbreviationTooShort => f.write_str(
356                "expected to find weekday abbreviation, \
357                 but the remaining input is too short \
358                 to contain one",
359            ),
360            ExpectedChoice { available } => {
361                f.write_str(
362                    "failed to find expected value, available choices are: ",
363                )?;
364                for (i, choice) in available.iter().enumerate() {
365                    if i > 0 {
366                        f.write_str(", ")?;
367                    }
368                    f.write_fmt(format_args!("{0}", escape::Bytes(choice)))write!(f, "{}", escape::Bytes(choice))?;
369                }
370                Ok(())
371            }
372            ExpectedFractionalDigit => f.write_str(
373                "expected at least one fractional decimal digit, \
374                 but did not find any",
375            ),
376            ExpectedMatchLiteralByte { expected, got } => f.write_fmt(format_args!("expected to match literal byte `{0}` from format string, but found byte `{1}` in input",
        escape::Byte(expected), escape::Byte(got)))write!(
377                f,
378                "expected to match literal byte `{expected}` from \
379                 format string, but found byte `{got}` in input",
380                expected = escape::Byte(expected),
381                got = escape::Byte(got),
382            ),
383            ExpectedMatchLiteralEndOfInput { expected } => f.write_fmt(format_args!("expected to match literal byte `{0}` from format string, but found end of input",
        escape::Byte(expected)))write!(
384                f,
385                "expected to match literal byte `{expected}` from \
386                 format string, but found end of input",
387                expected = escape::Byte(expected),
388            ),
389            ExpectedNonEmpty { directive } => f.write_fmt(format_args!("expected non-empty input for directive `%{0}`, but found end of input",
        escape::Byte(directive)))write!(
390                f,
391                "expected non-empty input for directive `%{directive}`, \
392                 but found end of input",
393                directive = escape::Byte(directive),
394            ),
395            #[cfg(not(feature = "alloc"))]
396            NotAllowedAlloc { directive, colons } => write!(
397                f,
398                "cannot parse `%{colons}{directive}` \
399                 without Jiff's `alloc` feature enabled",
400                colons = escape::RepeatByte { byte: b':', count: colons },
401                directive = escape::Byte(directive),
402            ),
403            NotAllowedLocaleClockTime => {
404                f.write_str("parsing locale clock time is not allowed")
405            }
406            NotAllowedLocaleDate => {
407                f.write_str("parsing locale date is not allowed")
408            }
409            NotAllowedLocaleDateAndTime => {
410                f.write_str("parsing locale date and time is not allowed")
411            }
412            NotAllowedLocaleTwelveHourClockTime => {
413                f.write_str("parsing locale 12-hour clock time is not allowed")
414            }
415            NotAllowedTimeZoneAbbreviation => {
416                f.write_str("parsing time zone abbreviation is not allowed")
417            }
418            ParseCentury => {
419                f.write_str("failed to parse year number for century")
420            }
421            ParseDay => f.write_str("failed to parse day number"),
422            ParseDayOfYear => {
423                f.write_str("failed to parse day of year number")
424            }
425            ParseFractionalSeconds => f.write_str(
426                "failed to parse fractional second component \
427                 (up to 9 digits, nanosecond precision)",
428            ),
429            ParseHour => f.write_str("failed to parse hour number"),
430            ParseMinute => f.write_str("failed to parse minute number"),
431            ParseWeekdayNumber => {
432                f.write_str("failed to parse weekday number")
433            }
434            ParseIsoWeekNumber => {
435                f.write_str("failed to parse ISO 8601 week number")
436            }
437            ParseIsoWeekYear => {
438                f.write_str("failed to parse ISO 8601 week year")
439            }
440            ParseIsoWeekYearTwoDigit => {
441                f.write_str("failed to parse 2-digit ISO 8601 week year")
442            }
443            ParseMondayWeekNumber => {
444                f.write_str("failed to parse Monday-based week number")
445            }
446            ParseMonth => f.write_str("failed to parse month number"),
447            ParseSecond => f.write_str("failed to parse second number"),
448            ParseSundayWeekNumber => {
449                f.write_str("failed to parse Sunday-based week number")
450            }
451            ParseTimestamp => {
452                f.write_str("failed to parse Unix timestamp (in seconds)")
453            }
454            ParseYear => f.write_str("failed to parse year"),
455            ParseYearTwoDigit => f.write_str("failed to parse 2-digit year"),
456            UnknownMonthName => f.write_str("unrecognized month name"),
457            UnknownWeekdayAbbreviation => {
458                f.write_str("unrecognized weekday abbreviation")
459            }
460        }
461    }
462}
463
464#[derive(#[automatically_derived]impl ::core::clone::Clone for FormatError {
    #[inline]
    #[rustc_trivial_field_reads]
    fn clone(&self) -> Self {
        match self {
            Self::RequiresDate => FormatError::RequiresDate,
            Self::RequiresInstant => FormatError::RequiresInstant,
            Self::RequiresOffset => FormatError::RequiresOffset,
            Self::RequiresTime => FormatError::RequiresTime,
            Self::RequiresTimeZone => FormatError::RequiresTimeZone,
            Self::RequiresTimeZoneOrOffset =>
                FormatError::RequiresTimeZoneOrOffset,
            Self::InvalidUtf8 => FormatError::InvalidUtf8,
            Self::ZeroPrecisionFloat => FormatError::ZeroPrecisionFloat,
            Self::ZeroPrecisionNano => FormatError::ZeroPrecisionNano,
        }
    }
}Clone, #[automatically_derived]impl ::core::fmt::Debug for FormatError {
    #[inline]
    #[rustc_trivial_field_reads]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_c_like_enum_write_str(f,
            "RequiresDate RequiresInstant RequiresOffset RequiresTime RequiresTimeZone RequiresTimeZoneOrOffset InvalidUtf8 ZeroPrecisionFloat ZeroPrecisionNano",
            match self {
                FormatError::RequiresDate => 0usize,
                FormatError::RequiresInstant => 13usize,
                FormatError::RequiresOffset => 29usize,
                FormatError::RequiresTime => 44usize,
                FormatError::RequiresTimeZone => 57usize,
                FormatError::RequiresTimeZoneOrOffset => 74usize,
                FormatError::InvalidUtf8 => 99usize,
                FormatError::ZeroPrecisionFloat => 111usize,
                FormatError::ZeroPrecisionNano => 130usize,
            })
    }
}Debug)]
465#[cfg_attr(feature = "defmt", derive(defmt::Format))]
466pub(crate) enum FormatError {
467    RequiresDate,
468    RequiresInstant,
469    RequiresOffset,
470    RequiresTime,
471    RequiresTimeZone,
472    RequiresTimeZoneOrOffset,
473    InvalidUtf8,
474    ZeroPrecisionFloat,
475    ZeroPrecisionNano,
476}
477
478impl error::IntoError for FormatError {
479    fn into_error(self) -> error::Error {
480        self.into()
481    }
482}
483
484impl From<FormatError> for error::Error {
485    #[cold]
486    #[inline(never)]
487    fn from(err: FormatError) -> error::Error {
488        error::ErrorKind::FmtStrtimeFormat(err).into()
489    }
490}
491
492impl core::fmt::Display for FormatError {
493    fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
494        use self::FormatError::*;
495
496        match *self {
497            RequiresDate => f.write_str("requires date to format"),
498            RequiresInstant => f.write_str(
499                "requires instant (a timestamp or a date, time and offset)",
500            ),
501            RequiresTime => f.write_str("requires time to format"),
502            RequiresOffset => f.write_str("requires time zone offset"),
503            RequiresTimeZone => {
504                f.write_str("requires IANA time zone identifier")
505            }
506            RequiresTimeZoneOrOffset => f.write_str(
507                "requires IANA time zone identifier or \
508                 time zone offset, but neither were present",
509            ),
510            InvalidUtf8 => {
511                f.write_str("invalid format string, it must be valid UTF-8")
512            }
513            ZeroPrecisionFloat => {
514                f.write_str("zero precision with %f is not allowed")
515            }
516            ZeroPrecisionNano => {
517                f.write_str("zero precision with %N is not allowed")
518            }
519        }
520    }
521}