timezone_abbreviations/lib.rs
1mod abbreviation;
2mod generated;
3
4/// Return one or more timezones for the given timezone abbreviation.
5/// Examples are `GMT` for Greenwich Mean Time or
6/// `PST` for Pacific Standard Time.
7/// Note that there is RFC for these abbreviations, which means that
8/// some of them resolve to multiple different timezones. Hence this
9/// function will return multiple [[`generated::Abbreviation`]] items.
10pub fn timezone(abbr: &str) -> Option<&'static [abbreviation::Abbreviation]> {
11 if let Some(n) = generated::ABBREVIATIONS.get(abbr) {
12 Some(n)
13 } else {
14 None
15 }
16}
17
18/// Return the maximum length that a timezone abbreviation can have.
19/// This can be used to fetch the appropriate number of characters
20/// from a string during parsing in order to identify a possible
21/// timezone entry.
22pub fn max_abbreviation_len() -> usize {
23 generated::MAX_ABBREVIATION_LEN
24}
25
26#[cfg(test)]
27mod tests {
28 use super::timezone;
29 #[test]
30 fn it_works() {
31 assert_eq!(timezone("PST").unwrap().first().unwrap().abbr, "PST");
32 assert_eq!(timezone("GMT").unwrap().first().unwrap().abbr, "GMT");
33 assert_eq!(timezone("XXWhat"), None);
34 }
35}