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
use proc_macro::{Ident, Span, TokenStream};

use super::modifier;
use crate::to_tokens::ToTokenStream;

macro_rules! declare_component {
    ($($name:ident)*) => {
        pub(crate) enum Component {$(
            $name(modifier::$name),
        )*}

        impl ToTokenStream for Component {
            fn append_to(self, ts: &mut TokenStream) {
                let mut mts = TokenStream::new();

                let component = match self {$(
                    Self::$name(modifier) => {
                        modifier.append_to(&mut mts);
                        stringify!($name)
                    }
                )*};
                let component = Ident::new(component, Span::mixed_site());

                quote_append! { ts
                    ::time::format_description::Component::#(component)(#S(mts))
                }
            }
        }
    };
}

declare_component! {
    Day
    Month
    Ordinal
    Weekday
    WeekNumber
    Year
    Hour
    Minute
    Period
    Second
    Subsecond
    OffsetHour
    OffsetMinute
    OffsetSecond
    Ignore
    UnixTimestamp
    End
}