| 1 | // auto-generated by: jiff-cli generate shared |
| 2 | |
| 3 | use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/}; |
| 4 | |
| 5 | use superrust-analyzer cargo jiff-static 0.2.16 shared/::{ |
| 6 | utilrust-analyzer cargo jiff-static 0.2.16 shared/util/::{ |
| 7 | array_strrust-analyzer cargo jiff-static 0.2.16 shared/util/array_str/::Abbreviationrust-analyzer cargo jiff-static 0.2.16 shared/util/array_str/Abbreviation#, |
| 8 | errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/::{errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#}, |
| 9 | escaperust-analyzer cargo jiff-static 0.2.16 shared/util/escape/::{Byterust-analyzer cargo jiff-static 0.2.16 shared/util/escape/Byte#, Bytesrust-analyzer cargo jiff-static 0.2.16 shared/util/escape/Bytes#}, |
| 10 | itimerust-analyzer cargo jiff-static 0.2.16 shared/util/itime/::{IOffsetrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#, ITimestamprust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#}, |
| 11 | }, |
| 12 | PosixTimeZonerust-analyzer cargo jiff-static 0.2.16 shared/PosixTimeZone#, TzifDateTimerust-analyzer cargo jiff-static 0.2.16 shared/TzifDateTime#, TzifFixedrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#, TzifIndicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#, TzifLocalTimeTyperust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#, |
| 13 | TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned#, TzifTransitionInforust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#, TzifTransitionKindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#, TzifTransitionsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#, |
| 14 | TzifTransitionsOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionsOwned#, |
| 15 | }; |
| 16 | |
| 17 | // These are Jiff min and max timestamp (in seconds) values. |
| 18 | // |
| 19 | // The TZif parser will clamp timestamps to this range. It's |
| 20 | // not ideal, but Jiff can't handle values outside of this range |
| 21 | // and completely refusing to use TZif data with pathological |
| 22 | // timestamps in typically irrelevant transitions is bad juju. |
| 23 | // |
| 24 | // Ref: https://github.com/BurntSushi/jiff/issues/163 |
| 25 | // Ref: https://github.com/BurntSushi/jiff/pull/164 |
| 26 | const TIMESTAMP_MINrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MIN.: i64 = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i64][Neg]neg().377705023201; |
| 27 | const TIMESTAMP_MAXrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MAX.: i64 = 253402207200; |
| 28 | |
| 29 | // Similarly for offsets, although in this case, if we find |
| 30 | // an offset outside of this range, we do actually error. This |
| 31 | // is because it could result in true incorrect datetimes for |
| 32 | // actual transitions. |
| 33 | // |
| 34 | // But our supported offset range is `-25:59:59..=+25:59:59`. |
| 35 | // There's no real time zone with offsets even close to those |
| 36 | // boundaries. |
| 37 | // |
| 38 | // If there is pathological data that we should ignore, then |
| 39 | // we should wait for a real bug report in order to determine |
| 40 | // the right way to ignore/clamp it. |
| 41 | const OFFSET_MINrust-analyzer cargo jiff-static 0.2.16 shared/tzif/OFFSET_MIN.: i32 = -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[i32][Neg]neg().93599; |
| 42 | const OFFSET_MAXrust-analyzer cargo jiff-static 0.2.16 shared/tzif/OFFSET_MAX.: i32 = 93599; |
| 43 | |
| 44 | // When fattening TZif data, this is the year to go up to. |
| 45 | // |
| 46 | // This year was chosen because it's what the "fat" TZif data generated |
| 47 | // by `zic` uses. |
| 48 | const FATTEN_UP_TO_YEARrust-analyzer cargo jiff-static 0.2.16 shared/tzif/FATTEN_UP_TO_YEAR.: i16 = 2038; |
| 49 | |
| 50 | // This is a "sanity" limit on the maximum number of transitions we'll |
| 51 | // add to TZif data when fattening them up. |
| 52 | // |
| 53 | // This is mostly just a defense-in-depth limit to avoid weird cases |
| 54 | // where a pathological POSIX time zone could be defined to create |
| 55 | // many transitions. It's not clear that this is actually possible, |
| 56 | // but I felt a little uneasy doing unbounded work that isn't linearly |
| 57 | // proportional to the input data. So, this limit is put into place for |
| 58 | // reasons of "good sense." |
| 59 | // |
| 60 | // For "normal" cases, there should be at most two transitions per |
| 61 | // year. So this limit permits 300/2=150 years of transition data. |
| 62 | // (Although we won't go above 2036. See above.) |
| 63 | const FATTEN_MAX_TRANSITIONSrust-analyzer cargo jiff-static 0.2.16 shared/tzif/FATTEN_MAX_TRANSITIONS.: usize = 300; |
| 64 | |
| 65 | impl TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned# { |
| 66 | /// Parses the given data as a TZif formatted file. |
| 67 | /// |
| 68 | /// The name given is attached to the `Tzif` value returned, but is |
| 69 | /// otherwise not significant. |
| 70 | /// |
| 71 | /// If the given data is not recognized to be valid TZif, then an error is |
| 72 | /// returned. |
| 73 | /// |
| 74 | /// In general, callers may assume that it is safe to pass arbitrary or |
| 75 | /// even untrusted data to this function and count on it not panicking |
| 76 | /// or using resources that aren't limited to a small constant factor of |
| 77 | /// the size of the data itself. That is, callers can reliably limit the |
| 78 | /// resources used by limiting the size of the data given to this parse |
| 79 | /// function. |
| 80 | pub(craterust-analyzer cargo jiff-static 0.2.16 crate/) fn parserust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse().( |
| 81 | name: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 82 | bytes: &[u8], |
| 83 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned#, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 84 | let original = bytes; |
| 85 | let name = name.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 86 | let (header32, rest) = Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#::parserust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]parse().(4, bytes) |
| 87 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("failed to parse 32-bit header: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 88 | let (mut tzif, rest) = if header32.versionrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#version. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 89 | TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned#::parse32rust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse32().(name, header32, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 90 | } else { |
| 91 | TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned#::parse64rust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse64().(name, header32, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch(). |
| 92 | }; |
| 93 | tzif.fattenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]fatten().(); |
| 94 | // This should come after fattening, because fattening may add new |
| 95 | // transitions and we want to add civil datetimes to those. |
| 96 | tzif.add_civil_datetimes_to_transitionsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add_civil_datetimes_to_transitions().(); |
| 97 | tzif.verify_posix_time_zone_consistencyrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]verify_posix_time_zone_consistency().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 98 | // Compute the checksum using the entire contents of the TZif data. |
| 99 | let tzif_raw_len = (rest.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as usize) |
| 100 | .checked_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_sub().(original.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().() as usize) |
| 101 | .unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); |
| 102 | let tzif_raw_bytes = &original[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#tzif_raw_len]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 103 | tzif.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..checksumrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#checksum. = superrust-analyzer cargo jiff-static 0.2.16 shared/::crc32rust-analyzer cargo jiff-static 0.2.16 shared/crc32/::sumrust-analyzer cargo jiff-static 0.2.16 shared/crc32/sum().(tzif_raw_bytes); |
| 104 | |
| 105 | // Shrink all of our allocs so we don't keep excess capacity around. |
| 106 | tzif.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]shrink_to_fit().(); |
| 107 | tzif.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 108 | tzif.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 109 | tzif.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..civil_startsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_starts..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 110 | tzif.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..civil_endsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_ends..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 111 | tzif.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 112 | |
| 113 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(tzif) |
| 114 | } |
| 115 | |
| 116 | fn parse32rust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse32().<'b>( |
| 117 | name: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 118 | header32: Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 119 | bytes: &'b [u8], |
| 120 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned#, &'b [u8]), Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 121 | let mut tzif = TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned# { |
| 122 | fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed.: TzifFixedrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed# { |
| 123 | namerust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#name., |
| 124 | versionrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#version.: header32.versionrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#version., |
| 125 | // filled in later |
| 126 | checksumrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#checksum.: 0, |
| 127 | designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(), |
| 128 | posix_tzrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#posix_tz.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 129 | }, |
| 130 | typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 131 | transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions.: TzifTransitionsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions# { |
| 132 | timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 133 | civil_startsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_starts.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 134 | civil_endsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_ends.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 135 | infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 136 | }, |
| 137 | }; |
| 138 | let rest = tzif.parse_transitionsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_transitions().(&header32, bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 139 | let rest = tzif.parse_transition_typesrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_transition_types().(&header32, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 140 | let rest = tzif.parse_local_time_typesrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_local_time_types().(&header32, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 141 | let rest = tzif.parse_time_zone_designationsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_time_zone_designations().(&header32, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 142 | let rest = tzif.parse_leap_secondsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_leap_seconds().(&header32, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 143 | let rest = tzif.parse_indicatorsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_indicators().(&header32, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 144 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((tzif, rest)) |
| 145 | } |
| 146 | |
| 147 | fn parse64rust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse64().<'b>( |
| 148 | name: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>, |
| 149 | header32: Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 150 | bytes: &'b [u8], |
| 151 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned#, &'b [u8]), Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 152 | let (_, rest) = try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().( |
| 153 | "V1 TZif data block", |
| 154 | bytes, |
| 155 | header32.data_block_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]data_block_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 156 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 157 | let (header64, rest) = Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#::parserust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]parse().(8, rest) |
| 158 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("failed to parse 64-bit header: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 159 | let mut tzif = TzifOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifOwned# { |
| 160 | fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed.: TzifFixedrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed# { |
| 161 | namerust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#name., |
| 162 | versionrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#version.: header64.versionrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#version., |
| 163 | // filled in later |
| 164 | checksumrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#checksum.: 0, |
| 165 | designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(), |
| 166 | posix_tzrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#posix_tz.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 167 | }, |
| 168 | typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 169 | transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions.: TzifTransitionsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions# { |
| 170 | timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 171 | civil_startsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_starts.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 172 | civil_endsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_ends.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 173 | infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![], |
| 174 | }, |
| 175 | }; |
| 176 | let rest = tzif.parse_transitionsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_transitions().(&header64, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 177 | let rest = tzif.parse_transition_typesrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_transition_types().(&header64, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 178 | let rest = tzif.parse_local_time_typesrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_local_time_types().(&header64, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 179 | let rest = tzif.parse_time_zone_designationsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_time_zone_designations().(&header64, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 180 | let rest = tzif.parse_leap_secondsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_leap_seconds().(&header64, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 181 | let rest = tzif.parse_indicatorsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_indicators().(&header64, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 182 | let rest = tzif.parse_footerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_footer().(&header64, rest)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 183 | // Note that we don't check that the TZif data is fully valid. It is |
| 184 | // possible for it to contain superfluous information. For example, a |
| 185 | // non-zero local time type that is never referenced by a transition. |
| 186 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((tzif, rest)) |
| 187 | } |
| 188 | |
| 189 | fn parse_transitionsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_transitions().<'b>( |
| 190 | &mut self, |
| 191 | header: &Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 192 | bytes: &'b [u8], |
| 193 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'b [u8], Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 194 | let (bytes, rest) = try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().( |
| 195 | "transition times data block", |
| 196 | bytes, |
| 197 | header.transition_times_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]transition_times_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 198 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 199 | let mut it = bytes.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(header.time_sizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#time_size.); |
| 200 | // RFC 8536 says: "If there are no transitions, local time for all |
| 201 | // timestamps is specified by the TZ string in the footer if present |
| 202 | // and nonempty; otherwise, it is specified by time type 0." |
| 203 | // |
| 204 | // RFC 8536 also says: "Local time for timestamps before the first |
| 205 | // transition is specified by the first time type (time type |
| 206 | // 0)." |
| 207 | // |
| 208 | // So if there are no transitions, pushing this dummy one will result |
| 209 | // in the desired behavior even when it's the only transition. |
| 210 | // Similarly, since this is the minimum timestamp value, it will |
| 211 | // trigger for any times before the first transition found in the TZif |
| 212 | // data. |
| 213 | self.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..add_with_type_indexrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`TzifTransitions<Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add_with_type_index().(TIMESTAMP_MINrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MIN., 0); |
| 214 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(chunk) = it.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`ChunksExact<'a, T>`][Iterator]next().() { |
| 215 | let mut timestamp = if header.is_32bitrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]is_32bit().() { |
| 216 | i64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i64][`From<i32>`]from().(from_be_bytes_i32rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_i32().(chunk)) |
| 217 | } else { |
| 218 | from_be_bytes_i64rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_i64().(chunk) |
| 219 | }; |
| 220 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(TIMESTAMP_MINrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MIN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().timestamp && timestamp rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().TIMESTAMP_MAXrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MAX.) { |
| 221 | // We really shouldn't error here just because the Unix |
| 222 | // timestamp is outside what Jiff supports. Since what Jiff |
| 223 | // supports is _somewhat_ arbitrary. But Jiff's supported |
| 224 | // range is good enough for all realistic purposes, so we |
| 225 | // just clamp an out-of-range Unix timestamp to the Jiff |
| 226 | // min or max value. |
| 227 | // |
| 228 | // This can't result in the sorting order being wrong, but |
| 229 | // it can result in a transition that is duplicative with |
| 230 | // the dummy transition we inserted above. This should be |
| 231 | // fine. |
| 232 | let clamped = timestamp.clamprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][Ord]clamp().(TIMESTAMP_MINrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MIN., TIMESTAMP_MAXrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MAX.); |
| 233 | timestamp = clamped; |
| 234 | } |
| 235 | self.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..addrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`TzifTransitions<Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add().(timestamp); |
| 236 | } |
| 237 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(it.remainderrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`ChunksExact<'a, T>`]remainder().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()); |
| 238 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rest) |
| 239 | } |
| 240 | |
| 241 | fn parse_transition_typesrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_transition_types().<'b>( |
| 242 | &mut self, |
| 243 | header: &Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 244 | bytes: &'b [u8], |
| 245 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'b [u8], Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 246 | let (bytes, rest) = try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().( |
| 247 | "transition types data block", |
| 248 | bytes, |
| 249 | header.transition_types_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]transition_types_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 250 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 251 | // We skip the first transition because it is our minimum dummy |
| 252 | // transition. |
| 253 | for (transition_index, &type_index) in (1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#).ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(bytes) { |
| 254 | if usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(type_index) rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().header.tzh_typecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_typecnt. { |
| 255 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 256 | "found transition type index {type_index}, |
| 257 | but there are only {} local time types", |
| 258 | header.tzh_typecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_typecnt., |
| 259 | )); |
| 260 | } |
| 261 | self.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().transition_index]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..type_indexrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#type_index. = type_index; |
| 262 | } |
| 263 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rest) |
| 264 | } |
| 265 | |
| 266 | fn parse_local_time_typesrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_local_time_types().<'b>( |
| 267 | &mut self, |
| 268 | header: &Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 269 | bytes: &'b [u8], |
| 270 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'b [u8], Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 271 | let (bytes, rest) = try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().( |
| 272 | "local time types data block", |
| 273 | bytes, |
| 274 | header.local_time_types_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]local_time_types_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 275 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 276 | let mut it = bytes.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(6); |
| 277 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(chunk) = it.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`ChunksExact<'a, T>`][Iterator]next().() { |
| 278 | let offset = from_be_bytes_i32rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_i32().(&chunk[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 279 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(OFFSET_MINrust-analyzer cargo jiff-static 0.2.16 shared/tzif/OFFSET_MIN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().offset && offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]le().OFFSET_MAXrust-analyzer cargo jiff-static 0.2.16 shared/tzif/OFFSET_MAX.) { |
| 280 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 281 | "found local time type with out-of-bounds offset: {offset}" |
| 282 | )); |
| 283 | } |
| 284 | let is_dst = chunk[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().4]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().1; |
| 285 | let designation = (chunk[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., chunk[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().5]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 286 | self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(TzifLocalTimeTyperust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType# { |
| 287 | offsetrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#offset., |
| 288 | is_dstrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#is_dst., |
| 289 | designationrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#designation., |
| 290 | indicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#indicator.: TzifIndicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#::LocalWallrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#LocalWall#, |
| 291 | }); |
| 292 | } |
| 293 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(it.remainderrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`ChunksExact<'a, T>`]remainder().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()); |
| 294 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rest) |
| 295 | } |
| 296 | |
| 297 | fn parse_time_zone_designationsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_time_zone_designations().<'b>( |
| 298 | &mut self, |
| 299 | header: &Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 300 | bytes: &'b [u8], |
| 301 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'b [u8], Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 302 | let (bytes, rest) = try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().( |
| 303 | "time zone designations data block", |
| 304 | bytes, |
| 305 | header.time_zone_designations_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]time_zone_designations_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 306 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 307 | self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations. = |
| 308 | Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8().(bytes.to_vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]to_vec().()).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| { |
| 309 | errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 310 | "time zone designations are not valid UTF-8: {:?}", |
| 311 | Bytesrust-analyzer cargo jiff-static 0.2.16 shared/util/escape/Bytes#(bytes), |
| 312 | ) |
| 313 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 314 | // Holy hell, this is brutal. The boundary conditions are crazy. |
| 315 | for (i, typ) in self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 316 | let start = usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(typ.designationrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#designation..0); |
| 317 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(suffix) = self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]get().(start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#) else { |
| 318 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 319 | "local time type {i} has designation index of {start}, \ |
| 320 | but cannot be more than {}", |
| 321 | self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(), |
| 322 | )); |
| 323 | }; |
| 324 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(len) = suffix.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('\x00') else { |
| 325 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 326 | "local time type {i} has designation index of {start}, \ |
| 327 | but could not find NUL terminator after it in \ |
| 328 | designations: {:?}", |
| 329 | self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations., |
| 330 | )); |
| 331 | }; |
| 332 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(end) = start.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(len) else { |
| 333 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 334 | "local time type {i} has designation index of {start}, \ |
| 335 | but its length {len} is too big", |
| 336 | )); |
| 337 | }; |
| 338 | typ.designationrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#designation..1 = u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u8][`TryFrom<usize>`]try_from().(end).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| { |
| 339 | errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 340 | "local time type {i} has designation range of \ |
| 341 | {start}..{end}, but end is too big", |
| 342 | ) |
| 343 | })?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 344 | } |
| 345 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rest) |
| 346 | } |
| 347 | |
| 348 | /// This parses the leap second corrections in the TZif data. |
| 349 | /// |
| 350 | /// Note that we only parse and verify them. We don't actually use them. |
| 351 | /// Jiff effectively ignores leap seconds. |
| 352 | fn parse_leap_secondsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_leap_seconds().<'b>( |
| 353 | &mut self, |
| 354 | header: &Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 355 | bytes: &'b [u8], |
| 356 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'b [u8], Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 357 | let (bytes, rest) = try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().( |
| 358 | "leap seconds data block", |
| 359 | bytes, |
| 360 | header.leap_second_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]leap_second_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 361 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 362 | let chunk_len = header |
| 363 | .time_sizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#time_size. |
| 364 | .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(4) |
| 365 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("time_size plus 4 fits in usize"); |
| 366 | let mut it = bytes.chunks_exactrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]chunks_exact().(chunk_len); |
| 367 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(chunk) = it.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`ChunksExact<'a, T>`][Iterator]next().() { |
| 368 | let (occur_bytes, _corr_bytes) = chunk.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(header.time_sizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#time_size.); |
| 369 | let occur = if header.is_32bitrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]is_32bit().() { |
| 370 | i64::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[i64][`From<i32>`]from().(from_be_bytes_i32rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_i32().(occur_bytes)) |
| 371 | } else { |
| 372 | from_be_bytes_i64rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_i64().(occur_bytes) |
| 373 | }; |
| 374 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().(TIMESTAMP_MINrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MIN. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().occur && occur rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i64][`PartialOrd<Self>`]le().TIMESTAMP_MAXrust-analyzer cargo jiff-static 0.2.16 shared/tzif/TIMESTAMP_MAX.) {} |
| 375 | } |
| 376 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(it.remainderrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`ChunksExact<'a, T>`]remainder().().is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()); |
| 377 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rest) |
| 378 | } |
| 379 | |
| 380 | fn parse_indicatorsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_indicators().<'b>( |
| 381 | &mut self, |
| 382 | header: &Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 383 | bytes: &'b [u8], |
| 384 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'b [u8], Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 385 | let (std_wall_bytes, rest) = try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().( |
| 386 | "standard/wall indicators data block", |
| 387 | bytes, |
| 388 | header.standard_wall_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]standard_wall_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 389 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 390 | let (ut_local_bytes, rest) = try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().( |
| 391 | "UT/local indicators data block", |
| 392 | rest, |
| 393 | header.ut_local_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]ut_local_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 394 | )?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 395 | if std_wall_bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ut_local_bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 396 | // This is a weird case, but technically possible only if all |
| 397 | // UT/local indicators are 0. If any are 1, then it's an error, |
| 398 | // because it would require the corresponding std/wall indicator |
| 399 | // to be 1 too. Which it can't be, because there aren't any. So |
| 400 | // we just check that they're all zeros. |
| 401 | for (i, &byte) in ut_local_bytes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 402 | if byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().0 { |
| 403 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 404 | "found UT/local indicator '{byte}' for local time \ |
| 405 | type {i}, but it must be 0 since all std/wall \ |
| 406 | indicators are 0", |
| 407 | )); |
| 408 | } |
| 409 | } |
| 410 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().std_wall_bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() && ut_local_bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 411 | for (i, &byte) in std_wall_bytes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 412 | // Indexing is OK because Header guarantees that the number of |
| 413 | // indicators is 0 or equal to the number of types. |
| 414 | self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..indicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#indicator. = if byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().0 { |
| 415 | TzifIndicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#::LocalWallrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#LocalWall# |
| 416 | } else if byte rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().1 { |
| 417 | TzifIndicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#::LocalStandardrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#LocalStandard# |
| 418 | } else { |
| 419 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 420 | "found invalid std/wall indicator '{byte}' for \ |
| 421 | local time type {i}, it must be 0 or 1", |
| 422 | )); |
| 423 | }; |
| 424 | } |
| 425 | } else if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().std_wall_bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() && !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().ut_local_bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 426 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(std_wall_bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), ut_local_bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()); |
| 427 | let it = std_wall_bytes.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(ut_local_bytes); |
| 428 | for (i, (&stdwall, &utlocal)) in it.enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 429 | // Indexing is OK because Header guarantees that the number of |
| 430 | // indicators is 0 or equal to the number of types. |
| 431 | self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..indicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#indicator. = match (stdwall, utlocal) { |
| 432 | (0, 0) => TzifIndicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#::LocalWallrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#LocalWall#, |
| 433 | (1, 0) => TzifIndicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#::LocalStandardrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#LocalStandard#, |
| 434 | (1, 1) => TzifIndicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#::UTStandardrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#UTStandard#, |
| 435 | (0, 1) => { |
| 436 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 437 | "found illegal ut-wall combination for \ |
| 438 | local time type {i}, only local-wall, \ |
| 439 | local-standard and ut-standard are allowed", |
| 440 | )) |
| 441 | } |
| 442 | _ => { |
| 443 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 444 | "found illegal std/wall or ut/local value for \ |
| 445 | local time type {i}, each must be 0 or 1", |
| 446 | )) |
| 447 | } |
| 448 | }; |
| 449 | } |
| 450 | } else { |
| 451 | // If they're both empty then we don't need to do anything. Every |
| 452 | // local time type record already has the correct default for this |
| 453 | // case set. |
| 454 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(std_wall_bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()); |
| 455 | debug_assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert!!(ut_local_bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().()); |
| 456 | } |
| 457 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(rest) |
| 458 | } |
| 459 | |
| 460 | fn parse_footerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]parse_footer().<'b>( |
| 461 | &mut self, |
| 462 | _header: &Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, |
| 463 | bytes: &'b [u8], |
| 464 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<&'b [u8], Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 465 | if bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 466 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 467 | "invalid V2+ TZif footer, expected \\n, \ |
| 468 | but found unexpected end of data", |
| 469 | )); |
| 470 | } |
| 471 | if bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]ne().b'\n' { |
| 472 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 473 | "invalid V2+ TZif footer, expected {:?}, but found {:?}", |
| 474 | Byterust-analyzer cargo jiff-static 0.2.16 shared/util/escape/Byte#(b'\n'), |
| 475 | Byterust-analyzer cargo jiff-static 0.2.16 shared/util/escape/Byte#(bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().), |
| 476 | )); |
| 477 | } |
| 478 | let bytes = &bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 479 | // Only scan up to 1KB for a NUL terminator in case we somehow got |
| 480 | // passed a huge block of bytes. |
| 481 | let toscan = &bytes[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeTo#bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().().minrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#min().(1024)]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 482 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(nlat) = toscan.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().positionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/impl#[`Iter<'a, T>`][Iterator]position().(|&b| b rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'\n') else { |
| 483 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 484 | "invalid V2 TZif footer, could not find {:?} \ |
| 485 | terminator in: {:?}", |
| 486 | Byterust-analyzer cargo jiff-static 0.2.16 shared/util/escape/Byte#(b'\n'), |
| 487 | Bytesrust-analyzer cargo jiff-static 0.2.16 shared/util/escape/Bytes#(toscan), |
| 488 | )); |
| 489 | }; |
| 490 | let (bytes, rest) = bytes.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(nlat); |
| 491 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().bytes.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]is_empty().() { |
| 492 | // We could in theory limit TZ strings to their strict POSIX |
| 493 | // definition here for TZif V2, but I don't think there is any |
| 494 | // harm in allowing the extensions in V2 formatted TZif data. Note |
| 495 | // that the GNU tooling allow it via the `TZ` environment variable |
| 496 | // even though POSIX doesn't specify it. This all seems okay to me |
| 497 | // because the V3+ extension is a strict superset of functionality. |
| 498 | let posix_tz = |
| 499 | PosixTimeZonerust-analyzer cargo jiff-static 0.2.16 shared/PosixTimeZone#::parserust-analyzer cargo jiff-static 0.2.16 shared/posix/impl#[`PosixTimeZone<super::util::array_str::ArrayStr<ABBREVIATION_MAX>>`]parse().(bytes).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("{e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 500 | self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..posix_tzrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#posix_tz. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(posix_tz); |
| 501 | } |
| 502 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(&rest[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().) |
| 503 | } |
| 504 | |
| 505 | /// Validates that the POSIX TZ string we parsed (if one exists) is |
| 506 | /// consistent with the last transition in this time zone. This is |
| 507 | /// required by RFC 8536. |
| 508 | /// |
| 509 | /// RFC 8536 says, "If the string is nonempty and one or more |
| 510 | /// transitions appear in the version 2+ data, the string MUST be |
| 511 | /// consistent with the last version 2+ transition." |
| 512 | fn verify_posix_time_zone_consistencyrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]verify_posix_time_zone_consistency().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(), Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 513 | // We need to be a little careful, since we always have at least one |
| 514 | // transition (accounting for the dummy `Timestamp::MIN` transition). |
| 515 | // So if we only have 1 transition and a POSIX TZ string, then we |
| 516 | // should not validate it since it's equivalent to the case of 0 |
| 517 | // transitions and a POSIX TZ string. |
| 518 | if self.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().1 { |
| 519 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 520 | } |
| 521 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(ref tz) = self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..posix_tzrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#posix_tz. else { |
| 522 | return Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()); |
| 523 | }; |
| 524 | let last = self |
| 525 | .transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions. |
| 526 | .timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps. |
| 527 | .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().() |
| 528 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("last transition timestamp"); |
| 529 | let type_index = self |
| 530 | .transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions. |
| 531 | .infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos. |
| 532 | .lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().() |
| 533 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("last transition info") |
| 534 | .type_indexrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#type_index.; |
| 535 | let typ = &self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(type_index)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 536 | let (ioff, abbrev, is_dst) = |
| 537 | tz.to_offset_inforust-analyzer cargo jiff-static 0.2.16 shared/posix/impl#[`PosixTimeZone<ABBREV>`]to_offset_info().(ITimestamprust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#::from_secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/impl#[ITimestamp]from_second().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().last)); |
| 538 | if ioff.secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#second. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]ne().typ.offsetrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#offset. { |
| 539 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 540 | "expected last transition to have DST offset \ |
| 541 | of {expected_offset}, but got {got_offset} \ |
| 542 | according to POSIX TZ string {tz}", |
| 543 | expected_offset = typ.offsetrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#offset., |
| 544 | got_offset = ioff.secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#second., |
| 545 | tz = tz, |
| 546 | )); |
| 547 | } |
| 548 | if is_dst rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]ne().typ.is_dstrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#is_dst. { |
| 549 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 550 | "expected last transition to have is_dst={expected_dst}, \ |
| 551 | but got is_dst={got_dst} according to POSIX TZ \ |
| 552 | string {tz}", |
| 553 | expected_dst = typ.is_dstrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#is_dst., |
| 554 | got_dst = is_dst, |
| 555 | tz = tz, |
| 556 | )); |
| 557 | } |
| 558 | if abbrev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().self.designationrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]designation().(&typ) { |
| 559 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 560 | "expected last transition to have \ |
| 561 | designation={expected_abbrev}, \ |
| 562 | but got designation={got_abbrev} according to POSIX TZ \ |
| 563 | string {tz}", |
| 564 | expected_abbrev = self.designationrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]designation().(&typ), |
| 565 | got_abbrev = abbrev, |
| 566 | tz = tz, |
| 567 | )); |
| 568 | } |
| 569 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 570 | } |
| 571 | |
| 572 | /// Add civil datetimes to our transitions. |
| 573 | /// |
| 574 | /// This isn't strictly necessary, but it speeds up time zone lookups when |
| 575 | /// the input is a civil datetime. It lets us do comparisons directly on |
| 576 | /// the civil datetime as given, instead of needing to convert the civil |
| 577 | /// datetime given to a timestamp first. (Even if we didn't do this, I |
| 578 | /// believe we'd still need at least one additional timestamp that is |
| 579 | /// offset, because TZ lookups for a civil datetime are done in local time, |
| 580 | /// and the timestamps in TZif data are, of course, all in UTC.) |
| 581 | fn add_civil_datetimes_to_transitionsrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add_civil_datetimes_to_transitions().(&mut self) { |
| 582 | fn to_datetimerust-analyzer cargo jiff-static 0.2.16 shared/tzif/to_datetime().(timestamp: i64, offset: i32) -> TzifDateTimerust-analyzer cargo jiff-static 0.2.16 shared/TzifDateTime# { |
| 583 | use craterust-analyzer cargo jiff-static 0.2.16 crate/::sharedrust-analyzer cargo jiff-static 0.2.16 shared/::utilrust-analyzer cargo jiff-static 0.2.16 shared/util/::itimerust-analyzer cargo jiff-static 0.2.16 shared/util/itime/::{IOffsetrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#, ITimestamprust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#}; |
| 584 | let its = ITimestamprust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp# { secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#second.: timestamp, nanosecondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#nanosecond.: 0 }; |
| 585 | let ioff = IOffsetrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset# { secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#second.: offset }; |
| 586 | let dt = its.to_datetimerust-analyzer cargo jiff-static 0.2.16 shared/util/itime/impl#[ITimestamp]to_datetime().(ioff); |
| 587 | TzifDateTimerust-analyzer cargo jiff-static 0.2.16 shared/TzifDateTime#::newrust-analyzer cargo jiff-static 0.2.16 shared/impl#[TzifDateTime]new().( |
| 588 | dt.daterust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDateTime#date..yearrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDate#year., |
| 589 | dt.daterust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDateTime#date..monthrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDate#month., |
| 590 | dt.daterust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDateTime#date..dayrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDate#day., |
| 591 | dt.timerust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDateTime#time..hourrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITime#hour., |
| 592 | dt.timerust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDateTime#time..minuterust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITime#minute., |
| 593 | dt.timerust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDateTime#time..secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITime#second., |
| 594 | ) |
| 595 | } |
| 596 | |
| 597 | let trans = &mut self.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions.; |
| 598 | for i in 0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#trans.timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 599 | let timestamp = trans.timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().; |
| 600 | let offset = { |
| 601 | let type_index = trans.infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..type_indexrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#type_index.; |
| 602 | self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(type_index)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..offsetrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#offset. |
| 603 | }; |
| 604 | let prev_offset = { |
| 605 | let type_index = trans.infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i.saturating_subrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]saturating_sub().(1)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..type_indexrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#type_index.; |
| 606 | self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(type_index)]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..offsetrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#offset. |
| 607 | }; |
| 608 | |
| 609 | if prev_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().offset { |
| 610 | // Equivalent offsets means there can never be any ambiguity. |
| 611 | let start = to_datetimerust-analyzer cargo jiff-static 0.2.16 shared/tzif/to_datetime().(timestamp, prev_offset); |
| 612 | trans.infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..kindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#kind. = TzifTransitionKindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#::Unambiguousrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#Unambiguous#; |
| 613 | trans.civil_startsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_starts.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = start; |
| 614 | } else if prev_offset rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]lt().offset { |
| 615 | // When the offset of the previous transition is less, that |
| 616 | // means there is some non-zero amount of time that is |
| 617 | // "skipped" when moving to the next transition. Thus, we have |
| 618 | // a gap. The start of the gap is the offset which gets us the |
| 619 | // earliest time, i.e., the smaller of the two offsets. |
| 620 | trans.infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..kindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#kind. = TzifTransitionKindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#::Gaprust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#Gap#; |
| 621 | trans.civil_startsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_starts.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = to_datetimerust-analyzer cargo jiff-static 0.2.16 shared/tzif/to_datetime().(timestamp, prev_offset); |
| 622 | trans.civil_endsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_ends.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = to_datetimerust-analyzer cargo jiff-static 0.2.16 shared/tzif/to_datetime().(timestamp, offset); |
| 623 | } else { |
| 624 | // When the offset of the previous transition is greater, that |
| 625 | // means there is some non-zero amount of time that will be |
| 626 | // replayed on a wall clock in this time zone. Thus, we have |
| 627 | // a fold. The start of the gold is the offset which gets us |
| 628 | // the earliest time, i.e., the smaller of the two offsets. |
| 629 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(prev_offset >rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialOrd<Self>`]gt(). offset); |
| 630 | trans.infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..kindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#kind. = TzifTransitionKindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#::Foldrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#Fold#; |
| 631 | trans.civil_startsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_starts.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = to_datetimerust-analyzer cargo jiff-static 0.2.16 shared/tzif/to_datetime().(timestamp, offset); |
| 632 | trans.civil_endsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_ends.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). = to_datetimerust-analyzer cargo jiff-static 0.2.16 shared/tzif/to_datetime().(timestamp, prev_offset); |
| 633 | } |
| 634 | } |
| 635 | } |
| 636 | |
| 637 | /// Fatten up this TZif data with additional transitions. |
| 638 | /// |
| 639 | /// These additional transitions often make time zone lookups faster, and |
| 640 | /// they smooth out the performance difference between using "slim" and |
| 641 | /// "fat" tzdbs. |
| 642 | fn fattenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]fatten().(&mut self) { |
| 643 | // Note that this is a crate feature for *both* `jiff` and |
| 644 | // `jiff-static`. |
| 645 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(feature = "tz-fat") { |
| 646 | return; |
| 647 | } |
| 648 | let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(posix_tz) = self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..posix_tzrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#posix_tz..clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Clone]clone().() else { return }; |
| 649 | let last = |
| 650 | self.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps..lastrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]last().().expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("last transition"); |
| 651 | let mut i = 0; |
| 652 | let mut prev = ITimestamprust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#::from_secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/impl#[ITimestamp]from_second().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().last); |
| 653 | loop { |
| 654 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().FATTEN_MAX_TRANSITIONSrust-analyzer cargo jiff-static 0.2.16 shared/tzif/FATTEN_MAX_TRANSITIONS. { |
| 655 | return; |
| 656 | } |
| 657 | i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 658 | prev = match self.add_transitionrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add_transition().(&posix_tz, prev) { |
| 659 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => break, |
| 660 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(next) => next, |
| 661 | }; |
| 662 | } |
| 663 | } |
| 664 | |
| 665 | /// If there's a transition strictly after the given timestamp for the |
| 666 | /// given POSIX time zone, then add it to this TZif data. |
| 667 | fn add_transitionrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add_transition().( |
| 668 | &mut self, |
| 669 | posix_tz: &PosixTimeZonerust-analyzer cargo jiff-static 0.2.16 shared/PosixTimeZone#<Abbreviationrust-analyzer cargo jiff-static 0.2.16 shared/util/array_str/Abbreviation#>, |
| 670 | prev: ITimestamprust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#, |
| 671 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<ITimestamprust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#> { |
| 672 | let (its, ioff, abbrev, is_dst) = posix_tz.next_transitionrust-analyzer cargo jiff-static 0.2.16 shared/posix/impl#[`PosixTimeZone<ABBREV>`]next_transition().(prev)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 673 | if its.to_datetimerust-analyzer cargo jiff-static 0.2.16 shared/util/itime/impl#[ITimestamp]to_datetime().(IOffsetrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#::UTCrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/impl#[IOffset]UTC.).daterust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDateTime#date..yearrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IDate#year. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i16][`PartialOrd<Self>`]ge().FATTEN_UP_TO_YEARrust-analyzer cargo jiff-static 0.2.16 shared/tzif/FATTEN_UP_TO_YEAR. { |
| 674 | return Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#; |
| 675 | } |
| 676 | let type_index = |
| 677 | self.find_or_create_local_time_typerust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]find_or_create_local_time_type().(ioff, abbrev, is_dst)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 678 | self.transitionsrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#transitions..add_with_type_indexrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`TzifTransitions<Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add_with_type_index().(its.secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/ITimestamp#second., type_index); |
| 679 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(its) |
| 680 | } |
| 681 | |
| 682 | /// Look for a local time type matching the data given. |
| 683 | /// |
| 684 | /// If one could not be found, then one is created and its index is |
| 685 | /// returned. |
| 686 | /// |
| 687 | /// If one could not be found and one could not be created (e.g., the index |
| 688 | /// would overflow `u8`), then `None` is returned. |
| 689 | fn find_or_create_local_time_typerust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]find_or_create_local_time_type().( |
| 690 | &mut self, |
| 691 | offset: IOffsetrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#, |
| 692 | abbrev: &str, |
| 693 | is_dst: bool, |
| 694 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u8> { |
| 695 | for (i, typ) in self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 696 | if offset.secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#second. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[i32][`PartialEq<Self>`]eq().typ.offsetrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#offset. |
| 697 | && abbrev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().self.designationrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]designation().(typ) |
| 698 | && is_dst rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[bool][`PartialEq<Self>`]eq().typ.is_dstrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#is_dst. |
| 699 | { |
| 700 | return u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u8][`TryFrom<usize>`]try_from().(i).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().(); |
| 701 | } |
| 702 | } |
| 703 | let i = u8::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[u8][`TryFrom<usize>`]try_from().(self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 704 | let designation = self.find_or_create_designationrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]find_or_create_designation().(abbrev)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().; |
| 705 | self.typesrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#types..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(TzifLocalTimeTyperust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType# { |
| 706 | offsetrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#offset.: offset.secondrust-analyzer cargo jiff-static 0.2.16 shared/util/itime/IOffset#second., |
| 707 | is_dstrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#is_dst., |
| 708 | designationrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#designation., |
| 709 | // Not really clear if this is correct, but Jiff |
| 710 | // ignores this anyway, so ¯\_(ツ)_/¯. |
| 711 | indicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#indicator.: TzifIndicatorrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#::LocalWallrust-analyzer cargo jiff-static 0.2.16 shared/TzifIndicator#LocalWall#, |
| 712 | }); |
| 713 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(i) |
| 714 | } |
| 715 | |
| 716 | /// Look for a designation (i.e., time zone abbreviation) matching the data |
| 717 | /// given, and return its range into `self.fixed.designations`. |
| 718 | /// |
| 719 | /// If one could not be found, then one is created and its range is |
| 720 | /// returned. |
| 721 | /// |
| 722 | /// If one could not be found and one could not be created (e.g., the range |
| 723 | /// would overflow `u8`), then `None` is returned. |
| 724 | fn find_or_create_designationrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]find_or_create_designation().( |
| 725 | &mut self, |
| 726 | needle: &str, |
| 727 | ) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(u8, u8)> { |
| 728 | let mut start = 0; |
| 729 | while let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(offset) = self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index()..findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().('\0') { |
| 730 | let end = start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().offset; |
| 731 | let abbrev = &self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().; |
| 732 | if needle rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().abbrev { |
| 733 | return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((start.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()., end.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().)); |
| 734 | } |
| 735 | start = end rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1; |
| 736 | } |
| 737 | |
| 738 | // Now we need to add a new abbreviation. This |
| 739 | // should generally only happen for malformed TZif |
| 740 | // data. i.e., TZif data with a POSIX time zone that |
| 741 | // contains an TZ abbreviation that isn't found in |
| 742 | // the TZif's designation list. |
| 743 | // |
| 744 | // And since we're guarding against malformed data, |
| 745 | // the designation list might not end with NUL. If |
| 746 | // not, add one. |
| 747 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\0') { |
| 748 | self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\0'); |
| 749 | } |
| 750 | let start = self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(); |
| 751 | self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(needle); |
| 752 | self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('\0'); |
| 753 | let end = self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().(); |
| 754 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((start.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()., end.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]ok().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().)) |
| 755 | } |
| 756 | |
| 757 | fn designationrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`super::Tzif<String, super::util::array_str::ArrayStr<ABBREVIATION_MAX>, Vec<TzifLocalTimeType>, Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]designation().(&self, typ: &TzifLocalTimeTyperust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#) -> &str { |
| 758 | let range = |
| 759 | usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(typ.designationrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#designation..0)..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#usize::fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/impl#[usize][`From<u8>`]from().(typ.designationrust-analyzer cargo jiff-static 0.2.16 shared/TzifLocalTimeType#designation..1); |
| 760 | // OK because we verify that the designation range on every local |
| 761 | // time type is a valid range into `self.designations`. |
| 762 | &self.fixedrust-analyzer cargo jiff-static 0.2.16 shared/Tzif#fixed..designationsrust-analyzer cargo jiff-static 0.2.16 shared/TzifFixed#designations.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().range]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index(). |
| 763 | } |
| 764 | } |
| 765 | |
| 766 | impl TzifTransitionsOwnedrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionsOwned# { |
| 767 | /// Add a single transition with the given timestamp. |
| 768 | /// |
| 769 | /// This also fills in the other columns (civil starts, civil ends and |
| 770 | /// infos) with sensible default values. It is expected that callers will |
| 771 | /// later fill them in. |
| 772 | fn addrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`TzifTransitions<Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add().(&mut self, timestamp: i64) { |
| 773 | self.add_with_type_indexrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`TzifTransitions<Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add_with_type_index().(timestamp, 0); |
| 774 | } |
| 775 | |
| 776 | /// Like `TzifTransitionsOwned::add`, but let's the caller provide a type |
| 777 | /// index if it is known. |
| 778 | fn add_with_type_indexrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[`TzifTransitions<Vec<i64>, Vec<TzifDateTime>, Vec<TzifDateTime>, Vec<TzifTransitionInfo>>`]add_with_type_index().(&mut self, timestamp: i64, type_index: u8) { |
| 779 | self.timestampsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#timestamps..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(timestamp); |
| 780 | self.civil_startsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_starts..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(TzifDateTimerust-analyzer cargo jiff-static 0.2.16 shared/TzifDateTime#::ZEROrust-analyzer cargo jiff-static 0.2.16 shared/impl#[TzifDateTime]ZERO.); |
| 781 | self.civil_endsrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#civil_ends..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(TzifDateTimerust-analyzer cargo jiff-static 0.2.16 shared/TzifDateTime#::ZEROrust-analyzer cargo jiff-static 0.2.16 shared/impl#[TzifDateTime]ZERO.); |
| 782 | self.infosrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitions#infos..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(TzifTransitionInforust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo# { |
| 783 | type_indexrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#type_index., |
| 784 | kindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionInfo#kind.: TzifTransitionKindrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#::Unambiguousrust-analyzer cargo jiff-static 0.2.16 shared/TzifTransitionKind#Unambiguous#, |
| 785 | }); |
| 786 | } |
| 787 | } |
| 788 | |
| 789 | /// The header for a TZif formatted file. |
| 790 | /// |
| 791 | /// V2+ TZif format have two headers: one for V1 data, and then a second |
| 792 | /// following the V1 data block that describes another data block which uses |
| 793 | /// 64-bit timestamps. The two headers both have the same format and both |
| 794 | /// use 32-bit big-endian encoded integers. |
| 795 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 796 | struct Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header# { |
| 797 | /// The size of the timestamps encoded in the data block. |
| 798 | /// |
| 799 | /// This is guaranteed to be either 4 (for V1) or 8 (for the 64-bit header |
| 800 | /// block in V2+). |
| 801 | time_sizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#time_size.: usize, |
| 802 | /// The file format version. |
| 803 | /// |
| 804 | /// Note that this is either a NUL byte (for version 1), or an ASCII byte |
| 805 | /// corresponding to the version number. That is, `0x32` for `2`, `0x33` |
| 806 | /// for `3` or `0x34` for `4`. Note also that just because zoneinfo might |
| 807 | /// have been recently generated does not mean it uses the latest format |
| 808 | /// version. It seems like newer versions are only compiled by `zic` when |
| 809 | /// they are needed. For example, `America/New_York` on my system (as of |
| 810 | /// `2024-03-25`) has version `0x32`, but `Asia/Jerusalem` has version |
| 811 | /// `0x33`. |
| 812 | versionrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#version.: u8, |
| 813 | /// Number of UT/local indicators stored in the file. |
| 814 | /// |
| 815 | /// This is checked to be either equal to `0` or equal to `tzh_typecnt`. |
| 816 | tzh_ttisutcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_ttisutcnt.: usize, |
| 817 | /// The number of standard/wall indicators stored in the file. |
| 818 | /// |
| 819 | /// This is checked to be either equal to `0` or equal to `tzh_typecnt`. |
| 820 | tzh_ttisstdcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_ttisstdcnt.: usize, |
| 821 | /// The number of leap seconds for which data entries are stored in the |
| 822 | /// file. |
| 823 | tzh_leapcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_leapcnt.: usize, |
| 824 | /// The number of transition times for which data entries are stored in |
| 825 | /// the file. |
| 826 | tzh_timecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_timecnt.: usize, |
| 827 | /// The number of local time types for which data entries are stored in the |
| 828 | /// file. |
| 829 | /// |
| 830 | /// This is checked to be at least `1`. |
| 831 | tzh_typecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_typecnt.: usize, |
| 832 | /// The number of bytes of time zone abbreviation strings stored in the |
| 833 | /// file. |
| 834 | /// |
| 835 | /// This is checked to be at least `1`. |
| 836 | tzh_charcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_charcnt.: usize, |
| 837 | } |
| 838 | |
| 839 | impl Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header# { |
| 840 | /// Parse the header record from the given bytes. |
| 841 | /// |
| 842 | /// Upon success, return the header and all bytes after the header. |
| 843 | /// |
| 844 | /// The given `time_size` must be 4 or 8, corresponding to either the |
| 845 | /// V1 header block or the V2+ header block, respectively. |
| 846 | fn parserust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]parse().( |
| 847 | time_size: usize, |
| 848 | bytes: &[u8], |
| 849 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#, &[u8]), Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 850 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(time_size == 4 || time_size == 8, "time size must be 4 or 8"); |
| 851 | if bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().44 { |
| 852 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("invalid header: too short")); |
| 853 | } |
| 854 | let (magic, rest) = bytes.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(4); |
| 855 | if magic rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]ne().b"TZif" { |
| 856 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("invalid header: magic bytes mismatch")); |
| 857 | } |
| 858 | let (version, rest) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(1); |
| 859 | let (_reserved, rest) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(15); |
| 860 | |
| 861 | let (tzh_ttisutcnt_bytes, rest) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(4); |
| 862 | let (tzh_ttisstdcnt_bytes, rest) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(4); |
| 863 | let (tzh_leapcnt_bytes, rest) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(4); |
| 864 | let (tzh_timecnt_bytes, rest) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(4); |
| 865 | let (tzh_typecnt_bytes, rest) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(4); |
| 866 | let (tzh_charcnt_bytes, rest) = rest.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(4); |
| 867 | |
| 868 | let tzh_ttisutcnt = from_be_bytes_u32_to_usizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32_to_usize().(tzh_ttisutcnt_bytes) |
| 869 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("failed to parse tzh_ttisutcnt: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 870 | let tzh_ttisstdcnt = from_be_bytes_u32_to_usizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32_to_usize().(tzh_ttisstdcnt_bytes) |
| 871 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("failed to parse tzh_ttisstdcnt: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 872 | let tzh_leapcnt = from_be_bytes_u32_to_usizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32_to_usize().(tzh_leapcnt_bytes) |
| 873 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("failed to parse tzh_leapcnt: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 874 | let tzh_timecnt = from_be_bytes_u32_to_usizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32_to_usize().(tzh_timecnt_bytes) |
| 875 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("failed to parse tzh_timecnt: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 876 | let tzh_typecnt = from_be_bytes_u32_to_usizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32_to_usize().(tzh_typecnt_bytes) |
| 877 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("failed to parse tzh_typecnt: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 878 | let tzh_charcnt = from_be_bytes_u32_to_usizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32_to_usize().(tzh_charcnt_bytes) |
| 879 | .map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|e| errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("failed to parse tzh_charcnt: {e}"))?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 880 | |
| 881 | if tzh_ttisutcnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 && tzh_ttisutcnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().tzh_typecnt { |
| 882 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 883 | "expected tzh_ttisutcnt={tzh_ttisutcnt} to be zero \ |
| 884 | or equal to tzh_typecnt={tzh_typecnt}", |
| 885 | )); |
| 886 | } |
| 887 | if tzh_ttisstdcnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().0 && tzh_ttisstdcnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]ne().tzh_typecnt { |
| 888 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 889 | "expected tzh_ttisstdcnt={tzh_ttisstdcnt} to be zero \ |
| 890 | or equal to tzh_typecnt={tzh_typecnt}", |
| 891 | )); |
| 892 | } |
| 893 | if tzh_typecnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().1 { |
| 894 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 895 | "expected tzh_typecnt={tzh_typecnt} to be at least 1", |
| 896 | )); |
| 897 | } |
| 898 | if tzh_charcnt rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]lt().1 { |
| 899 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 900 | "expected tzh_charcnt={tzh_charcnt} to be at least 1", |
| 901 | )); |
| 902 | } |
| 903 | |
| 904 | let header = Headerrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header# { |
| 905 | time_sizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#time_size., |
| 906 | versionrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#version.: version[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().0]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()., |
| 907 | tzh_ttisutcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_ttisutcnt., |
| 908 | tzh_ttisstdcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_ttisstdcnt., |
| 909 | tzh_leapcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_leapcnt., |
| 910 | tzh_timecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_timecnt., |
| 911 | tzh_typecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_typecnt., |
| 912 | tzh_charcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_charcnt., |
| 913 | }; |
| 914 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((header, rest)) |
| 915 | } |
| 916 | |
| 917 | /// Returns true if this header is for a 32-bit data block. |
| 918 | /// |
| 919 | /// When false, it is guaranteed that this header is for a 64-bit data |
| 920 | /// block. |
| 921 | fn is_32bitrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]is_32bit().(&self) -> bool { |
| 922 | self.time_sizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#time_size. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().4 |
| 923 | } |
| 924 | |
| 925 | /// Returns the size of the data block, in bytes, for this header. |
| 926 | /// |
| 927 | /// This returns an error if the arithmetic required to compute the |
| 928 | /// length would overflow. |
| 929 | /// |
| 930 | /// This is useful for, e.g., skipping over the 32-bit V1 data block in |
| 931 | /// V2+ TZif formatted files. |
| 932 | fn data_block_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]data_block_len().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 933 | let a = self.transition_times_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]transition_times_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 934 | let b = self.transition_types_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]transition_types_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 935 | let c = self.local_time_types_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]local_time_types_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 936 | let d = self.time_zone_designations_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]time_zone_designations_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 937 | let e = self.leap_second_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]leap_second_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 938 | let f = self.standard_wall_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]standard_wall_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 939 | let g = self.ut_local_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]ut_local_len().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 940 | a.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(b) |
| 941 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|z| z.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(c)) |
| 942 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|z| z.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(d)) |
| 943 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|z| z.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(e)) |
| 944 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|z| z.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(f)) |
| 945 | .and_thenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]and_then().(|z| z.checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(g)) |
| 946 | .ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| { |
| 947 | errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 948 | "length of data block in V{} tzfile is too big", |
| 949 | self.versionrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#version. |
| 950 | ) |
| 951 | }) |
| 952 | } |
| 953 | |
| 954 | fn transition_times_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]transition_times_len().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 955 | self.tzh_timecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_timecnt..checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(self.time_sizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#time_size.).ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| { |
| 956 | errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("tzh_timecnt value {} is too big", self.tzh_timecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_timecnt.) |
| 957 | }) |
| 958 | } |
| 959 | |
| 960 | fn transition_types_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]transition_types_len().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 961 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.tzh_timecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_timecnt.) |
| 962 | } |
| 963 | |
| 964 | fn local_time_types_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]local_time_types_len().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 965 | self.tzh_typecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_typecnt..checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(6).ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| { |
| 966 | errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("tzh_typecnt value {} is too big", self.tzh_typecntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_typecnt.) |
| 967 | }) |
| 968 | } |
| 969 | |
| 970 | fn time_zone_designations_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]time_zone_designations_len().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 971 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.tzh_charcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_charcnt.) |
| 972 | } |
| 973 | |
| 974 | fn leap_second_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]leap_second_len().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 975 | let record_len = self |
| 976 | .time_sizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#time_size. |
| 977 | .checked_addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_add().(4) |
| 978 | .expectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]expect().("4-or-8 plus 4 always fits in usize"); |
| 979 | self.tzh_leapcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_leapcnt..checked_mulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]checked_mul().(record_len).ok_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]ok_or_else().(|| { |
| 980 | errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!("tzh_leapcnt value {} is too big", self.tzh_leapcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_leapcnt.) |
| 981 | }) |
| 982 | } |
| 983 | |
| 984 | fn standard_wall_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]standard_wall_len().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 985 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.tzh_ttisstdcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_ttisstdcnt.) |
| 986 | } |
| 987 | |
| 988 | fn ut_local_lenrust-analyzer cargo jiff-static 0.2.16 shared/tzif/impl#[Header]ut_local_len().(&self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 989 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.tzh_ttisutcntrust-analyzer cargo jiff-static 0.2.16 shared/tzif/Header#tzh_ttisutcnt.) |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | /// Splits the given slice of bytes at the index given. |
| 994 | /// |
| 995 | /// If the index is out of range (greater than `bytes.len()`) then an error is |
| 996 | /// returned. The error message will include the `what` string given, which is |
| 997 | /// meant to describe the thing being split. |
| 998 | fn try_split_atrust-analyzer cargo jiff-static 0.2.16 shared/tzif/try_split_at().<'b>( |
| 999 | what: &'static str, |
| 1000 | bytes: &'b [u8], |
| 1001 | at: usize, |
| 1002 | ) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<(&'b [u8], &'b [u8]), Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 1003 | if at rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().() { |
| 1004 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 1005 | "expected at least {at} bytes for {what}, \ |
| 1006 | but found only {} bytes", |
| 1007 | bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 1008 | )) |
| 1009 | } else { |
| 1010 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(bytes.split_atrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]split_at().(at)) |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /// Interprets the given slice as an unsigned 32-bit big endian integer, |
| 1015 | /// attempts to convert it to a `usize` and returns it. |
| 1016 | /// |
| 1017 | /// # Panics |
| 1018 | /// |
| 1019 | /// When `bytes.len() != 4`. |
| 1020 | /// |
| 1021 | /// # Errors |
| 1022 | /// |
| 1023 | /// This errors if the `u32` parsed from the given bytes cannot fit in a |
| 1024 | /// `usize`. |
| 1025 | fn from_be_bytes_u32_to_usizerust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32_to_usize().(bytes: &[u8]) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<usize, Errorrust-analyzer cargo jiff-static 0.2.16 shared/util/error/Error#> { |
| 1026 | let n = from_be_bytes_u32rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32().(bytes); |
| 1027 | usize::try_fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/num/ptr_try_from_impls/impl#[usize][`TryFrom<u32>`]try_from().(n).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|_| { |
| 1028 | errrust-analyzer cargo jiff-static 0.2.16 shared/util/error/err!!( |
| 1029 | "failed to parse integer {n} (too big, max allowed is {}", |
| 1030 | usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX. |
| 1031 | ) |
| 1032 | }) |
| 1033 | } |
| 1034 | |
| 1035 | /// Interprets the given slice as an unsigned 32-bit big endian integer and |
| 1036 | /// returns it. |
| 1037 | /// |
| 1038 | /// # Panics |
| 1039 | /// |
| 1040 | /// When `bytes.len() != 4`. |
| 1041 | fn from_be_bytes_u32rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_u32().(bytes: &[u8]) -> u32 { |
| 1042 | u32::from_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u32]from_be_bytes().(bytes.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 1043 | } |
| 1044 | |
| 1045 | /// Interprets the given slice as a signed 32-bit big endian integer and |
| 1046 | /// returns it. |
| 1047 | /// |
| 1048 | /// # Panics |
| 1049 | /// |
| 1050 | /// When `bytes.len() != 4`. |
| 1051 | fn from_be_bytes_i32rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_i32().(bytes: &[u8]) -> i32 { |
| 1052 | i32::from_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i32]from_be_bytes().(bytes.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 1053 | } |
| 1054 | |
| 1055 | /// Interprets the given slice as a signed 64-bit big endian integer and |
| 1056 | /// returns it. |
| 1057 | /// |
| 1058 | /// # Panics |
| 1059 | /// |
| 1060 | /// When `bytes.len() != 8`. |
| 1061 | fn from_be_bytes_i64rust-analyzer cargo jiff-static 0.2.16 shared/tzif/from_be_bytes_i64().(bytes: &[u8]) -> i64 { |
| 1062 | i64::from_be_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[i64]from_be_bytes().(bytes.try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/TryInto#try_into().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()) |
| 1063 | } |