summaryrefslogtreecommitdiffstats
path: root/vendor/android-tzdata/src/lib.rs
blob: b6b0e36cf9eba3586e44e6f169558d5382402e24 (plain)
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
//! Parser for the Android-specific tzdata file.

mod tzdata;

/// Tries to locate the `tzdata` file, parse it, and return the entry for the
/// requested time zone.
///
/// # Errors
///
/// Returns an [std::io::Error] if the `tzdata` file cannot be found and parsed, or
/// if it does not contain the requested timezone entry.
///
/// # Example
///
///  ```rust
/// # use std::error::Error;
/// # use android_tzdata::find_tz_data;
/// #
/// # fn main() -> Result<(), Box<dyn Error>> {
/// let tz_data = find_tz_data("Europe/Kiev")?;
/// // Check it's version 2 of the [Time Zone Information Format](https://www.ietf.org/archive/id/draft-murchison-rfc8536bis-02.html).
/// assert!(tz_data.starts_with(b"TZif2"));
/// #     Ok(())
/// # }
/// ```
pub fn find_tz_data(tz_name: impl AsRef<str>) -> Result<Vec<u8>, std::io::Error> {
    let mut file = tzdata::find_file()?;
    tzdata::find_tz_data_in_file(&mut file, tz_name.as_ref())
}