Skip to main content

time/format_description/
component.rs

1//! Part of a format description.
2
3use crate::format_description::modifier;
4
5/// Indicate whether the hour is "am" or "pm".
6#[derive(Debug, Clone, Copy, PartialEq, Eq)]
7pub(crate) enum Period {
8    #[allow(clippy::missing_docs_in_private_items)]
9    Am,
10    #[allow(clippy::missing_docs_in_private_items)]
11    Pm,
12}
13
14/// A component of a larger format description.
15#[non_exhaustive]
16#[allow(deprecated)]
17#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub enum Component {
19    /// Day of the month.
20    Day(modifier::Day),
21    /// Month of the year in the abbreviated form (e.g. "Jan").
22    MonthShort(modifier::MonthShort),
23    /// Month of the year in the full form (e.g. "January").
24    MonthLong(modifier::MonthLong),
25    /// Month of the year in the numerical form (e.g. "1" for January).
26    MonthNumerical(modifier::MonthNumerical),
27    /// Ordinal day of the year.
28    Ordinal(modifier::Ordinal),
29    /// Weekday in the abbreviated form (e.g. "Mon").
30    WeekdayShort(modifier::WeekdayShort),
31    /// Weekday in the full form (e.g. "Monday").
32    WeekdayLong(modifier::WeekdayLong),
33    /// Weekday number where Sunday is either 0 or 1 depending on the modifier.
34    WeekdaySunday(modifier::WeekdaySunday),
35    /// Weekday number where Monday is either 0 or 1 depending on the modifier.
36    WeekdayMonday(modifier::WeekdayMonday),
37    /// Week number of the year, where week 1 starts is the week beginning on Monday that contains
38    /// January 4.
39    WeekNumberIso(modifier::WeekNumberIso),
40    /// Week number of the year, where week 1 starts on the first Sunday of the calendar year.
41    WeekNumberSunday(modifier::WeekNumberSunday),
42    /// Week number of the year, where week 1 starts on the first Monday of the calendar year.
43    WeekNumberMonday(modifier::WeekNumberMonday),
44    /// The calendar year. Supports the extended range.
45    CalendarYearFullExtendedRange(modifier::CalendarYearFullExtendedRange),
46    /// The calendar year. Does not support the extended range.
47    CalendarYearFullStandardRange(modifier::CalendarYearFullStandardRange),
48    /// The ISO week-based year. Supports the extended range.
49    IsoYearFullExtendedRange(modifier::IsoYearFullExtendedRange),
50    /// The ISO week-based year. Does not support the extended range.
51    IsoYearFullStandardRange(modifier::IsoYearFullStandardRange),
52    /// The century of the calendar year. Supports the extended range.
53    CalendarYearCenturyExtendedRange(modifier::CalendarYearCenturyExtendedRange),
54    /// The century of the calendar year. Does not support the extended range.
55    CalendarYearCenturyStandardRange(modifier::CalendarYearCenturyStandardRange),
56    /// The century of the ISO week-based year. Supports the extended range.
57    IsoYearCenturyExtendedRange(modifier::IsoYearCenturyExtendedRange),
58    /// The century of the ISO week-based year. Does not support the extended range.
59    IsoYearCenturyStandardRange(modifier::IsoYearCenturyStandardRange),
60    /// The last two digits of the calendar year.
61    CalendarYearLastTwo(modifier::CalendarYearLastTwo),
62    /// The last two digits of the ISO week-based year.
63    IsoYearLastTwo(modifier::IsoYearLastTwo),
64    /// Hour of the day using the 12-hour clock.
65    Hour12(modifier::Hour12),
66    /// Hour of the day using the 24-hour clock.
67    Hour24(modifier::Hour24),
68    /// Minute within the hour.
69    Minute(modifier::Minute),
70    /// AM/PM part of the time.
71    Period(modifier::Period),
72    /// Second within the minute.
73    Second(modifier::Second),
74    /// Subsecond within the second.
75    Subsecond(modifier::Subsecond),
76    /// Hour of the UTC offset.
77    OffsetHour(modifier::OffsetHour),
78    /// Minute within the hour of the UTC offset.
79    OffsetMinute(modifier::OffsetMinute),
80    /// Second within the minute of the UTC offset.
81    OffsetSecond(modifier::OffsetSecond),
82    /// A number of bytes to ignore when parsing. This has no effect on formatting.
83    Ignore(modifier::Ignore),
84    /// A Unix timestamp in seconds.
85    UnixTimestampSecond(modifier::UnixTimestampSecond),
86    /// A Unix timestamp in milliseconds.
87    UnixTimestampMillisecond(modifier::UnixTimestampMillisecond),
88    /// A Unix timestamp in microseconds.
89    UnixTimestampMicrosecond(modifier::UnixTimestampMicrosecond),
90    /// A Unix timestamp in nanoseconds.
91    UnixTimestampNanosecond(modifier::UnixTimestampNanosecond),
92    /// The end of input. Parsing this component will fail if there is any input remaining. This
93    /// component neither affects formatting nor consumes any input when parsing.
94    End(modifier::End),
95
96    // Start of deprecated components that are no longer emitted by macros or parsers. They must
97    // be maintained for backward compatibility, as downstream users could have constructed them
98    // manually.
99    /// Month of the year.
100    #[deprecated(
101        since = "0.3.48",
102        note = "use `MonthShort`, `MonthLong`, or `MonthNumeric` instead"
103    )]
104    Month(modifier::Month),
105    /// Day of the week.
106    #[deprecated(
107        since = "0.3.48",
108        note = "use `WeekdayShort`, `WeekdayLong`, or `WeekdaySunday`, or `WeekdayMonday` instead"
109    )]
110    Weekday(modifier::Weekday),
111    /// Week within the year.
112    #[deprecated(
113        since = "0.3.48",
114        note = "use `WeekNumberIso`, `WeekNumberSunday`, or `WeekNumberMonday` instead"
115    )]
116    WeekNumber(modifier::WeekNumber),
117    /// Hour of the day.
118    #[deprecated(since = "0.3.48", note = "use `Hour12` or `Hour24` instead")]
119    Hour(modifier::Hour),
120    /// A Unix timestamp.
121    #[deprecated(
122        since = "0.3.48",
123        note = "use `UnixTimestampSeconds`, `UnixTimestampMilliseconds`, \
124                `UnixTimestampMicroseconds`, or `UnixTimestampNanoseconds` instead"
125    )]
126    UnixTimestamp(modifier::UnixTimestamp),
127    /// Year of the date.
128    #[deprecated(
129        since = "0.3.48",
130        note = "use one of the various `Year*` components instead"
131    )]
132    Year(modifier::Year),
133}