icu_datetime/provider/neo/
adapter.rs1use crate::provider::calendar::*;
6use crate::provider::neo::*;
7use alloc::vec;
8use icu_calendar::types::MonthCode;
9
10impl<'a> From<&months::Symbols<'a>> for MonthNames<'a> {
11    fn from(other: &months::Symbols<'a>) -> Self {
12        match other {
13            months::Symbols::SolarTwelve(cow_list) => {
14                let vec: alloc::vec::Vec<&str> = cow_list.iter().map(|x| &**x).collect();
18                MonthNames::Linear((&vec).into())
19            }
20            months::Symbols::Other(zero_map) => {
21                let mut vec = vec![""; 24];
23
24                for (k, v) in zero_map.iter() {
25                    let Some((number, leap)) = MonthCode(*k).parsed() else {
26                        debug_assert!(false, "Found unknown month code {k}");
27                        continue;
28                    };
29                    let offset = if leap { 12 } else { 0 };
30                    if let Some(entry) = vec.get_mut((number + offset - 1) as usize) {
31                        *entry = v;
32                    } else {
33                        debug_assert!(false, "Found out of bounds hebrew month code {k}")
34                    }
35                }
36                MonthNames::LeapLinear((&vec).into())
37            }
38        }
39    }
40}
41
42impl<'a> From<&weekdays::Symbols<'a>> for LinearNames<'a> {
43    fn from(other: &weekdays::Symbols<'a>) -> Self {
44        let vec: alloc::vec::Vec<&str> = other.0.iter().map(|x| &**x).collect();
46        LinearNames {
47            names: (&vec).into(),
48        }
49    }
50}
51
52impl<'a> From<&day_periods::Symbols<'a>> for LinearNames<'a> {
53    fn from(other: &day_periods::Symbols<'a>) -> Self {
54        let vec: alloc::vec::Vec<&str> = match (other.noon.as_ref(), other.midnight.as_ref()) {
56            (Some(noon), Some(midnight)) => vec![&other.am, &other.pm, &noon, &midnight],
57            (Some(noon), None) => vec![&other.am, &other.pm, &noon],
58            (None, Some(midnight)) => vec![&other.am, &other.pm, "", &midnight],
59            (None, None) => vec![&other.am, &other.pm],
60        };
61        LinearNames {
62            names: (&vec).into(),
63        }
64    }
65}