| 1 |
//! Parser for the Android-specific tzdata file. |
| 2 |
|
| 3 |
mod tzdata; |
| 4 |
|
| 5 |
/// Tries to locate the `tzdata` file, parse it, and return the entry for the |
| 6 |
/// requested time zone. |
| 7 |
/// |
| 8 |
/// # Errors |
| 9 |
/// |
| 10 |
/// Returns an [std::io::Error] if the `tzdata` file cannot be found and parsed, or |
| 11 |
/// if it does not contain the requested timezone entry. |
| 12 |
/// |
| 13 |
/// # Example |
| 14 |
/// |
| 15 |
/// ```rust |
| 16 |
/// # use std::error::Error; |
| 17 |
/// # use android_tzdata::find_tz_data; |
| 18 |
/// # |
| 19 |
/// # fn main() -> Result<(), Box<dyn Error>> { |
| 20 |
/// let tz_data = find_tz_data("Europe/Kiev")?; |
| 21 |
/// // Check it's version 2 of the [Time Zone Information Format](https://www.ietf.org/archive/id/draft-murchison-rfc8536bis-02.html). |
| 22 |
/// assert!(tz_data.starts_with(b"TZif2")); |
| 23 |
/// # Ok(()) |
| 24 |
/// # } |
| 25 |
/// ``` |
| 26 |
pub fn find_tz_data(tz_name: impl AsRef<str>) -> Result<Vec<u8>, std::io::Error> { |
| 27 |
let mut file = tzdata::find_file()?; |
| 28 |
tzdata::find_tz_data_in_file(&mut file, tz_name.as_ref()) |
| 29 |
} |