| 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 |
//! All available field sets for datetime formatting. |
| 6 |
//! |
| 7 |
//! Each field set is a struct containing options specified to that field set. |
| 8 |
//! The fields can either be set directly or via helper functions. |
| 9 |
//! |
| 10 |
//! This module contains _static_ field sets, which deliver the smallest binary size. |
| 11 |
//! If the field set is not known until runtime, use a _dynamic_ field set: [`enums`] |
| 12 |
//! |
| 13 |
//! # What is a Field Set? |
| 14 |
//! |
| 15 |
//! A field set determines what datetime fields should be printed in the localized output. |
| 16 |
//! |
| 17 |
//! Examples of field sets include: |
| 18 |
//! |
| 19 |
//! 1. Year, month, and day ([`YMD`]) |
| 20 |
//! 2. Weekday and time ([`ET`]) |
| 21 |
//! |
| 22 |
//! Field sets fit into four categories: |
| 23 |
//! |
| 24 |
//! 1. Date: fields that specify a particular day in time. |
| 25 |
//! 2. Calendar period: fields that specify a span of time greater than a day. |
| 26 |
//! 3. Time: fields that specify a time within a day. |
| 27 |
//! 4. Zone: fields that specify a time zone or offset from UTC. |
| 28 |
//! |
| 29 |
//! Certain combinations of field sets are allowed, too. See [`Combo`]. |
| 30 |
//! |
| 31 |
//! # Examples |
| 32 |
//! |
| 33 |
//! There are two ways to configure the same field set: |
| 34 |
//! |
| 35 |
//! ``` |
| 36 |
//! use icu::datetime::fieldsets::YMDT; |
| 37 |
//! use icu::datetime::options::{Alignment, TimePrecision, YearStyle}; |
| 38 |
//! |
| 39 |
//! let field_set_1 = YMDT::long() |
| 40 |
//! .with_year_style(YearStyle::Full) |
| 41 |
//! .with_alignment(Alignment::Column) |
| 42 |
//! .with_time_precision(TimePrecision::Minute); |
| 43 |
//! |
| 44 |
//! let mut field_set_2 = YMDT::long(); |
| 45 |
//! field_set_2.year_style = Some(YearStyle::Full); |
| 46 |
//! field_set_2.alignment = Some(Alignment::Column); |
| 47 |
//! field_set_2.time_precision = Some(TimePrecision::Minute); |
| 48 |
//! |
| 49 |
//! assert_eq!(field_set_1, field_set_2); |
| 50 |
//! ``` |
| 51 |
|
| 52 |
#[path = "builder.rs"] |
| 53 |
pub mod builder; |
| 54 |
#[path = "dynamic.rs"] |
| 55 |
pub mod enums; |
| 56 |
|
| 57 |
pub use crate::combo::Combo; |
| 58 |
|
| 59 |
use crate::{ |
| 60 |
options::*, |
| 61 |
provider::semantic_skeletons::{DatetimePatternsGlueV1, GluePattern}, |
| 62 |
provider::{ |
| 63 |
fields, names::*, range_patterns::DatetimePatternsRangeTimeV1, semantic_skeletons::*, |
| 64 |
time_zones::tz, |
| 65 |
}, |
| 66 |
raw::neo::RawOptions, |
| 67 |
scaffold::*, |
| 68 |
}; |
| 69 |
use enums::*; |
| 70 |
use icu_calendar::types::{DayOfMonth, MonthInfo, Weekday, YearInfo}; |
| 71 |
use icu_provider::marker::NeverMarker; |
| 72 |
use icu_time::{ |
| 73 |
Hour, Minute, Nanosecond, Second, TimeZone, |
| 74 |
zone::{UtcOffset, ZoneNameTimestamp}, |
| 75 |
}; |
| 76 |
|
| 77 |
#[cfg(doc)] |
| 78 |
use icu_time::TimeZoneInfo; |
| 79 |
|
| 80 |
/// Maps the token `yes` to the given ident |
| 81 |
macro_rules! yes_to { |
| 82 |
($any:expr, $nonempty:expr) => { |
| 83 |
$any |
| 84 |
}; |
| 85 |
} |
| 86 |
|
| 87 |
macro_rules! yes_or { |
| 88 |
($fallback:expr, $actual:expr) => { |
| 89 |
$actual |
| 90 |
}; |
| 91 |
($fallback:expr,) => { |
| 92 |
$fallback |
| 93 |
}; |
| 94 |
} |
| 95 |
|
| 96 |
macro_rules! ternary { |
| 97 |
($present:expr, $missing:expr, yes) => { |
| 98 |
$present |
| 99 |
}; |
| 100 |
($present:expr, $missing:expr,) => { |
| 101 |
$missing |
| 102 |
}; |
| 103 |
} |
| 104 |
|
| 105 |
/// Generates the options argument passed into the docs test constructor |
| 106 |
macro_rules! length_option_helper { |
| 107 |
($type:ty, $length:ident) => { |
| 108 |
concat!(stringify!($type), "::", stringify!($length), "()") |
| 109 |
}; |
| 110 |
} |
| 111 |
|
| 112 |
macro_rules! impl_composite { |
| 113 |
($type:ident, $variant:ident, $enum:ident) => { |
| 114 |
impl $type { |
| 115 |
#[inline] |
| 116 |
pub(crate) fn to_enum(self) -> $enum { |
| 117 |
$enum::$type(self) |
| 118 |
} |
| 119 |
} |
| 120 |
impl GetField<CompositeFieldSet> for $type { |
| 121 |
#[inline] |
| 122 |
fn get_field(&self) -> CompositeFieldSet { |
| 123 |
CompositeFieldSet::$variant(self.to_enum()) |
| 124 |
} |
| 125 |
} |
| 126 |
}; |
| 127 |
} |
| 128 |
|
| 129 |
macro_rules! impl_marker_length_constructors { |
| 130 |
( |
| 131 |
$type:ident, |
| 132 |
$(alignment: $alignment_yes:ident,)? |
| 133 |
$(year_style: $yearstyle_yes:ident,)? |
| 134 |
$(time_precision: $timeprecision_yes:ident,)? |
| 135 |
) => { |
| 136 |
impl $type { |
| 137 |
#[doc = concat!("Creates a ", stringify!($type), " skeleton with the given formatting length.")] |
| 138 |
pub const fn for_length(length: Length) -> Self { |
| 139 |
Self { |
| 140 |
length, |
| 141 |
$( |
| 142 |
alignment: yes_to!(None, $alignment_yes), |
| 143 |
)? |
| 144 |
$( |
| 145 |
year_style: yes_to!(None, $yearstyle_yes), |
| 146 |
)? |
| 147 |
$( |
| 148 |
time_precision: yes_to!(None, $timeprecision_yes), |
| 149 |
)? |
| 150 |
} |
| 151 |
} |
| 152 |
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a long length.")] |
| 153 |
pub const fn long() -> Self { |
| 154 |
Self::for_length(Length::Long) |
| 155 |
} |
| 156 |
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a medium length.")] |
| 157 |
pub const fn medium() -> Self { |
| 158 |
Self::for_length(Length::Medium) |
| 159 |
} |
| 160 |
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a short length.")] |
| 161 |
pub const fn short() -> Self { |
| 162 |
Self::for_length(Length::Short) |
| 163 |
} |
| 164 |
} |
| 165 |
}; |
| 166 |
} |
| 167 |
|
| 168 |
macro_rules! impl_time_precision_constructors { |
| 169 |
( |
| 170 |
$time_type:ident, |
| 171 |
) => { |
| 172 |
impl $time_type { |
| 173 |
#[doc = concat!("Creates a ", stringify!($type), " that formats hours and minutes with the default length.")] |
| 174 |
pub fn hm() -> Self { |
| 175 |
Self::for_length(Default::default()).with_time_precision(TimePrecision::Minute) |
| 176 |
} |
| 177 |
#[doc = concat!("Creates a ", stringify!($type), " that formats hours, minutes, and seconds with the default length.")] |
| 178 |
pub fn hms() -> Self { |
| 179 |
Self::for_length(Default::default()).with_time_precision(TimePrecision::Second) |
| 180 |
} |
| 181 |
#[doc = concat!("Creates a ", stringify!($type), " that formats hours, minutes, seconds, and subseconds with the default length.")] |
| 182 |
pub fn hmss(subsecond_digits: SubsecondDigits) -> Self { |
| 183 |
Self::for_length(Default::default()).with_time_precision(TimePrecision::Subsecond(subsecond_digits)) |
| 184 |
} |
| 185 |
} |
| 186 |
}; |
| 187 |
} |
| 188 |
|
| 189 |
macro_rules! impl_marker_with_options { |
| 190 |
( |
| 191 |
$(#[$attr:meta])* |
| 192 |
$type:ident, |
| 193 |
$(sample_length: $sample_length:ident,)? |
| 194 |
$(date_fields: $date_fields:expr,)? |
| 195 |
$(alignment: $alignment_yes:ident,)? |
| 196 |
$(year_style: $yearstyle_yes:ident,)? |
| 197 |
$(time_precision: $timeprecision_yes:ident,)? |
| 198 |
$(length_override: $length_override:ident,)? |
| 199 |
) => { |
| 200 |
$(#[$attr])* |
| 201 |
#[derive(Debug, Copy, Clone, PartialEq, Eq)] |
| 202 |
#[non_exhaustive] |
| 203 |
pub struct $type { |
| 204 |
$( |
| 205 |
/// The desired length of the formatted string. |
| 206 |
/// |
| 207 |
/// See: [`Length`] |
| 208 |
pub length: datetime_marker_helper!(@option/length, $sample_length), |
| 209 |
)? |
| 210 |
$( |
| 211 |
/// Whether fields should be aligned for a column-like layout. |
| 212 |
/// |
| 213 |
/// See: [`Alignment`] |
| 214 |
pub alignment: datetime_marker_helper!(@option/alignment, $alignment_yes), |
| 215 |
)? |
| 216 |
$( |
| 217 |
/// When to display the era field in the formatted string. |
| 218 |
/// |
| 219 |
/// See: [`YearStyle`] |
| 220 |
pub year_style: datetime_marker_helper!(@option/yearstyle, $yearstyle_yes), |
| 221 |
)? |
| 222 |
$( |
| 223 |
/// How precisely to display the time of day |
| 224 |
/// |
| 225 |
/// See: [`TimePrecision`] |
| 226 |
pub time_precision: datetime_marker_helper!(@option/timeprecision, $timeprecision_yes), |
| 227 |
)? |
| 228 |
} |
| 229 |
impl $type { |
| 230 |
pub(crate) fn to_raw_options(self) -> RawOptions { |
| 231 |
RawOptions { |
| 232 |
length: yes_or!(Some(self.length), $(Some(Length::$length_override))?), |
| 233 |
date_fields: yes_or!(None, $($date_fields)?), |
| 234 |
alignment: ternary!(self.alignment, None, $($alignment_yes)?), |
| 235 |
year_style: ternary!(self.year_style, None, $($yearstyle_yes)?), |
| 236 |
time_precision: ternary!(self.time_precision, None, $($timeprecision_yes)?), |
| 237 |
} |
| 238 |
} |
| 239 |
/// Builds this field set, removing the needed options from the builder. |
| 240 |
pub(crate) fn take_from_builder( |
| 241 |
options: &mut builder::FieldSetBuilder |
| 242 |
) -> Self { |
| 243 |
Self { |
| 244 |
$(length: yes_to!(options.length.take().unwrap_or_default(), $sample_length),)? |
| 245 |
$(alignment: yes_to!(options.alignment.take(), $alignment_yes),)? |
| 246 |
$(year_style: yes_to!(options.year_style.take(), $yearstyle_yes),)? |
| 247 |
$(time_precision: yes_to!(options.time_precision.take(), $timeprecision_yes),)? |
| 248 |
} |
| 249 |
} |
| 250 |
} |
| 251 |
$( |
| 252 |
impl $type { |
| 253 |
/// Sets the length option. |
| 254 |
pub const fn with_length(mut self, length: Length) -> Self { |
| 255 |
self.length = yes_to!(length, $sample_length); |
| 256 |
self |
| 257 |
} |
| 258 |
} |
| 259 |
)? |
| 260 |
$( |
| 261 |
impl $type { |
| 262 |
/// Sets the alignment option. |
| 263 |
pub const fn with_alignment(mut self, alignment: Alignment) -> Self { |
| 264 |
self.alignment = Some(yes_to!(alignment, $alignment_yes)); |
| 265 |
self |
| 266 |
} |
| 267 |
} |
| 268 |
)? |
| 269 |
$( |
| 270 |
impl $type { |
| 271 |
/// Sets the year style option. |
| 272 |
pub const fn with_year_style(mut self, year_style: YearStyle) -> Self { |
| 273 |
self.year_style = Some(yes_to!(year_style, $yearstyle_yes)); |
| 274 |
self |
| 275 |
} |
| 276 |
} |
| 277 |
)? |
| 278 |
$( |
| 279 |
impl $type { |
| 280 |
/// Sets the time precision option. |
| 281 |
pub const fn with_time_precision(mut self, time_precision: TimePrecision) -> Self { |
| 282 |
self.time_precision = Some(yes_to!(time_precision, $timeprecision_yes)); |
| 283 |
self |
| 284 |
} |
| 285 |
} |
| 286 |
)? |
| 287 |
}; |
| 288 |
} |
| 289 |
|
| 290 |
macro_rules! impl_date_to_time_helpers { |
| 291 |
( |
| 292 |
$type:ident, |
| 293 |
$type_time:ident, |
| 294 |
$(alignment = $alignment_yes:ident,)? |
| 295 |
$(year_style = $yearstyle_yes:ident,)? |
| 296 |
) => { |
| 297 |
impl $type { |
| 298 |
/// Associates this field set with a time precision. |
| 299 |
pub fn with_time(self, time_precision: TimePrecision) -> $type_time { |
| 300 |
$type_time { |
| 301 |
length: self.length, |
| 302 |
time_precision: Some(time_precision), |
| 303 |
alignment: ternary!(self.alignment, Default::default(), $($alignment_yes)?), |
| 304 |
$(year_style: yes_to!(self.year_style, $yearstyle_yes),)? |
| 305 |
} |
| 306 |
} |
| 307 |
/// Shorthand to associate this field set with [`TimePrecision::Minute`]. |
| 308 |
/// |
| 309 |
/// # Examples |
| 310 |
/// |
| 311 |
/// ``` |
| 312 |
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")] |
| 313 |
/// use icu::datetime::options::TimePrecision; |
| 314 |
/// |
| 315 |
#[doc = concat!("let fs1 = ", stringify!($type), "::medium().with_time(TimePrecision::Minute);")] |
| 316 |
#[doc = concat!("let fs2 = ", stringify!($type), "::medium().with_time_hm();")] |
| 317 |
/// assert_eq!(fs1, fs2); |
| 318 |
/// ``` |
| 319 |
pub fn with_time_hm(self) -> $type_time { |
| 320 |
$type_time { |
| 321 |
length: self.length, |
| 322 |
time_precision: Some(TimePrecision::Minute), |
| 323 |
alignment: ternary!(self.alignment, Default::default(), $($alignment_yes)?), |
| 324 |
$(year_style: yes_to!(self.year_style, $yearstyle_yes),)? |
| 325 |
} |
| 326 |
} |
| 327 |
/// Shorthand to associate this field set with [`TimePrecision::Second`]. |
| 328 |
/// |
| 329 |
/// # Examples |
| 330 |
/// |
| 331 |
/// ``` |
| 332 |
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")] |
| 333 |
/// use icu::datetime::options::TimePrecision; |
| 334 |
/// |
| 335 |
#[doc = concat!("let fs1 = ", stringify!($type), "::medium().with_time(TimePrecision::Second);")] |
| 336 |
#[doc = concat!("let fs2 = ", stringify!($type), "::medium().with_time_hms();")] |
| 337 |
/// assert_eq!(fs1, fs2); |
| 338 |
/// ``` |
| 339 |
pub fn with_time_hms(self) -> $type_time { |
| 340 |
$type_time { |
| 341 |
length: self.length, |
| 342 |
time_precision: Some(TimePrecision::Second), |
| 343 |
alignment: ternary!(self.alignment, Default::default(), $($alignment_yes)?), |
| 344 |
$(year_style: yes_to!(self.year_style, $yearstyle_yes),)? |
| 345 |
} |
| 346 |
} |
| 347 |
/// Shorthand to associate this field set with [`TimePrecision::Subsecond`]. |
| 348 |
/// |
| 349 |
/// # Examples |
| 350 |
/// |
| 351 |
/// ``` |
| 352 |
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")] |
| 353 |
/// use icu::datetime::options::TimePrecision; |
| 354 |
/// use icu::datetime::options::SubsecondDigits::S2; |
| 355 |
/// |
| 356 |
#[doc = concat!("let fs1 = ", stringify!($type), "::medium().with_time(TimePrecision::Subsecond(S2));")] |
| 357 |
#[doc = concat!("let fs2 = ", stringify!($type), "::medium().with_time_hmss(S2);")] |
| 358 |
/// assert_eq!(fs1, fs2); |
| 359 |
/// ``` |
| 360 |
pub fn with_time_hmss(self, subsecond_digits: SubsecondDigits) -> $type_time { |
| 361 |
$type_time { |
| 362 |
length: self.length, |
| 363 |
time_precision: Some(TimePrecision::Subsecond(subsecond_digits)), |
| 364 |
alignment: ternary!(self.alignment, Default::default(), $($alignment_yes)?), |
| 365 |
$(year_style: yes_to!(self.year_style, $yearstyle_yes),)? |
| 366 |
} |
| 367 |
} |
| 368 |
} |
| 369 |
}; |
| 370 |
} |
| 371 |
|
| 372 |
macro_rules! impl_combo_get_field { |
| 373 |
($type:ident, $composite:ident, $enum:ident, $variant:path) => { |
| 374 |
impl GetField<CompositeFieldSet> for Combo<$type, $variant> { |
| 375 |
#[inline] |
| 376 |
fn get_field(&self) -> CompositeFieldSet { |
| 377 |
CompositeFieldSet::$composite(Combo::new(self.dt().to_enum(), self.z().to_enum())) |
| 378 |
} |
| 379 |
} |
| 380 |
impl Combo<$type, $variant> { |
| 381 |
/// Convert this specific [`Combo`] into a more general [`Combo`]. |
| 382 |
/// Useful when adding to the field of a [`CompositeFieldSet`]. |
| 383 |
/// |
| 384 |
/// [`CompositeFieldSet`]: enums::CompositeFieldSet |
| 385 |
pub fn into_enums(self) -> Combo<$enum, ZoneFieldSet> { |
| 386 |
Combo::new(self.dt().to_enum(), self.z().to_enum()) |
| 387 |
} |
| 388 |
} |
| 389 |
}; |
| 390 |
} |
| 391 |
|
| 392 |
macro_rules! impl_zone_combo_helpers { |
| 393 |
( |
| 394 |
$type:ident, |
| 395 |
$composite:ident, |
| 396 |
$enum:ident |
| 397 |
) => { |
| 398 |
impl $type { |
| 399 |
#[inline] |
| 400 |
/// Associates this field set with a time zone field set. |
| 401 |
pub fn with_zone<Z: ZoneMarkers>(self, zone: Z) -> Combo<Self, Z> { |
| 402 |
Combo::new(self, zone) |
| 403 |
} |
| 404 |
} |
| 405 |
impl_combo_get_field!($type, $composite, $enum, zone::SpecificLong); |
| 406 |
impl_combo_get_field!($type, $composite, $enum, zone::SpecificShort); |
| 407 |
impl_combo_get_field!($type, $composite, $enum, zone::LocalizedOffsetLong); |
| 408 |
impl_combo_get_field!($type, $composite, $enum, zone::LocalizedOffsetShort); |
| 409 |
impl_combo_get_field!($type, $composite, $enum, zone::GenericLong); |
| 410 |
impl_combo_get_field!($type, $composite, $enum, zone::GenericShort); |
| 411 |
impl_combo_get_field!($type, $composite, $enum, zone::Location); |
| 412 |
impl_combo_get_field!($type, $composite, $enum, zone::ExemplarCity); |
| 413 |
impl_combo_get_field!($type, $composite, $enum, ZoneFieldSet); |
| 414 |
}; |
| 415 |
} |
| 416 |
|
| 417 |
/// Internal helper macro used by [`impl_date_marker`] and [`impl_calendar_period_marker`] |
| 418 |
macro_rules! impl_date_or_calendar_period_marker { |
| 419 |
( |
| 420 |
$(#[$attr:meta])* |
| 421 |
// The name of the type being created. |
| 422 |
$type:ident, |
| 423 |
// A plain language description of the field set for documentation. |
| 424 |
description = $description:literal, |
| 425 |
// Length of the sample string below. |
| 426 |
sample_length = $sample_length:ident, |
| 427 |
// A sample string. A docs test will be generated! |
| 428 |
sample = $sample:literal, |
| 429 |
// Whether years can occur. |
| 430 |
$(years = $years_yes:ident,)? |
| 431 |
// Whether months can occur. |
| 432 |
$(months = $months_yes:ident,)? |
| 433 |
// Whether weekdays can occur. |
| 434 |
$(weekdays = $weekdays_yes:ident,)? |
| 435 |
// Whether the input should contain years. |
| 436 |
$(input_year = $year_yes:ident,)? |
| 437 |
// Whether the input should contain months. |
| 438 |
$(input_month = $month_yes:ident,)? |
| 439 |
// Whether the input should contain the day of the month. |
| 440 |
$(input_day_of_month = $day_of_month_yes:ident,)? |
| 441 |
// Whether the input should contain the weekday. |
| 442 |
$(input_weekday = $weekday_yes:ident,)? |
| 443 |
// Whether the input should contain the day of the year. |
| 444 |
$(input_day_of_year = $day_of_year_yes:ident,)? |
| 445 |
// Whether the input should contain the rata die. |
| 446 |
$(input_rata_die = $rata_die_yes:ident,)? |
| 447 |
// Whether the input should declare its calendar kind. |
| 448 |
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)? |
| 449 |
// Whether the alignment option should be available. |
| 450 |
// According to UTS 35, it should be available with years, months, and days. |
| 451 |
$(option_alignment = $option_alignment_yes:ident,)? |
| 452 |
) => { |
| 453 |
impl_marker_with_options!( |
| 454 |
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)] |
| 455 |
/// |
| 456 |
/// This is a field set marker. For more information, see [`fieldsets`](crate::fieldsets). |
| 457 |
/// |
| 458 |
/// # Examples |
| 459 |
/// |
| 460 |
/// In [`DateTimeFormatter`](crate::neo::DateTimeFormatter): |
| 461 |
/// |
| 462 |
/// ``` |
| 463 |
/// use icu::datetime::input::Date; |
| 464 |
/// use icu::datetime::DateTimeFormatter; |
| 465 |
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")] |
| 466 |
/// use icu::locale::locale; |
| 467 |
/// use writeable::assert_writeable_eq; |
| 468 |
#[doc = concat!("let fmt = DateTimeFormatter::<", stringify!($type), ">::try_new(")] |
| 469 |
/// locale!("en").into(), |
| 470 |
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")] |
| 471 |
/// ) |
| 472 |
/// .unwrap(); |
| 473 |
/// let dt = Date::try_new_iso(2024, 5, 17).unwrap(); |
| 474 |
/// |
| 475 |
/// assert_writeable_eq!( |
| 476 |
/// fmt.format(&dt), |
| 477 |
#[doc = concat!(" \"", $sample, "\"")] |
| 478 |
/// ); |
| 479 |
/// ``` |
| 480 |
/// |
| 481 |
/// In [`FixedCalendarDateTimeFormatter`](crate::neo::FixedCalendarDateTimeFormatter): |
| 482 |
/// |
| 483 |
/// ``` |
| 484 |
/// use icu::datetime::input::Date; |
| 485 |
/// use icu::calendar::Gregorian; |
| 486 |
/// use icu::datetime::FixedCalendarDateTimeFormatter; |
| 487 |
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")] |
| 488 |
/// use icu::locale::locale; |
| 489 |
/// use writeable::assert_writeable_eq; |
| 490 |
/// |
| 491 |
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::<Gregorian, ", stringify!($type), ">::try_new(")] |
| 492 |
/// locale!("en").into(), |
| 493 |
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")] |
| 494 |
/// ) |
| 495 |
/// .unwrap(); |
| 496 |
/// let dt = Date::try_new_gregorian(2024, 5, 17).unwrap(); |
| 497 |
/// |
| 498 |
/// assert_writeable_eq!( |
| 499 |
/// fmt.format(&dt), |
| 500 |
#[doc = concat!(" \"", $sample, "\"")] |
| 501 |
/// ); |
| 502 |
/// ``` |
| 503 |
$(#[$attr])* |
| 504 |
$type, |
| 505 |
sample_length: $sample_length, |
| 506 |
date_fields: Some(builder::DateFields::$type), |
| 507 |
$(alignment: $option_alignment_yes,)? |
| 508 |
$(year_style: $year_yes,)? |
| 509 |
); |
| 510 |
impl_marker_length_constructors!( |
| 511 |
$type, |
| 512 |
$(alignment: $option_alignment_yes,)? |
| 513 |
$(year_style: $year_yes,)? |
| 514 |
); |
| 515 |
impl UnstableSealed for $type {} |
| 516 |
impl DateTimeNamesMarker for $type { |
| 517 |
type YearNames = datetime_marker_helper!(@names/year, $($years_yes)?); |
| 518 |
type MonthNames = datetime_marker_helper!(@names/month, $($months_yes)?); |
| 519 |
type WeekdayNames = datetime_marker_helper!(@names/weekday, $($weekdays_yes)?); |
| 520 |
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod,); |
| 521 |
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,); |
| 522 |
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,); |
| 523 |
type ZoneLocationsRoot = datetime_marker_helper!(@names/zone/locations_root,); |
| 524 |
type ZoneExemplars = datetime_marker_helper!(@names/zone/exemplar,); |
| 525 |
type ZoneExemplarsRoot = datetime_marker_helper!(@names/zone/exemplar_root,); |
| 526 |
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,); |
| 527 |
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,); |
| 528 |
type ZoneStandardLong = datetime_marker_helper!(@names/zone/standard_long,); |
| 529 |
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,); |
| 530 |
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,); |
| 531 |
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,); |
| 532 |
} |
| 533 |
impl DateInputMarkers for $type { |
| 534 |
type YearInput = datetime_marker_helper!(@input/year, $($year_yes)?); |
| 535 |
type MonthInput = datetime_marker_helper!(@input/month, $($month_yes)?); |
| 536 |
type DayOfMonthInput = datetime_marker_helper!(@input/day_of_month, $($day_of_month_yes)?); |
| 537 |
type DayOfYearInput = datetime_marker_helper!(@input/day_of_year, $($day_of_year_yes)?); |
| 538 |
type RataDieInput = datetime_marker_helper!(@input/rata_die, $($rata_die_yes)?); |
| 539 |
type DayOfWeekInput = datetime_marker_helper!(@input/weekday, $($weekday_yes)?); |
| 540 |
} |
| 541 |
impl<C: CldrCalendar> TypedDateDataMarkers<C> for $type { |
| 542 |
type DateSkeletonPatternsV1 = datetime_marker_helper!(@dates/typed, yes); |
| 543 |
type DateRangeSkeletonPatternsV1 = datetime_marker_helper!(@dates/range/typed, yes); |
| 544 |
type YearNamesV1 = datetime_marker_helper!(@years/typed, $($years_yes)?); |
| 545 |
type MonthNamesV1 = datetime_marker_helper!(@months/typed, $($months_yes)?); |
| 546 |
type WeekdayNamesV1 = datetime_marker_helper!(@weekdays, $($weekdays_yes)?); |
| 547 |
} |
| 548 |
impl DateDataMarkers for $type { |
| 549 |
type Skel = datetime_marker_helper!(@calmarkers, yes); |
| 550 |
type RangeSkel = datetime_marker_helper!(@calmarkers, yes); |
| 551 |
type Year = datetime_marker_helper!(@calmarkers, $($years_yes)?); |
| 552 |
type Month = datetime_marker_helper!(@calmarkers, $($months_yes)?); |
| 553 |
type WeekdayNamesV1 = datetime_marker_helper!(@weekdays, $($weekdays_yes)?); |
| 554 |
} |
| 555 |
impl DateTimeMarkers for $type { |
| 556 |
type D = Self; |
| 557 |
type T = (); |
| 558 |
type Z = (); |
| 559 |
type GluePatternV1 = datetime_marker_helper!(@glue,); |
| 560 |
} |
| 561 |
}; |
| 562 |
} |
| 563 |
|
| 564 |
/// Implements a field set of date fields. |
| 565 |
/// |
| 566 |
/// Several arguments to this macro are required, and the rest are optional. |
| 567 |
/// The optional arguments should be written as `key = yes,` if that parameter |
| 568 |
/// should be included. |
| 569 |
/// |
| 570 |
/// See [`impl_date_marker`]. |
| 571 |
macro_rules! impl_date_marker { |
| 572 |
( |
| 573 |
$(#[$attr:meta])* |
| 574 |
$type:ident, |
| 575 |
$type_time:ident, |
| 576 |
description = $description:literal, |
| 577 |
sample_length = $sample_length:ident, |
| 578 |
sample = $sample:literal, |
| 579 |
sample_time = $sample_time:literal, |
| 580 |
$(years = $years_yes:ident,)? |
| 581 |
$(months = $months_yes:ident,)? |
| 582 |
$(dates = $dates_yes:ident,)? |
| 583 |
$(weekdays = $weekdays_yes:ident,)? |
| 584 |
$(input_year = $year_yes:ident,)? |
| 585 |
$(input_month = $month_yes:ident,)? |
| 586 |
$(input_day_of_month = $day_of_month_yes:ident,)? |
| 587 |
$(input_weekday = $weekday_yes:ident,)? |
| 588 |
$(input_day_of_year = $day_of_year_yes:ident,)? |
| 589 |
$(input_rata_die = $rata_die_yes:ident,)? |
| 590 |
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)? |
| 591 |
$(option_alignment = $option_alignment_yes:ident,)? |
| 592 |
) => { |
| 593 |
impl_date_or_calendar_period_marker!( |
| 594 |
$(#[$attr])* |
| 595 |
$type, |
| 596 |
description = $description, |
| 597 |
sample_length = $sample_length, |
| 598 |
sample = $sample, |
| 599 |
$(years = $years_yes,)? |
| 600 |
$(months = $months_yes,)? |
| 601 |
$(dates = $dates_yes,)? |
| 602 |
$(weekdays = $weekdays_yes,)? |
| 603 |
$(input_year = $year_yes,)? |
| 604 |
$(input_month = $month_yes,)? |
| 605 |
$(input_day_of_month = $day_of_month_yes,)? |
| 606 |
$(input_weekday = $weekday_yes,)? |
| 607 |
$(input_day_of_year = $day_of_year_yes,)? |
| 608 |
$(input_rata_die = $rata_die_yes,)? |
| 609 |
$(input_any_calendar_kind = $any_calendar_kind_yes,)? |
| 610 |
$(option_alignment = $option_alignment_yes,)? |
| 611 |
); |
| 612 |
impl_zone_combo_helpers!($type, DateZone, DateFieldSet); |
| 613 |
impl_composite!($type, Date, DateFieldSet); |
| 614 |
impl_date_to_time_helpers!($type, $type_time, $(alignment = $option_alignment_yes,)? $(year_style = $year_yes,)?); |
| 615 |
impl_marker_with_options!( |
| 616 |
#[doc = concat!("**“", $sample_time, "**” ⇒ ", $description, " with time")] |
| 617 |
/// |
| 618 |
/// # Examples |
| 619 |
/// |
| 620 |
/// In [`DateTimeFormatter`](crate::neo::DateTimeFormatter): |
| 621 |
/// |
| 622 |
/// ``` |
| 623 |
/// use icu::datetime::input::Date; |
| 624 |
/// use icu::datetime::DateTimeFormatter; |
| 625 |
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type_time), ";")] |
| 626 |
/// use icu::locale::locale; |
| 627 |
/// use icu::datetime::input::{DateTime, Time}; |
| 628 |
/// use writeable::assert_writeable_eq; |
| 629 |
/// |
| 630 |
#[doc = concat!("let fmt = DateTimeFormatter::try_new(")] |
| 631 |
/// locale!("en").into(), |
| 632 |
#[doc = concat!(" ", length_option_helper!($type_time, $sample_length), ",")] |
| 633 |
/// ) |
| 634 |
/// .unwrap(); |
| 635 |
/// let dt = DateTime { date: Date::try_new_iso(2024, 5, 17).unwrap(), time: Time::try_new(15, 47, 50, 0).unwrap() }; |
| 636 |
/// |
| 637 |
/// assert_writeable_eq!( |
| 638 |
/// fmt.format(&dt), |
| 639 |
#[doc = concat!(" \"", $sample_time, "\"")] |
| 640 |
/// ); |
| 641 |
/// ``` |
| 642 |
/// |
| 643 |
/// In [`FixedCalendarDateTimeFormatter`](crate::neo::FixedCalendarDateTimeFormatter): |
| 644 |
/// |
| 645 |
/// ``` |
| 646 |
/// use icu::datetime::input::Date; |
| 647 |
/// use icu::calendar::Gregorian; |
| 648 |
/// use icu::datetime::FixedCalendarDateTimeFormatter; |
| 649 |
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type_time), ";")] |
| 650 |
/// use icu::locale::locale; |
| 651 |
/// use icu::datetime::input::{DateTime, Time}; |
| 652 |
/// use writeable::assert_writeable_eq; |
| 653 |
/// |
| 654 |
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::try_new(")] |
| 655 |
/// locale!("en").into(), |
| 656 |
#[doc = concat!(" ", length_option_helper!($type_time, $sample_length), ",")] |
| 657 |
/// ) |
| 658 |
/// .unwrap(); |
| 659 |
/// let dt = DateTime { date: Date::try_new_gregorian(2024, 5, 17).unwrap(), time: Time::try_new(15, 47, 50, 0).unwrap() }; |
| 660 |
/// |
| 661 |
/// assert_writeable_eq!( |
| 662 |
/// fmt.format(&dt), |
| 663 |
#[doc = concat!(" \"", $sample_time, "\"")] |
| 664 |
/// ); |
| 665 |
/// ``` |
| 666 |
$(#[$attr])* |
| 667 |
$type_time, |
| 668 |
sample_length: $sample_length, |
| 669 |
date_fields: Some(builder::DateFields::$type), |
| 670 |
alignment: yes, |
| 671 |
$(year_style: $year_yes,)? |
| 672 |
time_precision: yes, |
| 673 |
); |
| 674 |
impl_marker_length_constructors!( |
| 675 |
$type_time, |
| 676 |
alignment: yes, |
| 677 |
$(year_style: $year_yes,)? |
| 678 |
time_precision: yes, |
| 679 |
); |
| 680 |
impl_zone_combo_helpers!($type_time, DateTimeZone, DateAndTimeFieldSet); |
| 681 |
impl UnstableSealed for $type_time {} |
| 682 |
impl DateTimeNamesMarker for $type_time { |
| 683 |
type YearNames = datetime_marker_helper!(@names/year, $($years_yes)?); |
| 684 |
type MonthNames = datetime_marker_helper!(@names/month, $($months_yes)?); |
| 685 |
type WeekdayNames = datetime_marker_helper!(@names/weekday, $($weekdays_yes)?); |
| 686 |
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod, yes); |
| 687 |
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,); |
| 688 |
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,); |
| 689 |
type ZoneLocationsRoot = datetime_marker_helper!(@names/zone/locations_root,); |
| 690 |
type ZoneExemplars = datetime_marker_helper!(@names/zone/exemplar,); |
| 691 |
type ZoneExemplarsRoot = datetime_marker_helper!(@names/zone/exemplar_root,); |
| 692 |
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,); |
| 693 |
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,); |
| 694 |
type ZoneStandardLong = datetime_marker_helper!(@names/zone/standard_long,); |
| 695 |
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,); |
| 696 |
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,); |
| 697 |
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,); |
| 698 |
} |
| 699 |
impl DateInputMarkers for $type_time { |
| 700 |
type YearInput = datetime_marker_helper!(@input/year, $($year_yes)?); |
| 701 |
type MonthInput = datetime_marker_helper!(@input/month, $($month_yes)?); |
| 702 |
type DayOfMonthInput = datetime_marker_helper!(@input/day_of_month, $($day_of_month_yes)?); |
| 703 |
type DayOfYearInput = datetime_marker_helper!(@input/day_of_year, $($day_of_year_yes)?); |
| 704 |
type RataDieInput = datetime_marker_helper!(@input/rata_die, $($rata_die_yes)?); |
| 705 |
type DayOfWeekInput = datetime_marker_helper!(@input/weekday, $($weekday_yes)?); |
| 706 |
} |
| 707 |
impl<C: CldrCalendar> TypedDateDataMarkers<C> for $type_time { |
| 708 |
type DateSkeletonPatternsV1 = datetime_marker_helper!(@dates/typed, yes); |
| 709 |
type DateRangeSkeletonPatternsV1 = datetime_marker_helper!(@dates/range/typed, yes); |
| 710 |
type YearNamesV1 = datetime_marker_helper!(@years/typed, $($years_yes)?); |
| 711 |
type MonthNamesV1 = datetime_marker_helper!(@months/typed, $($months_yes)?); |
| 712 |
type WeekdayNamesV1 = datetime_marker_helper!(@weekdays, $($weekdays_yes)?); |
| 713 |
} |
| 714 |
impl DateDataMarkers for $type_time { |
| 715 |
type Skel = datetime_marker_helper!(@calmarkers, yes); |
| 716 |
type RangeSkel = datetime_marker_helper!(@calmarkers, yes); |
| 717 |
type Year = datetime_marker_helper!(@calmarkers, $($years_yes)?); |
| 718 |
type Month = datetime_marker_helper!(@calmarkers, $($months_yes)?); |
| 719 |
type WeekdayNamesV1 = datetime_marker_helper!(@weekdays, $($weekdays_yes)?); |
| 720 |
} |
| 721 |
impl TimeMarkers for $type_time { |
| 722 |
// TODO(#6497): Consider making dayperiods optional |
| 723 |
type DayPeriodNamesV1 = datetime_marker_helper!(@dayperiods, yes); |
| 724 |
type TimeSkeletonPatternsV1 = datetime_marker_helper!(@times, yes); |
| 725 |
type TimeRangeSkeletonPatternsV1 = datetime_marker_helper!(@times/range, yes); |
| 726 |
type HourInput = datetime_marker_helper!(@input/hour, yes); |
| 727 |
type MinuteInput = datetime_marker_helper!(@input/minute, yes); |
| 728 |
type SecondInput = datetime_marker_helper!(@input/second, yes); |
| 729 |
type NanosecondInput = datetime_marker_helper!(@input/Nanosecond, yes); |
| 730 |
} |
| 731 |
impl DateTimeMarkers for $type_time { |
| 732 |
type D = Self; |
| 733 |
type T = Self; |
| 734 |
type Z = (); |
| 735 |
type GluePatternV1 = datetime_marker_helper!(@glue, yes); |
| 736 |
} |
| 737 |
impl_composite!($type_time, DateTime, DateAndTimeFieldSet); |
| 738 |
impl $type_time { |
| 739 |
pub(crate) fn to_date_field_set(self) -> $type { |
| 740 |
$type { |
| 741 |
length: self.length, |
| 742 |
$(alignment: yes_to!(self.alignment, $option_alignment_yes),)? |
| 743 |
$(year_style: yes_to!(self.year_style, $years_yes),)? |
| 744 |
} |
| 745 |
} |
| 746 |
} |
| 747 |
}; |
| 748 |
} |
| 749 |
|
| 750 |
/// Implements a field set of calendar period fields. |
| 751 |
/// |
| 752 |
/// Several arguments to this macro are required, and the rest are optional. |
| 753 |
/// The optional arguments should be written as `key = yes,` if that parameter |
| 754 |
/// should be included. |
| 755 |
/// |
| 756 |
/// See [`impl_date_marker`]. |
| 757 |
macro_rules! impl_calendar_period_marker { |
| 758 |
( |
| 759 |
$(#[$attr:meta])* |
| 760 |
$type:ident, |
| 761 |
description = $description:literal, |
| 762 |
sample_length = $sample_length:ident, |
| 763 |
sample = $sample:literal, |
| 764 |
$(years = $years_yes:ident,)? |
| 765 |
$(months = $months_yes:ident,)? |
| 766 |
$(dates = $dates_yes:ident,)? |
| 767 |
$(input_year = $year_yes:ident,)? |
| 768 |
$(input_month = $month_yes:ident,)? |
| 769 |
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)? |
| 770 |
$(option_alignment = $option_alignment_yes:ident,)? |
| 771 |
) => { |
| 772 |
impl_date_or_calendar_period_marker!( |
| 773 |
$(#[$attr])* |
| 774 |
$type, |
| 775 |
description = $description, |
| 776 |
sample_length = $sample_length, |
| 777 |
sample = $sample, |
| 778 |
$(years = $years_yes,)? |
| 779 |
$(months = $months_yes,)? |
| 780 |
$(dates = $dates_yes,)? |
| 781 |
$(input_year = $year_yes,)? |
| 782 |
$(input_month = $month_yes,)? |
| 783 |
$(input_any_calendar_kind = $any_calendar_kind_yes,)? |
| 784 |
$(option_alignment = $option_alignment_yes,)? |
| 785 |
); |
| 786 |
impl_composite!($type, CalendarPeriod, CalendarPeriodFieldSet); |
| 787 |
}; |
| 788 |
} |
| 789 |
|
| 790 |
/// Implements a field set of time fields. |
| 791 |
/// |
| 792 |
/// Several arguments to this macro are required, and the rest are optional. |
| 793 |
/// The optional arguments should be written as `key = yes,` if that parameter |
| 794 |
/// should be included. |
| 795 |
/// |
| 796 |
/// Documentation for each option is shown inline below. |
| 797 |
macro_rules! impl_time_marker { |
| 798 |
( |
| 799 |
$(#[$attr:meta])* |
| 800 |
// The name of the type being created. |
| 801 |
$type:ident, |
| 802 |
// A plain language description of the field set for documentation. |
| 803 |
description = $description:literal, |
| 804 |
// Length of the sample string below. |
| 805 |
sample_length = $sample_length:ident, |
| 806 |
// A sample string. A docs test will be generated! |
| 807 |
sample = $sample:literal, |
| 808 |
// Whether day periods can occur. |
| 809 |
$(dayperiods = $dayperiods_yes:ident,)? |
| 810 |
// Whether the input should include hours. |
| 811 |
$(input_hour = $hour_yes:ident,)? |
| 812 |
// Whether the input should contain minutes. |
| 813 |
$(input_minute = $minute_yes:ident,)? |
| 814 |
// Whether the input should contain seconds. |
| 815 |
$(input_second = $second_yes:ident,)? |
| 816 |
// Whether the input should contain fractional seconds. |
| 817 |
$(input_subsecond = $Nanosecond_yes:ident,)? |
| 818 |
) => { |
| 819 |
impl_marker_with_options!( |
| 820 |
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)] |
| 821 |
/// |
| 822 |
/// # Examples |
| 823 |
/// |
| 824 |
/// ``` |
| 825 |
/// use icu::datetime::input::Time; |
| 826 |
/// use icu::datetime::NoCalendarFormatter; |
| 827 |
#[doc = concat!("use icu::datetime::fieldsets::", stringify!($type), ";")] |
| 828 |
/// use icu::locale::locale; |
| 829 |
/// use writeable::assert_writeable_eq; |
| 830 |
/// |
| 831 |
#[doc = concat!("let fmt = NoCalendarFormatter::try_new(")] |
| 832 |
/// locale!("en").into(), |
| 833 |
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")] |
| 834 |
/// ) |
| 835 |
/// .unwrap(); |
| 836 |
/// let time = Time::try_new(15, 47, 50, 0).unwrap(); |
| 837 |
/// |
| 838 |
/// assert_writeable_eq!( |
| 839 |
/// fmt.format(&time), |
| 840 |
#[doc = concat!(" \"", $sample, "\"")] |
| 841 |
/// ); |
| 842 |
/// ``` |
| 843 |
$(#[$attr])* |
| 844 |
$type, |
| 845 |
sample_length: $sample_length, |
| 846 |
alignment: yes, |
| 847 |
time_precision: yes, |
| 848 |
); |
| 849 |
impl_marker_length_constructors!( |
| 850 |
$type, |
| 851 |
alignment: yes, |
| 852 |
time_precision: yes, |
| 853 |
); |
| 854 |
impl_time_precision_constructors!( |
| 855 |
$type, |
| 856 |
); |
| 857 |
impl_zone_combo_helpers!($type, TimeZone, TimeFieldSet); |
| 858 |
impl UnstableSealed for $type {} |
| 859 |
impl DateTimeNamesMarker for $type { |
| 860 |
type YearNames = datetime_marker_helper!(@names/year,); |
| 861 |
type MonthNames = datetime_marker_helper!(@names/month,); |
| 862 |
type WeekdayNames = datetime_marker_helper!(@names/weekday,); |
| 863 |
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod, $($dayperiods_yes)?); |
| 864 |
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,); |
| 865 |
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,); |
| 866 |
type ZoneLocationsRoot = datetime_marker_helper!(@names/zone/locations_root,); |
| 867 |
type ZoneExemplars = datetime_marker_helper!(@names/zone/exemplar,); |
| 868 |
type ZoneExemplarsRoot = datetime_marker_helper!(@names/zone/exemplar_root,); |
| 869 |
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,); |
| 870 |
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,); |
| 871 |
type ZoneStandardLong = datetime_marker_helper!(@names/zone/standard_long,); |
| 872 |
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,); |
| 873 |
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,); |
| 874 |
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,); |
| 875 |
} |
| 876 |
impl TimeMarkers for $type { |
| 877 |
type DayPeriodNamesV1 = datetime_marker_helper!(@dayperiods, $($dayperiods_yes)?); |
| 878 |
type TimeSkeletonPatternsV1 = datetime_marker_helper!(@times, yes); |
| 879 |
type TimeRangeSkeletonPatternsV1 = datetime_marker_helper!(@times/range, yes); |
| 880 |
type HourInput = datetime_marker_helper!(@input/hour, $($hour_yes)?); |
| 881 |
type MinuteInput = datetime_marker_helper!(@input/minute, $($minute_yes)?); |
| 882 |
type SecondInput = datetime_marker_helper!(@input/second, $($second_yes)?); |
| 883 |
type NanosecondInput = datetime_marker_helper!(@input/Nanosecond, $($Nanosecond_yes)?); |
| 884 |
} |
| 885 |
impl DateTimeMarkers for $type { |
| 886 |
type D = (); |
| 887 |
type T = Self; |
| 888 |
type Z = (); |
| 889 |
type GluePatternV1 = datetime_marker_helper!(@glue,); |
| 890 |
} |
| 891 |
impl_composite!($type, Time, TimeFieldSet); |
| 892 |
}; |
| 893 |
} |
| 894 |
|
| 895 |
/// Implements a field set of time zone fields. |
| 896 |
/// |
| 897 |
/// Several arguments to this macro are required, and the rest are optional. |
| 898 |
/// The optional arguments should be written as `key = yes,` if that parameter |
| 899 |
/// should be included. |
| 900 |
/// |
| 901 |
/// Documentation for each option is shown inline below. |
| 902 |
macro_rules! impl_zone_marker { |
| 903 |
( |
| 904 |
$(#[$attr:meta])* |
| 905 |
// The name of the type being created. |
| 906 |
$type:ident, |
| 907 |
// A plain language description of the field set for documentation. |
| 908 |
description = $description:literal, |
| 909 |
// Length of the skeleton if this is the only field. |
| 910 |
length_override = $length_override:ident, |
| 911 |
// A sample string. A docs test will be generated! |
| 912 |
sample = $sample:literal, |
| 913 |
// The field symbol and field length. |
| 914 |
field = $field:expr, |
| 915 |
// The type in ZoneFieldSet for this field set |
| 916 |
// Whether zone-essentials should be loaded. |
| 917 |
$(zone_essentials = $zone_essentials_yes:ident,)? |
| 918 |
// Whether locations names are needed. |
| 919 |
$(zone_locations = $zone_locations_yes:ident,)? |
| 920 |
// Whether exemplar city names are needed. |
| 921 |
$(zone_exemplars = $zone_exemplars_yes:ident,)? |
| 922 |
// Whether generic long names are needed. |
| 923 |
$(zone_generic_long = $zone_generic_long_yes:ident,)? |
| 924 |
// Whether generic short names are needed. |
| 925 |
$(zone_generic_short = $zone_generic_short_yes:ident,)? |
| 926 |
// Whether standard long names are needed. |
| 927 |
$(zone_standard_long = $zone_standard_long_yes:ident,)? |
| 928 |
// Whether specific long names are needed. |
| 929 |
$(zone_specific_long = $zone_specific_long_yes:ident,)? |
| 930 |
// Whether specific short names are needed. |
| 931 |
$(zone_specific_short = $zone_specific_short_yes:ident,)? |
| 932 |
// Whether metazone periods are needed |
| 933 |
$(metazone_periods = $metazone_periods_yes:ident,)? |
| 934 |
// Whether to require the TimeZone |
| 935 |
$(input_tzid = $tzid_input_yes:ident,)? |
| 936 |
// Whether to require the Timestamp |
| 937 |
$(input_timestamp = $timestamp_input_yes:ident,)? |
| 938 |
) => { |
| 939 |
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)] |
| 940 |
/// |
| 941 |
/// # Examples |
| 942 |
/// |
| 943 |
/// ``` |
| 944 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 945 |
/// use icu::datetime::NoCalendarFormatter; |
| 946 |
#[doc = concat!("use icu::datetime::fieldsets::zone::", stringify!($type), ";")] |
| 947 |
/// use icu::locale::locale; |
| 948 |
/// use writeable::assert_writeable_eq; |
| 949 |
/// |
| 950 |
/// let fmt = NoCalendarFormatter::try_new( |
| 951 |
/// locale!("en").into(), |
| 952 |
#[doc = concat!(" ", stringify!($type))] |
| 953 |
/// ) |
| 954 |
/// .unwrap(); |
| 955 |
/// |
| 956 |
/// // Time zone info for America/Chicago in the summer |
| 957 |
/// let zone = TimeZone::from_iana_id("America/Chicago") |
| 958 |
/// .with_offset(UtcOffset::try_from_seconds(-5 * 3600).ok()) |
| 959 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1661724000)); |
| 960 |
/// |
| 961 |
/// assert_writeable_eq!( |
| 962 |
/// fmt.format(&zone), |
| 963 |
#[doc = concat!(" \"", $sample, "\"")] |
| 964 |
/// ); |
| 965 |
/// ``` |
| 966 |
$(#[$attr])* |
| 967 |
#[derive(Debug, Copy, Clone, PartialEq, Eq)] |
| 968 |
#[allow(clippy::exhaustive_structs)] // singleton marker |
| 969 |
pub struct $type; |
| 970 |
impl UnstableSealed for $type {} |
| 971 |
impl DateTimeNamesMarker for $type { |
| 972 |
type YearNames = datetime_marker_helper!(@names/year,); |
| 973 |
type MonthNames = datetime_marker_helper!(@names/month,); |
| 974 |
type WeekdayNames = datetime_marker_helper!(@names/weekday,); |
| 975 |
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod,); |
| 976 |
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials, $($zone_essentials_yes)?); |
| 977 |
type ZoneLocations = datetime_marker_helper!(@names/zone/locations, $($zone_locations_yes)?); |
| 978 |
type ZoneLocationsRoot = datetime_marker_helper!(@names/zone/locations_root, $($zone_locations_yes)?); |
| 979 |
type ZoneExemplars = datetime_marker_helper!(@names/zone/exemplars, $($zone_exemplars_yes)?); |
| 980 |
type ZoneExemplarsRoot = datetime_marker_helper!(@names/zone/exemplars_root, $($zone_exemplars_yes)?); |
| 981 |
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long, $($zone_generic_long_yes)?); |
| 982 |
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short, $($zone_generic_short_yes)?); |
| 983 |
type ZoneStandardLong = datetime_marker_helper!(@names/zone/standard_long, $($zone_standard_long_yes)?); |
| 984 |
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long, $($zone_specific_long_yes)?); |
| 985 |
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short, $($zone_specific_short_yes)?); |
| 986 |
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods, $($metazone_periods_yes)?); |
| 987 |
} |
| 988 |
impl ZoneMarkers for $type { |
| 989 |
type TimeZoneIdInput = datetime_marker_helper!(@input/timezone/id, $($tzid_input_yes)?); |
| 990 |
type TimeZoneOffsetInput = datetime_marker_helper!(@input/timezone/offset, yes); |
| 991 |
type TimeZoneNameTimestampInput = datetime_marker_helper!(@input/timezone/timestamp, $($timestamp_input_yes)?); |
| 992 |
type EssentialsV1 = datetime_marker_helper!(@data/zone/essentials, $($zone_essentials_yes)?); |
| 993 |
type LocationsV1 = datetime_marker_helper!(@data/zone/locations, $($zone_locations_yes)?); |
| 994 |
type LocationsRootV1 = datetime_marker_helper!(@data/zone/locations_root, $($zone_locations_yes)?); |
| 995 |
type ExemplarCitiesV1 = datetime_marker_helper!(@data/zone/exemplars, $($zone_exemplars_yes)?); |
| 996 |
type ExemplarCitiesRootV1 = datetime_marker_helper!(@data/zone/exemplars_root, $($zone_exemplars_yes)?); |
| 997 |
type GenericLongV1 = datetime_marker_helper!(@data/zone/generic_long, $($zone_generic_long_yes)?); |
| 998 |
type GenericShortV1 = datetime_marker_helper!(@data/zone/generic_short, $($zone_generic_short_yes)?); |
| 999 |
type StandardLongV1 = datetime_marker_helper!(@data/zone/standard_long, $($zone_standard_long_yes)?); |
| 1000 |
type SpecificLongV1 = datetime_marker_helper!(@data/zone/specific_long, $($zone_specific_long_yes)?); |
| 1001 |
type SpecificShortV1 = datetime_marker_helper!(@data/zone/specific_short, $($zone_specific_short_yes)?); |
| 1002 |
type MetazonePeriodV1 = datetime_marker_helper!(@data/zone/metazone_periods, $($metazone_periods_yes)?); |
| 1003 |
} |
| 1004 |
impl DateTimeMarkers for $type { |
| 1005 |
type D = (); |
| 1006 |
type T = (); |
| 1007 |
type Z = Self; |
| 1008 |
type GluePatternV1 = datetime_marker_helper!(@glue,); |
| 1009 |
} |
| 1010 |
impl_composite!($type, Zone, ZoneFieldSet); |
| 1011 |
impl $type { |
| 1012 |
pub(crate) fn to_field(self) -> (fields::TimeZone, fields::FieldLength) { |
| 1013 |
$field |
| 1014 |
} |
| 1015 |
} |
| 1016 |
}; |
| 1017 |
} |
| 1018 |
|
| 1019 |
impl_date_marker!( |
| 1020 |
/// This format may use ordinal formatting, such as "the 17th", |
| 1021 |
/// in the future. See CLDR-18040. |
| 1022 |
D, |
| 1023 |
DT, |
| 1024 |
description = "day of month (standalone)", |
| 1025 |
sample_length = short, |
| 1026 |
sample = "17", |
| 1027 |
sample_time = "17, 3:47:50 PM", |
| 1028 |
input_day_of_month = yes, |
| 1029 |
input_any_calendar_kind = yes, |
| 1030 |
option_alignment = yes, |
| 1031 |
); |
| 1032 |
|
| 1033 |
impl_date_marker!( |
| 1034 |
/// Format a weekday using [`Weekday`]: |
| 1035 |
/// |
| 1036 |
/// ``` |
| 1037 |
/// use icu::calendar::Gregorian; |
| 1038 |
/// use icu::calendar::types::Weekday; |
| 1039 |
/// use icu::datetime::fieldsets; |
| 1040 |
/// use icu::datetime::FixedCalendarDateTimeFormatter; |
| 1041 |
/// use icu::locale::locale; |
| 1042 |
/// use writeable::assert_writeable_eq; |
| 1043 |
/// |
| 1044 |
/// let formatter = FixedCalendarDateTimeFormatter::<Gregorian, _>::try_new( |
| 1045 |
/// locale!("fr").into(), |
| 1046 |
/// fieldsets::E::long(), |
| 1047 |
/// ).unwrap(); |
| 1048 |
/// |
| 1049 |
/// assert_writeable_eq!( |
| 1050 |
/// formatter.format(&Weekday::Monday), |
| 1051 |
/// "lundi" |
| 1052 |
/// ); |
| 1053 |
/// ``` |
| 1054 |
E, |
| 1055 |
ET, |
| 1056 |
description = "weekday (standalone)", |
| 1057 |
sample_length = long, |
| 1058 |
sample = "Friday", |
| 1059 |
sample_time = "Friday 3:47:50 PM", |
| 1060 |
weekdays = yes, |
| 1061 |
input_weekday = yes, |
| 1062 |
); |
| 1063 |
|
| 1064 |
impl_date_marker!( |
| 1065 |
/// This format may use ordinal formatting, such as "Friday the 17th", |
| 1066 |
/// in the future. See CLDR-18040. |
| 1067 |
DE, |
| 1068 |
DET, |
| 1069 |
description = "day of month and weekday", |
| 1070 |
sample_length = long, |
| 1071 |
sample = "17 Friday", |
| 1072 |
sample_time = "17 Friday at 3:47:50 PM", |
| 1073 |
weekdays = yes, |
| 1074 |
input_day_of_month = yes, |
| 1075 |
input_weekday = yes, |
| 1076 |
option_alignment = yes, |
| 1077 |
); |
| 1078 |
|
| 1079 |
impl_date_marker!( |
| 1080 |
MD, |
| 1081 |
MDT, |
| 1082 |
description = "month and day", |
| 1083 |
sample_length = medium, |
| 1084 |
sample = "May 17", |
| 1085 |
sample_time = "May 17, 3:47:50 PM", |
| 1086 |
months = yes, |
| 1087 |
input_month = yes, |
| 1088 |
input_day_of_month = yes, |
| 1089 |
input_any_calendar_kind = yes, |
| 1090 |
option_alignment = yes, |
| 1091 |
); |
| 1092 |
|
| 1093 |
impl_date_marker!( |
| 1094 |
/// See CLDR-18040 for progress on improving this format. |
| 1095 |
MDE, |
| 1096 |
MDET, |
| 1097 |
description = "month, day, and weekday", |
| 1098 |
sample_length = medium, |
| 1099 |
sample = "Fri, May 17", |
| 1100 |
sample_time = "Fri, May 17, 3:47:50 PM", |
| 1101 |
months = yes, |
| 1102 |
weekdays = yes, |
| 1103 |
input_month = yes, |
| 1104 |
input_day_of_month = yes, |
| 1105 |
input_weekday = yes, |
| 1106 |
input_any_calendar_kind = yes, |
| 1107 |
option_alignment = yes, |
| 1108 |
); |
| 1109 |
|
| 1110 |
impl_date_marker!( |
| 1111 |
YMD, |
| 1112 |
YMDT, |
| 1113 |
description = "year, month, and day", |
| 1114 |
sample_length = short, |
| 1115 |
sample = "5/17/24", |
| 1116 |
sample_time = "5/17/24, 3:47:50 PM", |
| 1117 |
years = yes, |
| 1118 |
months = yes, |
| 1119 |
input_year = yes, |
| 1120 |
input_month = yes, |
| 1121 |
input_day_of_month = yes, |
| 1122 |
input_any_calendar_kind = yes, |
| 1123 |
option_alignment = yes, |
| 1124 |
); |
| 1125 |
|
| 1126 |
impl_date_marker!( |
| 1127 |
YMDE, |
| 1128 |
YMDET, |
| 1129 |
description = "year, month, day, and weekday", |
| 1130 |
sample_length = short, |
| 1131 |
sample = "Fri, 5/17/24", |
| 1132 |
sample_time = "Fri, 5/17/24, 3:47:50 PM", |
| 1133 |
years = yes, |
| 1134 |
months = yes, |
| 1135 |
weekdays = yes, |
| 1136 |
input_year = yes, |
| 1137 |
input_month = yes, |
| 1138 |
input_day_of_month = yes, |
| 1139 |
input_weekday = yes, |
| 1140 |
input_any_calendar_kind = yes, |
| 1141 |
option_alignment = yes, |
| 1142 |
); |
| 1143 |
|
| 1144 |
impl_calendar_period_marker!( |
| 1145 |
Y, |
| 1146 |
description = "year (standalone)", |
| 1147 |
sample_length = medium, |
| 1148 |
sample = "2024", |
| 1149 |
years = yes, |
| 1150 |
input_year = yes, |
| 1151 |
input_any_calendar_kind = yes, |
| 1152 |
option_alignment = yes, |
| 1153 |
); |
| 1154 |
|
| 1155 |
impl_calendar_period_marker!( |
| 1156 |
M, |
| 1157 |
description = "month (standalone)", |
| 1158 |
sample_length = long, |
| 1159 |
sample = "May", |
| 1160 |
months = yes, |
| 1161 |
input_month = yes, |
| 1162 |
input_any_calendar_kind = yes, |
| 1163 |
option_alignment = yes, |
| 1164 |
); |
| 1165 |
|
| 1166 |
impl_calendar_period_marker!( |
| 1167 |
YM, |
| 1168 |
description = "year and month", |
| 1169 |
sample_length = medium, |
| 1170 |
sample = "May 2024", |
| 1171 |
years = yes, |
| 1172 |
months = yes, |
| 1173 |
input_year = yes, |
| 1174 |
input_month = yes, |
| 1175 |
input_any_calendar_kind = yes, |
| 1176 |
option_alignment = yes, |
| 1177 |
); |
| 1178 |
|
| 1179 |
#[cfg(doc)] |
| 1180 |
use crate::preferences::HourCycle; |
| 1181 |
|
| 1182 |
impl_time_marker!( |
| 1183 |
/// Hours can be switched between 12-hour and 24-hour time via [`HourCycle::Clock12`] |
| 1184 |
/// or [`HourCycle::Clock24`] on [`DateTimeFormatterPreferences`] or via the `u-hc` |
| 1185 |
/// locale keyword. |
| 1186 |
/// |
| 1187 |
/// ``` |
| 1188 |
/// use icu::datetime::DateTimeFormatterPreferences; |
| 1189 |
/// use icu::datetime::fieldsets::T; |
| 1190 |
/// use icu::datetime::input::Time; |
| 1191 |
/// use icu::datetime::NoCalendarFormatter; |
| 1192 |
/// use icu::datetime::preferences::HourCycle; |
| 1193 |
/// use icu::locale::locale; |
| 1194 |
/// use writeable::assert_writeable_eq; |
| 1195 |
/// |
| 1196 |
/// let time_midnight = Time::try_new(0, 20, 30, 0).unwrap(); |
| 1197 |
/// let time_afternoon = Time::try_new(16, 12, 20, 0).unwrap(); |
| 1198 |
/// |
| 1199 |
/// let prefs_en_us = DateTimeFormatterPreferences::from(locale!("en-US")); |
| 1200 |
/// let prefs_ja_jp = DateTimeFormatterPreferences::from(locale!("ja-JP")); |
| 1201 |
/// |
| 1202 |
/// // By default, en-US uses 12-hour time and ja-JP uses 24-hour time, |
| 1203 |
/// // but we can set overrides. |
| 1204 |
/// |
| 1205 |
/// let formatter = NoCalendarFormatter::try_new(prefs_en_us, T::hm()).unwrap(); |
| 1206 |
/// assert_writeable_eq!( |
| 1207 |
/// formatter.format(&time_midnight), |
| 1208 |
/// "12:20 AM" |
| 1209 |
/// ); |
| 1210 |
/// assert_writeable_eq!( |
| 1211 |
/// formatter.format(&time_afternoon), |
| 1212 |
/// "4:12 PM" |
| 1213 |
/// ); |
| 1214 |
/// |
| 1215 |
/// let formatter = NoCalendarFormatter::try_new({ |
| 1216 |
/// let mut prefs = prefs_en_us; |
| 1217 |
/// prefs.hour_cycle = Some(HourCycle::Clock24); |
| 1218 |
/// prefs |
| 1219 |
/// }, T::hm()) |
| 1220 |
/// .unwrap(); |
| 1221 |
/// assert_writeable_eq!( |
| 1222 |
/// formatter.format(&time_midnight), |
| 1223 |
/// "00:20" |
| 1224 |
/// ); |
| 1225 |
/// assert_writeable_eq!( |
| 1226 |
/// formatter.format(&time_afternoon), |
| 1227 |
/// "16:12" |
| 1228 |
/// ); |
| 1229 |
/// |
| 1230 |
/// let formatter = NoCalendarFormatter::try_new(prefs_ja_jp, T::hm()).unwrap(); |
| 1231 |
/// assert_writeable_eq!( |
| 1232 |
/// formatter.format(&time_midnight), |
| 1233 |
/// "0:20" |
| 1234 |
/// ); |
| 1235 |
/// assert_writeable_eq!( |
| 1236 |
/// formatter.format(&time_afternoon), |
| 1237 |
/// "16:12" |
| 1238 |
/// ); |
| 1239 |
/// |
| 1240 |
/// let formatter = NoCalendarFormatter::try_new({ |
| 1241 |
/// let mut prefs = prefs_ja_jp; |
| 1242 |
/// prefs.hour_cycle = Some(HourCycle::Clock12); |
| 1243 |
/// prefs |
| 1244 |
/// }, T::hm()) |
| 1245 |
/// .unwrap(); |
| 1246 |
/// // Japan uses 0 instead of 12 for midnight and noon. |
| 1247 |
/// assert_writeable_eq!( |
| 1248 |
/// formatter.format(&time_midnight), |
| 1249 |
/// "午前0:20" |
| 1250 |
/// ); |
| 1251 |
/// assert_writeable_eq!( |
| 1252 |
/// formatter.format(&time_afternoon), |
| 1253 |
/// "午後4:12" |
| 1254 |
/// ); |
| 1255 |
/// ``` |
| 1256 |
/// |
| 1257 |
/// Hour cycles `h11`, `h12`, and `h23` are supported, too: |
| 1258 |
/// |
| 1259 |
/// ``` |
| 1260 |
/// use icu::datetime::input::Time; |
| 1261 |
/// use icu::datetime::fieldsets::T; |
| 1262 |
/// use icu::datetime::NoCalendarFormatter; |
| 1263 |
/// use icu::locale::locale; |
| 1264 |
/// use writeable::assert_writeable_eq; |
| 1265 |
/// |
| 1266 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1267 |
/// locale!("und-u-hc-h11").into(), |
| 1268 |
/// T::hm(), |
| 1269 |
/// ) |
| 1270 |
/// .unwrap(); |
| 1271 |
/// |
| 1272 |
/// assert_writeable_eq!( |
| 1273 |
/// formatter.format(&Time::try_new(0, 0, 0, 0).unwrap()), |
| 1274 |
/// "0:00 AM" |
| 1275 |
/// ); |
| 1276 |
/// |
| 1277 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1278 |
/// locale!("und-u-hc-h12").into(), |
| 1279 |
/// T::hm(), |
| 1280 |
/// ) |
| 1281 |
/// .unwrap(); |
| 1282 |
/// |
| 1283 |
/// assert_writeable_eq!( |
| 1284 |
/// formatter.format(&Time::try_new(0, 0, 0, 0).unwrap()), |
| 1285 |
/// "12:00 AM" |
| 1286 |
/// ); |
| 1287 |
/// |
| 1288 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1289 |
/// locale!("und-u-hc-h23").into(), |
| 1290 |
/// T::hm(), |
| 1291 |
/// ) |
| 1292 |
/// .unwrap(); |
| 1293 |
/// |
| 1294 |
/// assert_writeable_eq!( |
| 1295 |
/// formatter.format(&Time::try_new(0, 0, 0, 0).unwrap()), |
| 1296 |
/// "00:00" |
| 1297 |
/// ); |
| 1298 |
/// ``` |
| 1299 |
/// |
| 1300 |
/// Conveniently construct a time formatter with subseconds: |
| 1301 |
/// |
| 1302 |
/// ``` |
| 1303 |
/// use icu::datetime::input::Time; |
| 1304 |
/// use icu::datetime::fieldsets::T; |
| 1305 |
/// use icu::datetime::options::SubsecondDigits; |
| 1306 |
/// use icu::datetime::NoCalendarFormatter; |
| 1307 |
/// use icu::locale::locale; |
| 1308 |
/// use writeable::assert_writeable_eq; |
| 1309 |
/// |
| 1310 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1311 |
/// locale!("en").into(), |
| 1312 |
/// T::hmss(SubsecondDigits::S4), |
| 1313 |
/// ) |
| 1314 |
/// .unwrap(); |
| 1315 |
/// |
| 1316 |
/// assert_writeable_eq!( |
| 1317 |
/// formatter.format(&Time::try_new(18, 24, 36, 987654321).unwrap()), |
| 1318 |
/// "6:24:36.9876 PM" |
| 1319 |
/// ); |
| 1320 |
/// ``` |
| 1321 |
/// |
| 1322 |
/// [`DateTimeFormatterPreferences`]: crate::DateTimeFormatterPreferences |
| 1323 |
T, |
| 1324 |
description = "time (locale-dependent hour cycle)", |
| 1325 |
sample_length = medium, |
| 1326 |
sample = "3:47:50 PM", |
| 1327 |
dayperiods = yes, |
| 1328 |
input_hour = yes, |
| 1329 |
input_minute = yes, |
| 1330 |
input_second = yes, |
| 1331 |
input_subsecond = yes, |
| 1332 |
); |
| 1333 |
|
| 1334 |
/// Time zone field sets |
| 1335 |
pub mod zone { |
| 1336 |
use super::*; |
| 1337 |
impl_zone_marker!( |
| 1338 |
/// If a non-location name is not defined, falls back to the specific location format: |
| 1339 |
/// |
| 1340 |
/// ``` |
| 1341 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 1342 |
/// use icu::datetime::NoCalendarFormatter; |
| 1343 |
/// use icu::datetime::fieldsets::zone::SpecificLong; |
| 1344 |
/// use icu::locale::locale; |
| 1345 |
/// use writeable::assert_writeable_eq; |
| 1346 |
/// |
| 1347 |
/// // Time zone info for Europe/Istanbul in the winter |
| 1348 |
/// let zone = TimeZone::from_iana_id("Europe/Istanbul") |
| 1349 |
/// .with_offset(UtcOffset::try_from_seconds(3 * 3600).ok()) |
| 1350 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1643410800)); |
| 1351 |
/// |
| 1352 |
/// let fmt = NoCalendarFormatter::try_new( |
| 1353 |
/// locale!("en").into(), |
| 1354 |
/// SpecificLong, |
| 1355 |
/// ) |
| 1356 |
/// .unwrap(); |
| 1357 |
/// |
| 1358 |
/// assert_writeable_eq!( |
| 1359 |
/// fmt.format(&zone), |
| 1360 |
/// "Türkiye Standard Time" |
| 1361 |
/// ); |
| 1362 |
/// ``` |
| 1363 |
/// |
| 1364 |
/// If the offset doesn't match one of the valid offsets for the zone, falls back to the localized offset format: |
| 1365 |
/// ``` |
| 1366 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 1367 |
/// use icu::datetime::NoCalendarFormatter; |
| 1368 |
/// use icu::datetime::fieldsets::zone::SpecificLong; |
| 1369 |
/// use icu::locale::locale; |
| 1370 |
/// use writeable::assert_writeable_eq; |
| 1371 |
/// |
| 1372 |
/// // Time zone info for America/Chicago with a wrong offset |
| 1373 |
/// let wrong_offset = TimeZone::from_iana_id("America/Chicago") |
| 1374 |
/// .with_offset(UtcOffset::try_from_seconds(-4 * 3600).ok()) |
| 1375 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1661724000)); |
| 1376 |
/// |
| 1377 |
/// let fmt = NoCalendarFormatter::try_new( |
| 1378 |
/// locale!("en").into(), |
| 1379 |
/// SpecificLong, |
| 1380 |
/// ) |
| 1381 |
/// .unwrap(); |
| 1382 |
/// |
| 1383 |
/// assert_writeable_eq!( |
| 1384 |
/// fmt.format(&wrong_offset), |
| 1385 |
/// "GMT-04:00" |
| 1386 |
/// ); |
| 1387 |
/// |
| 1388 |
/// // This of course always happens for the unknown time zone |
| 1389 |
/// let unk = TimeZone::UNKNOWN.with_offset(wrong_offset.offset()).with_zone_name_timestamp(wrong_offset.zone_name_timestamp()); |
| 1390 |
/// |
| 1391 |
/// assert_writeable_eq!( |
| 1392 |
/// fmt.format(&unk), |
| 1393 |
/// "GMT-04:00" |
| 1394 |
/// ); |
| 1395 |
/// ``` |
| 1396 |
/// |
| 1397 |
/// Since non-location names might change over time, |
| 1398 |
/// this time zone style requires a reference time. |
| 1399 |
/// |
| 1400 |
/// ```compile_fail,E0271 |
| 1401 |
/// use icu::datetime::NoCalendarFormatter; |
| 1402 |
/// use icu::datetime::fieldsets::zone::SpecificLong; |
| 1403 |
/// use icu::locale::locale; |
| 1404 |
/// use icu::datetime::input::{TimeZone, UtcOffset}; |
| 1405 |
/// |
| 1406 |
/// let time_zone_basic = TimeZone::from_iana_id("America/Chicago").without_offset(); |
| 1407 |
/// |
| 1408 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1409 |
/// locale!("en-US").into(), |
| 1410 |
/// SpecificLong, |
| 1411 |
/// ) |
| 1412 |
/// .unwrap(); |
| 1413 |
/// |
| 1414 |
/// // error[E0271]: type mismatch resolving `<Base as TimeZoneModel>::ZoneNameTimestamp == ZoneNameTimestamp` |
| 1415 |
/// formatter.format(&time_zone_basic); |
| 1416 |
/// ``` |
| 1417 |
SpecificLong, |
| 1418 |
description = "time zone in specific non-location format, long length", |
| 1419 |
length_override = Long, |
| 1420 |
sample = "Central Daylight Time", |
| 1421 |
field = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::Four), |
| 1422 |
zone_essentials = yes, |
| 1423 |
zone_locations = yes, |
| 1424 |
zone_standard_long = yes, |
| 1425 |
zone_specific_long = yes, |
| 1426 |
metazone_periods = yes, |
| 1427 |
input_tzid = yes, |
| 1428 |
input_timestamp = yes, |
| 1429 |
); |
| 1430 |
|
| 1431 |
impl_zone_marker!( |
| 1432 |
/// If a non-location name is not defined, falls back to the localized offset format. |
| 1433 |
/// This is the case for most zones, as each locale only contains the short names that are |
| 1434 |
/// used locally and generally understood: |
| 1435 |
/// |
| 1436 |
/// ``` |
| 1437 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 1438 |
/// use icu::datetime::NoCalendarFormatter; |
| 1439 |
/// use icu::datetime::fieldsets::zone::SpecificShort; |
| 1440 |
/// use icu::locale::locale; |
| 1441 |
/// use writeable::assert_writeable_eq; |
| 1442 |
/// |
| 1443 |
/// // Time zone info for Asia/Tokyo |
| 1444 |
/// let zone = TimeZone::from_iana_id("Asia/Tokyo") |
| 1445 |
/// .with_offset(UtcOffset::try_from_seconds(9 * 3600).ok()) |
| 1446 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1643410800)); |
| 1447 |
/// |
| 1448 |
/// let fmt = NoCalendarFormatter::try_new( |
| 1449 |
/// locale!("en").into(), |
| 1450 |
/// SpecificShort, |
| 1451 |
/// ) |
| 1452 |
/// .unwrap(); |
| 1453 |
/// |
| 1454 |
/// // "JST" is not generally known in American English |
| 1455 |
/// assert_writeable_eq!( |
| 1456 |
/// fmt.format(&zone), |
| 1457 |
/// "GMT+9" |
| 1458 |
/// ); |
| 1459 |
/// ``` |
| 1460 |
/// |
| 1461 |
/// If the offset doesn't match one of the valid offsets for the zone, falls back to the localized offset format: |
| 1462 |
/// ``` |
| 1463 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 1464 |
/// use icu::datetime::NoCalendarFormatter; |
| 1465 |
/// use icu::datetime::fieldsets::zone::SpecificShort; |
| 1466 |
/// use icu::locale::locale; |
| 1467 |
/// use writeable::assert_writeable_eq; |
| 1468 |
/// |
| 1469 |
/// // Time zone info for America/Chicago with a wrong offset |
| 1470 |
/// let wrong_offset = TimeZone::from_iana_id("America/Chicago") |
| 1471 |
/// .with_offset(UtcOffset::try_from_seconds(-4 * 3600).ok()) |
| 1472 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1661724000)); |
| 1473 |
/// |
| 1474 |
/// let fmt = NoCalendarFormatter::try_new( |
| 1475 |
/// locale!("en").into(), |
| 1476 |
/// SpecificShort, |
| 1477 |
/// ) |
| 1478 |
/// .unwrap(); |
| 1479 |
/// |
| 1480 |
/// assert_writeable_eq!( |
| 1481 |
/// fmt.format(&wrong_offset), |
| 1482 |
/// "GMT-4" |
| 1483 |
/// ); |
| 1484 |
/// |
| 1485 |
/// // This of course always happens for the unknown time zone |
| 1486 |
/// let unk = TimeZone::UNKNOWN.with_offset(wrong_offset.offset()).with_zone_name_timestamp(wrong_offset.zone_name_timestamp()); |
| 1487 |
/// |
| 1488 |
/// assert_writeable_eq!( |
| 1489 |
/// fmt.format(&unk), |
| 1490 |
/// "GMT-4" |
| 1491 |
/// ); |
| 1492 |
/// ``` |
| 1493 |
/// |
| 1494 |
/// Since non-location names might change over time, |
| 1495 |
/// this time zone style requires a reference time. |
| 1496 |
/// |
| 1497 |
/// ```compile_fail,E0271 |
| 1498 |
/// use icu::datetime::NoCalendarFormatter; |
| 1499 |
/// use icu::datetime::fieldsets::zone::SpecificShort; |
| 1500 |
/// use icu::datetime::input::TimeZone; |
| 1501 |
/// use icu::locale::locale; |
| 1502 |
/// |
| 1503 |
/// let time_zone_basic = TimeZone::from_iana_id("America/Chicago").without_offset(); |
| 1504 |
/// |
| 1505 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1506 |
/// locale!("en-US").into(), |
| 1507 |
/// SpecificShort, |
| 1508 |
/// ) |
| 1509 |
/// .unwrap(); |
| 1510 |
/// |
| 1511 |
/// // error[E0271]: type mismatch resolving `<Base as TimeZoneModel>::ZoneNameTimestamp == ZoneNameTimestamp` |
| 1512 |
/// formatter.format(&time_zone_basic); |
| 1513 |
/// ``` |
| 1514 |
SpecificShort, |
| 1515 |
description = "time zone in specific non-location format, short length", |
| 1516 |
length_override = Short, |
| 1517 |
sample = "CDT", |
| 1518 |
field = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::One), |
| 1519 |
zone_essentials = yes, |
| 1520 |
zone_specific_short = yes, |
| 1521 |
metazone_periods = yes, |
| 1522 |
input_tzid = yes, |
| 1523 |
input_timestamp = yes, |
| 1524 |
); |
| 1525 |
|
| 1526 |
impl_zone_marker!( |
| 1527 |
/// All shapes of time zones can be formatted with this style. |
| 1528 |
/// |
| 1529 |
/// ``` |
| 1530 |
/// use icu::datetime::input::Date; |
| 1531 |
/// use icu::datetime::NoCalendarFormatter; |
| 1532 |
/// use icu::datetime::fieldsets::zone::LocalizedOffsetLong; |
| 1533 |
/// use icu::datetime::input::{DateTime, Time, TimeZone, UtcOffset}; |
| 1534 |
/// use icu::locale::locale; |
| 1535 |
/// use writeable::assert_writeable_eq; |
| 1536 |
/// |
| 1537 |
/// let utc_offset = UtcOffset::try_from_seconds(-6 * 3600).unwrap(); |
| 1538 |
/// let time_zone_basic = TimeZone::from_iana_id("America/Chicago").with_offset(Some(utc_offset)); |
| 1539 |
/// |
| 1540 |
/// let time_zone_at_time = time_zone_basic.with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1729202400)); |
| 1541 |
/// |
| 1542 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1543 |
/// locale!("en-US").into(), |
| 1544 |
/// LocalizedOffsetLong, |
| 1545 |
/// ) |
| 1546 |
/// .unwrap(); |
| 1547 |
/// |
| 1548 |
/// assert_writeable_eq!( |
| 1549 |
/// formatter.format(&utc_offset), |
| 1550 |
/// "GMT-06:00" |
| 1551 |
/// ); |
| 1552 |
/// |
| 1553 |
/// assert_writeable_eq!( |
| 1554 |
/// formatter.format(&time_zone_basic), |
| 1555 |
/// "GMT-06:00" |
| 1556 |
/// ); |
| 1557 |
/// |
| 1558 |
/// assert_writeable_eq!( |
| 1559 |
/// formatter.format(&time_zone_at_time), |
| 1560 |
/// "GMT-06:00" |
| 1561 |
/// ); |
| 1562 |
/// ``` |
| 1563 |
LocalizedOffsetLong, |
| 1564 |
description = "UTC offset, long length", |
| 1565 |
length_override = Long, |
| 1566 |
sample = "GMT-05:00", |
| 1567 |
field = (fields::TimeZone::LocalizedOffset, fields::FieldLength::Four), |
| 1568 |
zone_essentials = yes, |
| 1569 |
); |
| 1570 |
|
| 1571 |
impl_zone_marker!( |
| 1572 |
/// All shapes of time zones can be formatted with this style. |
| 1573 |
/// |
| 1574 |
/// ``` |
| 1575 |
/// use icu::datetime::input::Date; |
| 1576 |
/// use icu::datetime::NoCalendarFormatter; |
| 1577 |
/// use icu::datetime::fieldsets::zone::LocalizedOffsetShort; |
| 1578 |
/// use icu::datetime::input::{DateTime, Time, TimeZone, UtcOffset}; |
| 1579 |
/// use icu::locale::locale; |
| 1580 |
/// use writeable::assert_writeable_eq; |
| 1581 |
/// |
| 1582 |
/// let utc_offset = UtcOffset::try_from_seconds(-6 * 3600).unwrap(); |
| 1583 |
/// let time_zone_basic = TimeZone::from_iana_id("America/Chicago").with_offset(Some(utc_offset)); |
| 1584 |
/// |
| 1585 |
/// let time_zone_at_time = time_zone_basic.with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1729202400)); |
| 1586 |
/// |
| 1587 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1588 |
/// locale!("en-US").into(), |
| 1589 |
/// LocalizedOffsetShort, |
| 1590 |
/// ) |
| 1591 |
/// .unwrap(); |
| 1592 |
/// |
| 1593 |
/// assert_writeable_eq!( |
| 1594 |
/// formatter.format(&utc_offset), |
| 1595 |
/// "GMT-6" |
| 1596 |
/// ); |
| 1597 |
/// |
| 1598 |
/// assert_writeable_eq!( |
| 1599 |
/// formatter.format(&time_zone_basic), |
| 1600 |
/// "GMT-6" |
| 1601 |
/// ); |
| 1602 |
/// |
| 1603 |
/// assert_writeable_eq!( |
| 1604 |
/// formatter.format(&time_zone_at_time), |
| 1605 |
/// "GMT-6" |
| 1606 |
/// ); |
| 1607 |
/// ``` |
| 1608 |
LocalizedOffsetShort, |
| 1609 |
description = "UTC offset, short length", |
| 1610 |
length_override = Short, |
| 1611 |
sample = "GMT-5", |
| 1612 |
field = (fields::TimeZone::LocalizedOffset, fields::FieldLength::One), |
| 1613 |
zone_essentials = yes, |
| 1614 |
); |
| 1615 |
|
| 1616 |
impl_zone_marker!( |
| 1617 |
/// If a non-location name is not defined, falls back to the specific location format: |
| 1618 |
/// |
| 1619 |
/// ``` |
| 1620 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 1621 |
/// use icu::datetime::NoCalendarFormatter; |
| 1622 |
/// use icu::datetime::fieldsets::zone::GenericLong; |
| 1623 |
/// use icu::locale::locale; |
| 1624 |
/// use writeable::assert_writeable_eq; |
| 1625 |
/// |
| 1626 |
/// // Time zone info for Europe/Istanbul in the winter |
| 1627 |
/// let zone = TimeZone::from_iana_id("Europe/Istanbul") |
| 1628 |
/// .with_offset(UtcOffset::try_from_seconds(3 * 3600).ok()) |
| 1629 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1643410800)); |
| 1630 |
/// |
| 1631 |
/// let fmt = NoCalendarFormatter::try_new( |
| 1632 |
/// locale!("en").into(), |
| 1633 |
/// GenericLong, |
| 1634 |
/// ) |
| 1635 |
/// .unwrap(); |
| 1636 |
/// |
| 1637 |
/// assert_writeable_eq!( |
| 1638 |
/// fmt.format(&zone), |
| 1639 |
/// "Türkiye Time" |
| 1640 |
/// ); |
| 1641 |
/// ``` |
| 1642 |
/// |
| 1643 |
/// If the offset doesn't match one of the valid offsets for the zone, falls back to the localized offset format: |
| 1644 |
/// ``` |
| 1645 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 1646 |
/// use icu::datetime::NoCalendarFormatter; |
| 1647 |
/// use icu::datetime::fieldsets::zone::GenericLong; |
| 1648 |
/// use icu::locale::locale; |
| 1649 |
/// use writeable::assert_writeable_eq; |
| 1650 |
/// |
| 1651 |
/// // Time zone info for America/Chicago with a wrong offset |
| 1652 |
/// let wrong_offset = TimeZone::from_iana_id("America/Chicago") |
| 1653 |
/// .with_offset(UtcOffset::try_from_seconds(-4 * 3600).ok()) |
| 1654 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1661724000)); |
| 1655 |
/// |
| 1656 |
/// let fmt = NoCalendarFormatter::try_new( |
| 1657 |
/// locale!("en").into(), |
| 1658 |
/// GenericLong, |
| 1659 |
/// ) |
| 1660 |
/// .unwrap(); |
| 1661 |
/// |
| 1662 |
/// assert_writeable_eq!( |
| 1663 |
/// fmt.format(&wrong_offset), |
| 1664 |
/// "GMT-04:00" |
| 1665 |
/// ); |
| 1666 |
/// |
| 1667 |
/// // This of course always happens for the unknown time zone |
| 1668 |
/// let unk = TimeZone::UNKNOWN.with_offset(wrong_offset.offset()).with_zone_name_timestamp(wrong_offset.zone_name_timestamp()); |
| 1669 |
/// |
| 1670 |
/// assert_writeable_eq!( |
| 1671 |
/// fmt.format(&unk), |
| 1672 |
/// "GMT-04:00" |
| 1673 |
/// ); |
| 1674 |
/// ``` |
| 1675 |
/// |
| 1676 |
/// Since non-location names might change over time, |
| 1677 |
/// this time zone style requires a reference time. |
| 1678 |
/// |
| 1679 |
/// ```compile_fail,E0271 |
| 1680 |
/// use icu::datetime::NoCalendarFormatter; |
| 1681 |
/// use icu::datetime::fieldsets::zone::GenericLong; |
| 1682 |
/// use icu::datetime::input::TimeZone; |
| 1683 |
/// use icu::locale::locale; |
| 1684 |
/// |
| 1685 |
/// let time_zone_basic = TimeZone::from_iana_id("America/Chicago").without_offset(); |
| 1686 |
/// |
| 1687 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1688 |
/// locale!("en-US").into(), |
| 1689 |
/// GenericLong, |
| 1690 |
/// ) |
| 1691 |
/// .unwrap(); |
| 1692 |
/// |
| 1693 |
/// // error[E0271]: type mismatch resolving `<Base as TimeZoneModel>::ZoneNameTimestamp == ZoneNameTimestamp` |
| 1694 |
/// formatter.format(&time_zone_basic); |
| 1695 |
/// ``` |
| 1696 |
GenericLong, |
| 1697 |
description = "time zone in generic non-location format, long length", |
| 1698 |
length_override = Long, |
| 1699 |
sample = "Central Time", |
| 1700 |
field = (fields::TimeZone::GenericNonLocation, fields::FieldLength::Four), |
| 1701 |
zone_essentials = yes, |
| 1702 |
zone_locations = yes, |
| 1703 |
zone_generic_long = yes, |
| 1704 |
zone_standard_long = yes, |
| 1705 |
metazone_periods = yes, |
| 1706 |
input_tzid = yes, |
| 1707 |
input_timestamp = yes, |
| 1708 |
); |
| 1709 |
|
| 1710 |
impl_zone_marker!( |
| 1711 |
/// If a non-location name is not defined, falls back to the location format, which is |
| 1712 |
/// often significantly longer! |
| 1713 |
/// This is the case for most zones, as each locale only contains the short names that are |
| 1714 |
/// used locally and generally understood: |
| 1715 |
/// |
| 1716 |
/// ``` |
| 1717 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 1718 |
/// use icu::datetime::NoCalendarFormatter; |
| 1719 |
/// use icu::datetime::fieldsets::zone::GenericShort; |
| 1720 |
/// use icu::locale::locale; |
| 1721 |
/// use writeable::assert_writeable_eq; |
| 1722 |
/// |
| 1723 |
/// // Time zone info for Asia/Tokyo |
| 1724 |
/// let zone = TimeZone::from_iana_id("Asia/Tokyo") |
| 1725 |
/// .with_offset(UtcOffset::try_from_seconds(9 * 3600).ok()) |
| 1726 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1643410800)); |
| 1727 |
/// |
| 1728 |
/// let fmt = NoCalendarFormatter::try_new( |
| 1729 |
/// locale!("en").into(), |
| 1730 |
/// GenericShort, |
| 1731 |
/// ) |
| 1732 |
/// .unwrap(); |
| 1733 |
/// |
| 1734 |
/// // "JST" is not generally known in American English |
| 1735 |
/// assert_writeable_eq!( |
| 1736 |
/// fmt.format(&zone), |
| 1737 |
/// "Japan Time" |
| 1738 |
/// ); |
| 1739 |
/// ``` |
| 1740 |
/// |
| 1741 |
/// If the offset doesn't match one of the valid offsets for the zone, falls back to the localized offset format: |
| 1742 |
/// ``` |
| 1743 |
/// use icu::datetime::input::{Date, DateTime, Time, TimeZone, TimeZoneInfo, UtcOffset}; |
| 1744 |
/// use icu::datetime::NoCalendarFormatter; |
| 1745 |
/// use icu::datetime::fieldsets::zone::GenericShort; |
| 1746 |
/// use icu::locale::locale; |
| 1747 |
/// use writeable::assert_writeable_eq; |
| 1748 |
/// |
| 1749 |
/// // Time zone info for America/Chicago with a wrong offset |
| 1750 |
/// let wrong_offset = TimeZone::from_iana_id("America/Chicago") |
| 1751 |
/// .with_offset(UtcOffset::try_from_seconds(-4 * 3600).ok()) |
| 1752 |
/// .with_zone_name_timestamp(icu::time::zone::ZoneNameTimestamp::from_epoch_seconds(1661724000)); |
| 1753 |
/// |
| 1754 |
/// let fmt = NoCalendarFormatter::try_new( |
| 1755 |
/// locale!("en").into(), |
| 1756 |
/// GenericShort, |
| 1757 |
/// ) |
| 1758 |
/// .unwrap(); |
| 1759 |
/// |
| 1760 |
/// assert_writeable_eq!( |
| 1761 |
/// fmt.format(&wrong_offset), |
| 1762 |
/// "GMT-4" |
| 1763 |
/// ); |
| 1764 |
/// |
| 1765 |
/// // This of course always happens for the unknown time zone |
| 1766 |
/// let unk = TimeZone::UNKNOWN.with_offset(wrong_offset.offset()).with_zone_name_timestamp(wrong_offset.zone_name_timestamp()); |
| 1767 |
/// |
| 1768 |
/// assert_writeable_eq!( |
| 1769 |
/// fmt.format(&unk), |
| 1770 |
/// "GMT-4" |
| 1771 |
/// ); |
| 1772 |
/// ``` |
| 1773 |
/// |
| 1774 |
/// Since non-location names might change over time, |
| 1775 |
/// this time zone style requires a reference time. |
| 1776 |
/// |
| 1777 |
/// ```compile_fail,E0271 |
| 1778 |
/// use icu::datetime::NoCalendarFormatter; |
| 1779 |
/// use icu::datetime::fieldsets::zone::GenericShort; |
| 1780 |
/// use icu::datetime::input::TimeZone; |
| 1781 |
/// use icu::locale::locale; |
| 1782 |
/// |
| 1783 |
/// let time_zone_basic = TimeZone::from_iana_id("America/Chicago").without_offset(); |
| 1784 |
/// |
| 1785 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1786 |
/// locale!("en-US").into(), |
| 1787 |
/// GenericShort, |
| 1788 |
/// ) |
| 1789 |
/// .unwrap(); |
| 1790 |
/// |
| 1791 |
/// // error[E0271]: type mismatch resolving `<Base as TimeZoneModel>::ZoneNameTimestamp == ZoneNameTimestamp` |
| 1792 |
/// formatter.format(&time_zone_basic); |
| 1793 |
/// ``` |
| 1794 |
GenericShort, |
| 1795 |
description = "time zone in generic non-location format, short length", |
| 1796 |
length_override = Short, |
| 1797 |
sample = "CT", |
| 1798 |
field = (fields::TimeZone::GenericNonLocation, fields::FieldLength::One), |
| 1799 |
zone_essentials = yes, |
| 1800 |
zone_locations = yes, |
| 1801 |
zone_generic_short = yes, |
| 1802 |
metazone_periods = yes, |
| 1803 |
input_tzid = yes, |
| 1804 |
input_timestamp = yes, |
| 1805 |
); |
| 1806 |
|
| 1807 |
impl_zone_marker!( |
| 1808 |
/// A time zone ID is required to format with this style. |
| 1809 |
/// For example, a raw [`UtcOffset`] cannot be used here. |
| 1810 |
/// |
| 1811 |
/// ```compile_fail,E0277 |
| 1812 |
/// use icu::datetime::input::DateTime; |
| 1813 |
/// use icu::datetime::NoCalendarFormatter; |
| 1814 |
/// use icu::datetime::fieldsets::zone::Location; |
| 1815 |
/// use icu::datetime::input::UtcOffset; |
| 1816 |
/// use tinystr::tinystr; |
| 1817 |
/// use icu::locale::locale; |
| 1818 |
/// use writeable::assert_writeable_eq; |
| 1819 |
/// |
| 1820 |
/// let utc_offset = UtcOffset::try_from_seconds(-6 * 3600).unwrap(); |
| 1821 |
/// |
| 1822 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1823 |
/// locale!("en-US").into(), |
| 1824 |
/// Location, |
| 1825 |
/// ) |
| 1826 |
/// .unwrap(); |
| 1827 |
/// |
| 1828 |
/// // error[E0277]: the trait bound `UtcOffset: AllInputMarkers<Location>` is not satisfied |
| 1829 |
/// // note: required by a bound in `NoCalendarFormatter::<C, FSet>::format` |
| 1830 |
/// formatter.format(&utc_offset); |
| 1831 |
/// ``` |
| 1832 |
Location, |
| 1833 |
description = "time zone in location format", |
| 1834 |
length_override = Long, |
| 1835 |
sample = "Chicago Time", |
| 1836 |
field = (fields::TimeZone::Location, fields::FieldLength::Four), |
| 1837 |
zone_essentials = yes, |
| 1838 |
zone_locations = yes, |
| 1839 |
input_tzid = yes, |
| 1840 |
); |
| 1841 |
|
| 1842 |
impl_zone_marker!( |
| 1843 |
/// A time zone ID is required to format with this style. |
| 1844 |
/// For example, a raw [`UtcOffset`] cannot be used here. |
| 1845 |
/// |
| 1846 |
/// ```compile_fail,E0277 |
| 1847 |
/// use icu::datetime::input::DateTime; |
| 1848 |
/// use icu::datetime::NoCalendarFormatter; |
| 1849 |
/// use icu::datetime::fieldsets::zone::ExemplarCity; |
| 1850 |
/// use icu::datetime::input::UtcOffset; |
| 1851 |
/// use tinystr::tinystr; |
| 1852 |
/// use icu::locale::locale; |
| 1853 |
/// use writeable::assert_writeable_eq; |
| 1854 |
/// |
| 1855 |
/// let utc_offset = UtcOffset::try_from_seconds(-6 * 3600).unwrap(); |
| 1856 |
/// |
| 1857 |
/// let formatter = NoCalendarFormatter::try_new( |
| 1858 |
/// locale!("en-US").into(), |
| 1859 |
/// ExemplarCity, |
| 1860 |
/// ) |
| 1861 |
/// .unwrap(); |
| 1862 |
/// |
| 1863 |
/// // error[E0277]: the trait bound `UtcOffset: AllInputMarkers<ExemplarCity>` is not satisfied |
| 1864 |
/// // note: required by a bound in `NoCalendarFormatter::<C, FSet>::format` |
| 1865 |
/// formatter.format(&utc_offset); |
| 1866 |
/// ``` |
| 1867 |
ExemplarCity, |
| 1868 |
description = "time zone in exemplar city format", |
| 1869 |
length_override = Long, |
| 1870 |
sample = "Chicago", |
| 1871 |
field = (fields::TimeZone::Location, fields::FieldLength::Three), |
| 1872 |
zone_locations = yes, |
| 1873 |
zone_exemplars = yes, |
| 1874 |
input_tzid = yes, |
| 1875 |
); |
| 1876 |
} |
| 1877 |
|
| 1878 |
impl_zone_combo_helpers!(DateFieldSet, DateZone, DateFieldSet); |
| 1879 |
|
| 1880 |
impl_zone_combo_helpers!(TimeFieldSet, TimeZone, TimeFieldSet); |
| 1881 |
|
| 1882 |
impl_zone_combo_helpers!(DateAndTimeFieldSet, DateTimeZone, DateAndTimeFieldSet); |