icu_datetime/provider/
time_zones.rs

1// This file is part of ICU4X. For terms of use, please see the file
2// called LICENSE at the top level of the ICU4X source tree
3// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
4
5//! Data provider structs for time zones.
6
7use alloc::borrow::Cow;
8use icu_pattern::{DoublePlaceholderPattern, SinglePlaceholderPattern};
9use icu_provider::prelude::*;
10use zerovec::{ule::NichedOption, ZeroMap, ZeroMap2d, ZeroVec};
11
12use icu_time::{zone::TimeZoneVariant, zone::ZoneNameTimestamp, TimeZone};
13
14/// Time zone type aliases for cleaner code
15pub(crate) mod tz {
16    pub(crate) use super::ExemplarCities;
17    pub(crate) use super::Locations;
18    pub(crate) use super::MetazoneGenericNames as MzGeneric;
19    pub(crate) use super::MetazonePeriod as MzPeriod;
20    pub(crate) use super::MetazoneSpecificNames as MzSpecific;
21    pub(crate) use super::TimeZoneEssentials as Essentials;
22    pub(crate) use super::TimezoneMetazonePeriodsV1 as MzPeriodV1;
23    pub(crate) use super::TimezoneNamesCitiesOverrideV1 as CitiesOverrideV1;
24    pub(crate) use super::TimezoneNamesCitiesRootV1 as CitiesRootV1;
25    pub(crate) use super::TimezoneNamesEssentialsV1 as EssentialsV1;
26    pub(crate) use super::TimezoneNamesGenericLongV1 as MzGenericLongV1;
27    pub(crate) use super::TimezoneNamesGenericShortV1 as MzGenericShortV1;
28    pub(crate) use super::TimezoneNamesLocationsOverrideV1 as LocationsOverrideV1;
29    pub(crate) use super::TimezoneNamesLocationsRootV1 as LocationsRootV1;
30    pub(crate) use super::TimezoneNamesSpecificLongV1 as MzSpecificLongV1;
31    pub(crate) use super::TimezoneNamesSpecificShortV1 as MzSpecificShortV1;
32    pub(crate) use super::TimezoneNamesStandardLongV1 as MzStandardLongV1;
33}
34
35icu_provider::data_marker!(
36    /// `TimezoneNamesEssentialsV1`
37    TimezoneNamesEssentialsV1,
38    TimeZoneEssentials<'static>
39);
40icu_provider::data_marker!(
41    /// `TimezoneNamesLocationsOverrideV1`
42    TimezoneNamesLocationsOverrideV1,
43    Locations<'static>
44);
45icu_provider::data_marker!(
46    /// `TimezoneNamesLocationsRootV1`
47    TimezoneNamesLocationsRootV1,
48    Locations<'static>
49);
50icu_provider::data_marker!(
51    /// `TimezoneNamesCitiesOverrideV1`
52    TimezoneNamesCitiesOverrideV1,
53    ExemplarCities<'static>
54);
55icu_provider::data_marker!(
56    /// `TimezoneNamesCitiesRootV1`
57    TimezoneNamesCitiesRootV1,
58    ExemplarCities<'static>
59);
60
61icu_provider::data_marker!(
62    /// `TimezoneNamesGenericLongV1`
63    ///
64    /// Checksumed to ensure consistency with [`TimezoneMetazonePeriodsV1`].
65    TimezoneNamesGenericLongV1,
66    MetazoneGenericNames<'static>,
67    has_checksum = true
68);
69icu_provider::data_marker!(
70    /// `TimezoneNamesGenericShortV1`
71    ///
72    /// Checksumed to ensure consistency with [`TimezoneMetazonePeriodsV1`].
73    TimezoneNamesGenericShortV1,
74    MetazoneGenericNames<'static>,
75    has_checksum = true
76);
77icu_provider::data_marker!(
78    /// `TimezoneNamesStandardLongV1`
79    ///
80    /// Checksumed to ensure consistency with [`TimezoneMetazonePeriodsV1`].
81    TimezoneNamesStandardLongV1,
82    MetazoneGenericNames<'static>,
83    has_checksum = true
84);
85icu_provider::data_marker!(
86    /// `TimezoneNamesSpecificLongV1`
87    ///
88    /// Checksumed to ensure consistency with [`TimezoneMetazonePeriodsV1`].
89    TimezoneNamesSpecificLongV1,
90    MetazoneSpecificNames<'static>,
91    has_checksum = true
92);
93icu_provider::data_marker!(
94    /// `TimezoneNamesSpecificShortV1`
95    ///
96    /// Checksumed to ensure consistency with [`TimezoneMetazonePeriodsV1`].
97    TimezoneNamesSpecificShortV1,
98    MetazoneSpecificNames<'static>,
99    has_checksum = true,
100);
101icu_provider::data_marker!(
102    /// `TimezoneMetazonePeriodsV1`
103    TimezoneMetazonePeriodsV1,
104    MetazonePeriod<'static>,
105    is_singleton = true,
106    has_checksum = true
107);
108
109/// An ICU4X mapping to the CLDR timeZoneNames format strings.
110/// See CLDR-JSON timeZoneNames.json and <https://cldr.unicode.org/translation/time-zones-and-city-names>
111/// for more context.
112///
113/// <div class="stab unstable">
114/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
115/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
116/// to be stable, their Rust representation might not be. Use with caution.
117/// </div>
118#[derive(PartialEq, Debug, Clone, Default, yoke::Yokeable, zerofrom::ZeroFrom)]
119#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
120#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
121#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
122#[yoke(prove_covariance_manually)]
123pub struct TimeZoneEssentials<'data> {
124    /// The separator sign
125    #[cfg_attr(feature = "serde", serde(borrow,))]
126    pub offset_separator: Cow<'data, str>,
127    /// The localized offset format.
128    #[cfg_attr(
129        feature = "serde",
130        serde(
131            borrow,
132            deserialize_with = "icu_pattern::deserialize_borrowed_cow::<icu_pattern::SinglePlaceholder, _>"
133        )
134    )]
135    pub offset_pattern: Cow<'data, SinglePlaceholderPattern>,
136    /// The localized zero-offset format.
137    #[cfg_attr(feature = "serde", serde(borrow))]
138    pub offset_zero: Cow<'data, str>,
139    /// The localized unknown-offset format.
140    #[cfg_attr(feature = "serde", serde(borrow))]
141    pub offset_unknown: Cow<'data, str>,
142}
143
144icu_provider::data_struct!(
145    TimeZoneEssentials<'_>,
146    #[cfg(feature = "datagen")]
147);
148
149/// An ICU4X mapping to the CLDR timeZoneNames exemplar cities.
150/// See CLDR-JSON timeZoneNames.json for more context.
151///
152/// <div class="stab unstable">
153/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
154/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
155/// to be stable, their Rust representation might not be. Use with caution.
156/// </div>
157#[derive(PartialEq, Debug, Clone, Default, yoke::Yokeable, zerofrom::ZeroFrom)]
158#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
159#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
160#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
161#[yoke(prove_covariance_manually)]
162pub struct Locations<'data> {
163    /// Per-zone location display name
164    #[cfg_attr(feature = "serde", serde(borrow))]
165    pub locations: ZeroMap<'data, TimeZone, str>,
166    /// The format string for a region's generic time.
167    #[cfg_attr(
168        feature = "serde",
169        serde(
170            borrow,
171            deserialize_with = "icu_pattern::deserialize_borrowed_cow::<icu_pattern::SinglePlaceholder, _>"
172        )
173    )]
174    pub pattern_generic: Cow<'data, SinglePlaceholderPattern>,
175    /// The format string for a region's standard time.
176    #[cfg_attr(
177        feature = "serde",
178        serde(
179            borrow,
180            deserialize_with = "icu_pattern::deserialize_borrowed_cow::<icu_pattern::SinglePlaceholder, _>"
181        )
182    )]
183    pub pattern_standard: Cow<'data, SinglePlaceholderPattern>,
184    /// The format string for a region's daylight time.
185    #[cfg_attr(
186        feature = "serde",
187        serde(
188            borrow,
189            deserialize_with = "icu_pattern::deserialize_borrowed_cow::<icu_pattern::SinglePlaceholder, _>"
190        )
191    )]
192    pub pattern_daylight: Cow<'data, SinglePlaceholderPattern>,
193    /// Metazone Name with Location Pattern.
194    #[cfg_attr(
195        feature = "serde",
196        serde(
197            borrow,
198            deserialize_with = "icu_pattern::deserialize_borrowed_cow::<icu_pattern::DoublePlaceholder, _>"
199        )
200    )]
201    pub pattern_partial_location: Cow<'data, DoublePlaceholderPattern>,
202}
203
204icu_provider::data_struct!(
205    Locations<'_>,
206    #[cfg(feature = "datagen")]
207);
208
209/// An ICU4X mapping to the CLDR timeZoneNames exemplar cities.
210/// See CLDR-JSON timeZoneNames.json for more context.
211///
212/// <div class="stab unstable">
213/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
214/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
215/// to be stable, their Rust representation might not be. Use with caution.
216/// </div>
217#[derive(PartialEq, Debug, Clone, Default, yoke::Yokeable, zerofrom::ZeroFrom)]
218#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
219#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
220#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
221#[yoke(prove_covariance_manually)]
222pub struct ExemplarCities<'data> {
223    /// Per-zone exemplar city name. This is deduplicated against `Locations.locations`, so it
224    /// only contains time zones that don't use the exemplar city in the location format.
225    #[cfg_attr(feature = "serde", serde(borrow))]
226    pub exemplars: ZeroMap<'data, TimeZone, str>,
227}
228
229icu_provider::data_struct!(
230    ExemplarCities<'_>,
231    #[cfg(feature = "datagen")]
232);
233
234/// An ICU4X mapping to generic metazone names.
235/// See CLDR-JSON timeZoneNames.json for more context.
236///
237/// <div class="stab unstable">
238/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
239/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
240/// to be stable, their Rust representation might not be. Use with caution.
241/// </div>
242#[derive(PartialEq, Debug, Clone, Default, yoke::Yokeable, zerofrom::ZeroFrom)]
243#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
244#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
245#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
246#[yoke(prove_covariance_manually)]
247pub struct MetazoneGenericNames<'data> {
248    /// The default mapping between metazone id and localized metazone name.
249    #[cfg_attr(feature = "serde", serde(borrow))]
250    pub defaults: ZeroMap<'data, MetazoneId, str>,
251    /// The override mapping between timezone id and localized metazone name.
252    #[cfg_attr(feature = "serde", serde(borrow))]
253    pub overrides: ZeroMap<'data, TimeZone, str>,
254}
255
256icu_provider::data_struct!(
257    MetazoneGenericNames<'_>,
258    #[cfg(feature = "datagen")]
259);
260
261/// An ICU4X mapping to specific metazone names.
262/// Specific names include time variants such as "daylight."
263/// See CLDR-JSON timeZoneNames.json for more context.
264///
265/// These markers use a checksum to ensure consistency with [`MetazonePeriod`].
266///
267/// <div class="stab unstable">
268/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
269/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
270/// to be stable, their Rust representation might not be. Use with caution.
271/// </div>
272#[derive(PartialEq, Debug, Clone, Default, yoke::Yokeable, zerofrom::ZeroFrom)]
273#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
274#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
275#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
276#[yoke(prove_covariance_manually)]
277pub struct MetazoneSpecificNames<'data> {
278    /// The default mapping between metazone id and localized metazone name.
279    #[cfg_attr(feature = "serde", serde(borrow))]
280    pub defaults: ZeroMap<'data, (MetazoneId, TimeZoneVariant), str>,
281    /// The override mapping between timezone id and localized metazone name.
282    #[cfg_attr(feature = "serde", serde(borrow))]
283    pub overrides: ZeroMap<'data, (TimeZone, TimeZoneVariant), str>,
284    /// The metazones for which the standard name is in `MetazoneGenericStandardNames*V1`
285    #[cfg_attr(feature = "serde", serde(borrow))]
286    pub use_standard: ZeroVec<'data, MetazoneId>,
287}
288
289icu_provider::data_struct!(
290    MetazoneSpecificNames<'_>,
291    #[cfg(feature = "datagen")]
292);
293
294/// Metazone ID in a compact format
295///
296/// <div class="stab unstable">
297/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
298/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
299/// to be stable, their Rust representation might not be. Use with caution.
300/// </div>
301pub type MetazoneId = core::num::NonZeroU8;
302
303/// An ICU4X mapping to the metazones at a given period.
304/// See CLDR-JSON metaZones.json for more context.
305///
306/// <div class="stab unstable">
307/// 🚧 This code is considered unstable; it may change at any time, in breaking or non-breaking ways,
308/// including in SemVer minor releases. While the serde representation of data structs is guaranteed
309/// to be stable, their Rust representation might not be. Use with caution.
310/// </div>
311#[derive(PartialEq, Debug, Clone, Default, yoke::Yokeable, zerofrom::ZeroFrom)]
312#[cfg_attr(feature = "datagen", derive(serde::Serialize, databake::Bake))]
313#[cfg_attr(feature = "datagen", databake(path = icu_datetime::provider::time_zones))]
314#[cfg_attr(feature = "serde", derive(serde::Deserialize))]
315#[yoke(prove_covariance_manually)]
316pub struct MetazonePeriod<'data> {
317    /// The default mapping between period and offsets. The second level key is a wall-clock time encoded as
318    /// [`ZoneNameTimestamp`]. It represents when the metazone started to be used.
319    #[cfg_attr(feature = "serde", serde(borrow))]
320    pub list: ZeroMap2d<'data, TimeZone, ZoneNameTimestamp, NichedOption<MetazoneId, 1>>,
321}
322
323icu_provider::data_struct!(
324    MetazonePeriod<'_>,
325    #[cfg(feature = "datagen")]
326);