| 1 |
#[cfg(not(miri))] |
| 2 |
use jcore::tz::tzif; |
| 3 |
|
| 4 |
/// A concatenated list of TZif data with a header and an index block. |
| 5 |
/// |
| 6 |
/// This was exactracted from an Android emulator file system via `adb`. |
| 7 |
pub(crate) static ANDROID_CONCATENATED_TZIF: &'static [u8] = |
| 8 |
include_bytes!("testdata/android/tzdata"); |
| 9 |
|
| 10 |
/// A list of all TZif files in our testdata directory. |
| 11 |
/// |
| 12 |
/// Feel free to add more if there are other "interesting" cases. Note that |
| 13 |
/// some tests iterate over this slice to check each entry. So adding a new |
| 14 |
/// test file here might require updating some tests. |
| 15 |
/// |
| 16 |
/// # Revisions |
| 17 |
/// |
| 18 |
/// * 2024-03-27: Initial set pulled from my local copy of `tzdata 2024a`. |
| 19 |
/// * 2024-07-05: Added `UTC`. |
| 20 |
/// * 2024-11-30: Added special Sydney time zone from RHEL8. |
| 21 |
pub(crate) static TZIF_TEST_FILES: &[TzifTestFile] = &[ |
| 22 |
TzifTestFile { |
| 23 |
name: "America/New_York", |
| 24 |
data: include_bytes!("testdata/america-new-york.tzif"), |
| 25 |
}, |
| 26 |
TzifTestFile { |
| 27 |
name: "America/Sitka", |
| 28 |
data: include_bytes!("testdata/america-sitka.tzif"), |
| 29 |
}, |
| 30 |
TzifTestFile { |
| 31 |
name: "America/St_Johns", |
| 32 |
data: include_bytes!("testdata/america-st-johns.tzif"), |
| 33 |
}, |
| 34 |
TzifTestFile { |
| 35 |
name: "right/America/New_York", |
| 36 |
data: include_bytes!("testdata/right-america-new-york.tzif"), |
| 37 |
}, |
| 38 |
TzifTestFile { |
| 39 |
name: "Antarctica/Troll", |
| 40 |
data: include_bytes!("testdata/antarctica-troll.tzif"), |
| 41 |
}, |
| 42 |
TzifTestFile { |
| 43 |
name: "Australia/Tasmania", |
| 44 |
data: include_bytes!("testdata/australia-tasmania.tzif"), |
| 45 |
}, |
| 46 |
TzifTestFile { |
| 47 |
name: "Europe/Dublin", |
| 48 |
data: include_bytes!("testdata/europe-dublin.tzif"), |
| 49 |
}, |
| 50 |
TzifTestFile { |
| 51 |
name: "Pacific/Honolulu", |
| 52 |
data: include_bytes!("testdata/pacific-honolulu.tzif"), |
| 53 |
}, |
| 54 |
// This TZif file comes from a RHEL8 installation[1]. Apparently RHEL |
| 55 |
// added a special first transition far back in the past. It is probably |
| 56 |
// similar in purpose to what Jiff does internally, which is to add a |
| 57 |
// dummy "minimum" transition. We test this case here because RHEL's dummy |
| 58 |
// transition falls outside of Jiff's supported `Timestamp` range, which |
| 59 |
// did result in an error at parse time. But we should be able to parse it, |
| 60 |
// so we test it here. |
| 61 |
// |
| 62 |
// [1]: https://github.com/BurntSushi/jiff/issues/163 |
| 63 |
TzifTestFile { |
| 64 |
name: "Australia/Sydney/RHEL8", |
| 65 |
data: include_bytes!("testdata/australia-sydney-rhel8.tzif"), |
| 66 |
}, |
| 67 |
// I added this to test finding previous time zone transitions in a time |
| 68 |
// zone that had somewhat recently eliminated DST. The bug was that Jiff |
| 69 |
// wasn't reporting *any* previous time zone transitions. |
| 70 |
TzifTestFile { |
| 71 |
name: "America/Sao_Paulo", |
| 72 |
data: include_bytes!("testdata/america-sao-paulo.tzif"), |
| 73 |
}, |
| 74 |
// Another test file I added for a region that eliminated DST and thus |
| 75 |
// has a "final" time zone transition. |
| 76 |
TzifTestFile { |
| 77 |
name: "America/Boa_Vista", |
| 78 |
data: include_bytes!("testdata/america-boa-vista.tzif"), |
| 79 |
}, |
| 80 |
// Just another random test file. |
| 81 |
TzifTestFile { |
| 82 |
name: "Asia/Tokyo", |
| 83 |
data: include_bytes!("testdata/asia-tokyo.tzif"), |
| 84 |
}, |
| 85 |
TzifTestFile { name: "UTC", data: include_bytes!("testdata/utc.tzif") }, |
| 86 |
]; |
| 87 |
|
| 88 |
/// A single TZif datum. |
| 89 |
/// |
| 90 |
/// It contains the name of the time zone and the raw bytes of the |
| 91 |
/// corresponding TZif file. |
| 92 |
#[derive(Clone, Copy)] |
| 93 |
pub(crate) struct TzifTestFile { |
| 94 |
pub(crate) name: &'static str, |
| 95 |
pub(crate) data: &'static [u8], |
| 96 |
} |
| 97 |
|
| 98 |
impl TzifTestFile { |
| 99 |
/// Look up the TZif test file for the given time zone name. |
| 100 |
/// |
| 101 |
/// If one doesn't exist, then this panics and fails the current |
| 102 |
/// test. |
| 103 |
pub(crate) fn get(name: &str) -> TzifTestFile { |
| 104 |
for &tzif_file in TZIF_TEST_FILES { |
| 105 |
if tzif_file.name == name { |
| 106 |
return tzif_file; |
| 107 |
} |
| 108 |
} |
| 109 |
panic!("could not find TZif test file for {name:?}") |
| 110 |
} |
| 111 |
|
| 112 |
/// Parse this test TZif data into a structured representation. |
| 113 |
#[cfg(not(miri))] |
| 114 |
pub(crate) fn parse(self) -> tzif::TimeZone { |
| 115 |
tzif::TimeZone::parse(self.data).unwrap_or_else(|err| { |
| 116 |
panic!("failed to parse TZif test file for {:?}: {err}", self.name) |
| 117 |
}) |
| 118 |
} |
| 119 |
|
| 120 |
/// Parse this test TZif data as if it were V1. |
| 121 |
#[cfg(not(miri))] |
| 122 |
pub(crate) fn parse_v1(self) -> tzif::TimeZone { |
| 123 |
let mut data = self.data.to_vec(); |
| 124 |
data[4] = 0; |
| 125 |
tzif::TimeZone::parse(&data).unwrap_or_else(|err| { |
| 126 |
panic!( |
| 127 |
"failed to parse V1 TZif test file for {:?}: {err}", |
| 128 |
self.name |
| 129 |
) |
| 130 |
}) |
| 131 |
} |
| 132 |
} |