1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538
// This file is part of ICU4X. For terms of use, please see the file
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).
//! All available field sets for datetime formatting.
pub use crate::combo::Combo;
use crate::{
dynamic::*,
fields,
format::neo::*,
neo_skeleton::*,
provider::{neo::*, time_zones::tz, *},
raw::neo::RawNeoOptions,
scaffold::*,
};
use icu_calendar::{
types::{
DayOfMonth, IsoHour, IsoMinute, IsoSecond, IsoWeekday, MonthInfo, NanoSecond, YearInfo,
},
Date, Iso, Time,
};
use icu_provider::marker::NeverMarker;
use icu_timezone::{TimeZoneBcp47Id, UtcOffset, ZoneVariant};
/// Enumerations over field sets.
pub mod dynamic {
// TODO: Rename to `pub mod enums`
pub use crate::dynamic::*;
}
#[cfg(doc)]
use icu_timezone::TimeZoneInfo;
/// Maps the token `yes` to the given ident
macro_rules! yes_to {
($any:expr, yes) => {
$any
};
() => {
unreachable!() // prevent bugs
};
}
macro_rules! yes_or {
($fallback:expr, $actual:expr) => {
$actual
};
($fallback:expr,) => {
$fallback
};
}
macro_rules! ternary {
($present:expr, $missing:expr, yes) => {
$present
};
($present:expr, $missing:expr, $any:literal) => {
$present
};
($present:expr, $missing:expr,) => {
$missing
};
}
/// Generates the options argument passed into the docs test constructor
macro_rules! length_option_helper {
($type:ty, $length:ident) => {
concat!(stringify!($type), "::", stringify!($length), "()")
};
}
macro_rules! impl_composite {
($type:ident, $variant:ident, $enum:ident) => {
impl $type {
#[inline]
pub(crate) fn to_enum(self) -> $enum {
$enum::$type(self)
}
}
impl GetField<CompositeFieldSet> for $type {
#[inline]
fn get_field(&self) -> CompositeFieldSet {
CompositeFieldSet::$variant(self.to_enum())
}
}
};
}
macro_rules! impl_marker_with_options {
(
$(#[$attr:meta])*
$type:ident,
$(sample_length: $sample_length:ident,)?
$(alignment: $alignment_yes:ident,)?
$(year_style: $yearstyle_yes:ident,)?
$(time_precision: $timeprecision_yes:ident,)?
$(enumerated: $enumerated_yes:ident,)?
) => {
$(#[$attr])*
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
#[non_exhaustive]
pub struct $type {
$(
/// The desired length of the formatted string.
///
/// See: [`NeoSkeletonLength`]
pub length: datetime_marker_helper!(@option/length, $sample_length),
)?
$(
/// Whether fields should be aligned for a column-like layout.
///
/// See: [`Alignment`]
pub alignment: datetime_marker_helper!(@option/alignment, $alignment_yes),
)?
$(
/// When to display the era field in the formatted string.
///
/// See: [`YearStyle`]
pub year_style: datetime_marker_helper!(@option/yearstyle, $yearstyle_yes),
)?
$(
/// How precisely to display the time of day
///
/// See: [`TimePrecision`]
pub time_precision: datetime_marker_helper!(@option/timeprecision, $timeprecision_yes),
)?
}
impl $type {
#[doc = concat!("Creates a ", stringify!($type), " skeleton with the given formatting length.")]
pub const fn with_length(length: NeoSkeletonLength) -> Self {
Self {
length,
$(
alignment: yes_to!(None, $alignment_yes),
)?
$(
year_style: yes_to!(None, $yearstyle_yes),
)?
$(
time_precision: yes_to!(None, $timeprecision_yes),
)?
}
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a long length.")]
pub const fn long() -> Self {
Self::with_length(NeoSkeletonLength::Long)
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a medium length.")]
pub const fn medium() -> Self {
Self::with_length(NeoSkeletonLength::Medium)
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a short length.")]
pub const fn short() -> Self {
Self::with_length(NeoSkeletonLength::Short)
}
}
#[allow(dead_code)]
impl $type {
$(
const _: () = yes_to!((), $enumerated_yes); // condition for this macro block
#[warn(dead_code)]
)?
pub(crate) fn to_raw_options(self) -> RawNeoOptions {
RawNeoOptions {
length: self.length,
alignment: ternary!(self.alignment, None, $($alignment_yes)?),
year_style: ternary!(self.year_style, None, $($yearstyle_yes)?),
time_precision: ternary!(self.time_precision, None, $($timeprecision_yes)?),
}
}
$(
const _: () = yes_to!((), $enumerated_yes); // condition for this macro block
#[warn(dead_code)]
)?
pub(crate) fn from_raw_options(options: RawNeoOptions) -> Self {
Self {
length: options.length,
$(alignment: yes_to!(options.alignment, $alignment_yes),)?
$(year_style: yes_to!(options.year_style, $yearstyle_yes),)?
$(time_precision: yes_to!(options.time_precision, $timeprecision_yes),)?
}
}
}
impl_get_field!($type, never);
impl_get_field!($type, length, yes);
$(
impl_get_field!($type, alignment, $alignment_yes);
impl $type {
/// Sets the alignment option.
pub const fn with_alignment(mut self, alignment: Alignment) -> Self {
self.alignment = Some(alignment);
self
}
}
)?
$(
impl_get_field!($type, year_style, $yearstyle_yes);
impl $type {
/// Sets the year style option.
pub const fn with_year_style(mut self, year_style: YearStyle) -> Self {
self.year_style = Some(year_style);
self
}
}
)?
$(
impl_get_field!($type, time_precision, $timeprecision_yes);
impl $type {
/// Sets the time precision option.
pub const fn with_time_precision(mut self, time_precision: TimePrecision) -> Self {
self.time_precision = Some(time_precision);
self
}
/// Sets the time precision to [`TimePrecision::MinuteExact`]
pub fn hm(mut self) -> Self {
self.time_precision = Some(TimePrecision::MinuteExact);
self
}
/// Sets the time precision to [`TimePrecision::SecondPlus`]
pub fn hms(mut self) -> Self {
self.time_precision = Some(TimePrecision::SecondPlus);
self
}
}
)?
};
}
macro_rules! impl_combo_get_field {
($type:ident, $composite:ident, $enum:ident, $wrap:ident, $in:ident, $out:ident) => {
impl GetField<CompositeFieldSet> for Combo<$type, $in> {
#[inline]
fn get_field(&self) -> CompositeFieldSet {
CompositeFieldSet::$composite(self.dt().to_enum(), ZoneStyle::$out)
}
}
};
}
macro_rules! impl_combo_generic_fns {
($type:ident) => {
impl<Z> Combo<$type, Z> {
#[doc = concat!("Creates a ", stringify!($type), " skeleton with the given formatting length and a time zone.")]
pub fn with_length(length: NeoSkeletonLength) -> Self {
Self::new($type::with_length(length))
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a long length and a time zone.")]
pub const fn long() -> Self {
Self::new($type::long())
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a medium length and a time zone.")]
pub const fn medium() -> Self {
Self::new($type::medium())
}
#[doc = concat!("Creates a ", stringify!($type), " skeleton with a short length and a time zone.")]
pub const fn short() -> Self {
Self::new($type::short())
}
}
};
}
macro_rules! impl_zone_combo_helpers {
(
$type:ident,
$composite:ident,
$enum:ident,
$wrap:ident
) => {
impl $type {
/// Associates this field set with a specific non-location format time zone, as in
/// “Pacific Daylight Time”.
#[inline]
pub fn z(self) -> Combo<Self, Zs> {
Combo::new(self)
}
/// Associates this field set with an offset format time zone, as in
/// “GMT−8”.
#[inline]
pub fn o(self) -> Combo<Self, O> {
Combo::new(self)
}
/// Associates this field set with a generic non-location format time zone, as in
/// “Pacific Time”.
#[inline]
pub fn v(self) -> Combo<Self, Vs> {
Combo::new(self)
}
/// Associates this field set with a location format time zone, as in
/// “Los Angeles time”.
#[inline]
pub fn l(self) -> Combo<Self, L> {
Combo::new(self)
}
}
impl_combo_get_field!($type, $composite, $enum, $wrap, Zs, Z);
impl_combo_get_field!($type, $composite, $enum, $wrap, O, O);
impl_combo_get_field!($type, $composite, $enum, $wrap, Vs, V);
impl_combo_get_field!($type, $composite, $enum, $wrap, L, L);
};
}
/// Internal helper macro used by [`impl_date_marker`] and [`impl_calendar_period_marker`]
macro_rules! impl_date_or_calendar_period_marker {
(
$(#[$attr:meta])*
// The name of the type being created.
$type:ident,
// A plain language description of the field set for documentation.
description = $description:literal,
// Length of the sample string below.
sample_length = $sample_length:ident,
// A sample string. A docs test will be generated!
sample = $sample:literal,
// Whether years can occur.
$(years = $years_yes:ident,)?
// Whether months can occur.
$(months = $months_yes:ident,)?
// Whether weekdays can occur.
$(weekdays = $weekdays_yes:ident,)?
// Whether the input should contain years.
$(input_year = $year_yes:ident,)?
// Whether the input should contain months.
$(input_month = $month_yes:ident,)?
// Whether the input should contain the day of the month.
$(input_day_of_month = $day_of_month_yes:ident,)?
// Whether the input should contain the day of the week.
$(input_day_of_week = $day_of_week_yes:ident,)?
// Whether the input should contain the day of the year.
$(input_day_of_year = $day_of_year_yes:ident,)?
// Whether the input should declare its calendar kind.
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)?
// Whether the alignment option should be available.
// According to UTS 35, it should be available with years, months, and days.
$(option_alignment = $option_alignment_yes:ident,)?
) => {
impl_marker_with_options!(
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
///
/// # Examples
///
/// In [`DateTimeFormatter`](crate::neo::DateTimeFormatter):
///
/// ```
/// use icu::calendar::Date;
/// use icu::datetime::DateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
#[doc = concat!("let fmt = DateTimeFormatter::<", stringify!($type), ">::try_new(")]
/// &locale!("en").into(),
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
/// )
/// .unwrap();
/// let dt = Date::try_new_iso(2024, 5, 17).unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&dt),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
///
/// In [`FixedCalendarDateTimeFormatter`](crate::neo::FixedCalendarDateTimeFormatter):
///
/// ```
/// use icu::calendar::Date;
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::<Gregorian, ", stringify!($type), ">::try_new(")]
/// &locale!("en").into(),
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
/// )
/// .unwrap();
/// let dt = Date::try_new_gregorian(2024, 5, 17).unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.format(&dt),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
$(#[$attr])*
$type,
sample_length: $sample_length,
$(alignment: $option_alignment_yes,)?
$(year_style: $year_yes,)?
);
impl UnstableSealed for $type {}
impl DateTimeNamesMarker for $type {
type YearNames = datetime_marker_helper!(@names/year, $($years_yes)?);
type MonthNames = datetime_marker_helper!(@names/month, $($months_yes)?);
type WeekdayNames = datetime_marker_helper!(@names/weekday, $($weekdays_yes)?);
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod,);
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,);
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,);
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,);
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,);
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,);
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,);
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,);
}
impl DateInputMarkers for $type {
type YearInput = datetime_marker_helper!(@input/year, $($year_yes)?);
type MonthInput = datetime_marker_helper!(@input/month, $($month_yes)?);
type DayOfMonthInput = datetime_marker_helper!(@input/day_of_month, $($day_of_month_yes)?);
type DayOfYearInput = datetime_marker_helper!(@input/day_of_year, $($day_of_year_yes)?);
type DayOfWeekInput = datetime_marker_helper!(@input/day_of_week, $($day_of_week_yes)?);
}
impl<C: CldrCalendar> TypedDateDataMarkers<C> for $type {
type DateSkeletonPatternsV1Marker = datetime_marker_helper!(@dates/typed, yes);
type YearNamesV1Marker = datetime_marker_helper!(@years/typed, $($years_yes)?);
type MonthNamesV1Marker = datetime_marker_helper!(@months/typed, $($months_yes)?);
type WeekdayNamesV1Marker = datetime_marker_helper!(@weekdays, $($weekdays_yes)?);
}
impl DateDataMarkers for $type {
type Skel = datetime_marker_helper!(@calmarkers, yes);
type Year = datetime_marker_helper!(@calmarkers, $($years_yes)?);
type Month = datetime_marker_helper!(@calmarkers, $($months_yes)?);
type WeekdayNamesV1Marker = datetime_marker_helper!(@weekdays, $($weekdays_yes)?);
}
impl DateTimeMarkers for $type {
type D = Self;
type T = NeoNeverMarker;
type Z = NeoNeverMarker;
type GluePatternV1Marker = datetime_marker_helper!(@glue,);
}
};
}
/// Implements a field set of date fields.
///
/// Several arguments to this macro are required, and the rest are optional.
/// The optional arguments should be written as `key = yes,` if that parameter
/// should be included.
///
/// See [`impl_date_marker`].
macro_rules! impl_date_marker {
(
$(#[$attr:meta])*
$type:ident,
$type_time:ident,
$components:expr,
description = $description:literal,
sample_length = $sample_length:ident,
sample = $sample:literal,
sample_time = $sample_time:literal,
$(years = $years_yes:ident,)?
$(months = $months_yes:ident,)?
$(dates = $dates_yes:ident,)?
$(weekdays = $weekdays_yes:ident,)?
$(input_year = $year_yes:ident,)?
$(input_month = $month_yes:ident,)?
$(input_day_of_month = $day_of_month_yes:ident,)?
$(input_day_of_week = $day_of_week_yes:ident,)?
$(input_day_of_year = $day_of_year_yes:ident,)?
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)?
$(option_alignment = $option_alignment_yes:ident,)?
) => {
impl_date_or_calendar_period_marker!(
$(#[$attr])*
$type,
description = $description,
sample_length = $sample_length,
sample = $sample,
$(years = $years_yes,)?
$(months = $months_yes,)?
$(dates = $dates_yes,)?
$(weekdays = $weekdays_yes,)?
$(input_year = $year_yes,)?
$(input_month = $month_yes,)?
$(input_day_of_month = $day_of_month_yes,)?
$(input_day_of_week = $day_of_week_yes,)?
$(input_day_of_year = $day_of_year_yes,)?
$(input_any_calendar_kind = $any_calendar_kind_yes,)?
$(option_alignment = $option_alignment_yes,)?
);
impl_zone_combo_helpers!($type, DateZone, DateFieldSet, wrap);
impl_combo_generic_fns!($type);
impl_composite!($type, Date, DateFieldSet);
impl_marker_with_options!(
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
///
/// # Examples
///
/// In [`DateTimeFormatter`](crate::neo::DateTimeFormatter):
///
/// ```
/// use icu::calendar::DateTime;
/// use icu::datetime::DateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type_time), ";")]
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
#[doc = concat!("let fmt = DateTimeFormatter::<", stringify!($type_time), ">::try_new(")]
/// &locale!("en").into(),
#[doc = concat!(" ", length_option_helper!($type_time, $sample_length), ",")]
/// )
/// .unwrap();
/// let dt = DateTime::try_new_iso(2024, 5, 17, 15, 47, 50).unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&dt),
#[doc = concat!(" \"", $sample_time, "\"")]
/// );
/// ```
///
/// In [`FixedCalendarDateTimeFormatter`](crate::neo::FixedCalendarDateTimeFormatter):
///
/// ```
/// use icu::calendar::DateTime;
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type_time), ";")]
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::<Gregorian, ", stringify!($type_time), ">::try_new(")]
/// &locale!("en").into(),
#[doc = concat!(" ", length_option_helper!($type_time, $sample_length), ",")]
/// )
/// .unwrap();
/// let dt = DateTime::try_new_gregorian(2024, 5, 17, 15, 47, 50).unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.format(&dt),
#[doc = concat!(" \"", $sample_time, "\"")]
/// );
/// ```
$(#[$attr])*
$type_time,
sample_length: $sample_length,
alignment: yes,
$(year_style: $year_yes,)?
time_precision: yes,
);
impl_zone_combo_helpers!($type_time, DateTimeZone, DateAndTimeFieldSet, wrap);
impl_combo_generic_fns!($type_time);
impl UnstableSealed for $type_time {}
impl DateTimeNamesMarker for $type_time {
type YearNames = datetime_marker_helper!(@names/year, $($years_yes)?);
type MonthNames = datetime_marker_helper!(@names/month, $($months_yes)?);
type WeekdayNames = datetime_marker_helper!(@names/weekday, $($weekdays_yes)?);
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod, yes);
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,);
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,);
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,);
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,);
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,);
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,);
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,);
}
impl DateInputMarkers for $type_time {
type YearInput = datetime_marker_helper!(@input/year, $($year_yes)?);
type MonthInput = datetime_marker_helper!(@input/month, $($month_yes)?);
type DayOfMonthInput = datetime_marker_helper!(@input/day_of_month, $($day_of_month_yes)?);
type DayOfYearInput = datetime_marker_helper!(@input/day_of_year, $($day_of_year_yes)?);
type DayOfWeekInput = datetime_marker_helper!(@input/day_of_week, $($day_of_week_yes)?);
}
impl<C: CldrCalendar> TypedDateDataMarkers<C> for $type_time {
type DateSkeletonPatternsV1Marker = datetime_marker_helper!(@dates/typed, yes);
type YearNamesV1Marker = datetime_marker_helper!(@years/typed, $($years_yes)?);
type MonthNamesV1Marker = datetime_marker_helper!(@months/typed, $($months_yes)?);
type WeekdayNamesV1Marker = datetime_marker_helper!(@weekdays, $($weekdays_yes)?);
}
impl DateDataMarkers for $type_time {
type Skel = datetime_marker_helper!(@calmarkers, yes);
type Year = datetime_marker_helper!(@calmarkers, $($years_yes)?);
type Month = datetime_marker_helper!(@calmarkers, $($months_yes)?);
type WeekdayNamesV1Marker = datetime_marker_helper!(@weekdays, $($weekdays_yes)?);
}
impl TimeMarkers for $type_time {
// TODO: Consider making dayperiods optional again
type DayPeriodNamesV1Marker = datetime_marker_helper!(@dayperiods, yes);
type TimeSkeletonPatternsV1Marker = datetime_marker_helper!(@times, yes);
type HourInput = datetime_marker_helper!(@input/hour, yes);
type MinuteInput = datetime_marker_helper!(@input/minute, yes);
type SecondInput = datetime_marker_helper!(@input/second, yes);
type NanoSecondInput = datetime_marker_helper!(@input/nanosecond, yes);
}
impl DateTimeMarkers for $type_time {
type D = Self;
type T = Self;
type Z = NeoNeverMarker;
type GluePatternV1Marker = datetime_marker_helper!(@glue, yes);
}
impl_composite!($type_time, DateTime, DateAndTimeFieldSet);
impl $type_time {
pub(crate) fn to_date_field_set(self) -> $type {
$type {
length: self.length,
$(alignment: yes_to!(self.alignment, $option_alignment_yes),)?
$(year_style: yes_to!(self.year_style, $years_yes),)?
}
}
}
};
}
/// Implements a field set of calendar period fields.
///
/// Several arguments to this macro are required, and the rest are optional.
/// The optional arguments should be written as `key = yes,` if that parameter
/// should be included.
///
/// See [`impl_date_marker`].
macro_rules! impl_calendar_period_marker {
(
$(#[$attr:meta])*
$type:ident,
$components:expr,
description = $description:literal,
sample_length = $sample_length:ident,
sample = $sample:literal,
$(years = $years_yes:ident,)?
$(months = $months_yes:ident,)?
$(dates = $dates_yes:ident,)?
$(input_year = $year_yes:ident,)?
$(input_month = $month_yes:ident,)?
$(input_any_calendar_kind = $any_calendar_kind_yes:ident,)?
$(option_alignment = $option_alignment_yes:ident,)?
) => {
impl_date_or_calendar_period_marker!(
$(#[$attr])*
$type,
description = $description,
sample_length = $sample_length,
sample = $sample,
$(years = $years_yes,)?
$(months = $months_yes,)?
$(dates = $dates_yes,)?
$(input_year = $year_yes,)?
$(input_month = $month_yes,)?
$(input_any_calendar_kind = $any_calendar_kind_yes,)?
$(option_alignment = $option_alignment_yes,)?
);
impl_composite!($type, CalendarPeriod, CalendarPeriodFieldSet);
};
}
/// Implements a field set of time fields.
///
/// Several arguments to this macro are required, and the rest are optional.
/// The optional arguments should be written as `key = yes,` if that parameter
/// should be included.
///
/// Documentation for each option is shown inline below.
macro_rules! impl_time_marker {
(
$(#[$attr:meta])*
// The name of the type being created.
$type:ident,
// An expression for the field set.
$components:expr,
// A plain language description of the field set for documentation.
description = $description:literal,
// Length of the sample string below.
sample_length = $sample_length:ident,
// A sample string. A docs test will be generated!
sample = $sample:literal,
// Whether day periods can occur.
$(dayperiods = $dayperiods_yes:ident,)?
// Whether the input should include hours.
$(input_hour = $hour_yes:ident,)?
// Whether the input should contain minutes.
$(input_minute = $minute_yes:ident,)?
// Whether the input should contain seconds.
$(input_second = $second_yes:ident,)?
// Whether the input should contain fractional seconds.
$(input_nanosecond = $nanosecond_yes:ident,)?
) => {
impl_marker_with_options!(
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
///
/// # Examples
///
/// In [`DateTimeFormatter`](crate::neo::DateTimeFormatter):
///
/// ```
/// use icu::calendar::DateTime;
/// use icu::datetime::DateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
#[doc = concat!("let fmt = DateTimeFormatter::<", stringify!($type), ">::try_new(")]
/// &locale!("en").into(),
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
/// )
/// .unwrap();
/// let dt = DateTime::try_new_iso(2024, 5, 17, 15, 47, 50).unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&dt),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
///
/// In [`FixedCalendarDateTimeFormatter`](crate::neo::FixedCalendarDateTimeFormatter):
///
/// ```
/// use icu::calendar::Time;
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::<Gregorian, ", stringify!($type), ">::try_new(")]
/// &locale!("en").into(),
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
/// )
/// .unwrap();
/// let dt = Time::try_new(15, 47, 50, 0).unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.format(&dt),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
$(#[$attr])*
$type,
sample_length: $sample_length,
alignment: yes,
time_precision: yes,
);
impl_zone_combo_helpers!($type, TimeZone, TimeFieldSet, wrap);
impl_combo_generic_fns!($type);
impl UnstableSealed for $type {}
impl DateTimeNamesMarker for $type {
type YearNames = datetime_marker_helper!(@names/year,);
type MonthNames = datetime_marker_helper!(@names/month,);
type WeekdayNames = datetime_marker_helper!(@names/weekday,);
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod, $($dayperiods_yes)?);
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials,);
type ZoneLocations = datetime_marker_helper!(@names/zone/locations,);
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long,);
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short,);
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long,);
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short,);
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods,);
}
impl TimeMarkers for $type {
type DayPeriodNamesV1Marker = datetime_marker_helper!(@dayperiods, $($dayperiods_yes)?);
type TimeSkeletonPatternsV1Marker = datetime_marker_helper!(@times, yes);
type HourInput = datetime_marker_helper!(@input/hour, $($hour_yes)?);
type MinuteInput = datetime_marker_helper!(@input/minute, $($minute_yes)?);
type SecondInput = datetime_marker_helper!(@input/second, $($second_yes)?);
type NanoSecondInput = datetime_marker_helper!(@input/nanosecond, $($nanosecond_yes)?);
}
impl DateTimeMarkers for $type {
type D = NeoNeverMarker;
type T = Self;
type Z = NeoNeverMarker;
type GluePatternV1Marker = datetime_marker_helper!(@glue,);
}
impl_composite!($type, Time, TimeFieldSet);
};
}
/// Implements a field set of time zone fields.
///
/// Several arguments to this macro are required, and the rest are optional.
/// The optional arguments should be written as `key = yes,` if that parameter
/// should be included.
///
/// Documentation for each option is shown inline below.
macro_rules! impl_zone_marker {
(
$(#[$attr:meta])*
// The name of the type being created.
$type:ident,
// An expression for the field set.
$components:expr,
// A plain language description of the field set for documentation.
description = $description:literal,
// Length of the sample string below.
sample_length = $sample_length:ident,
// A sample string. A docs test will be generated!
sample = $sample:literal,
// The field symbol and field length when the semantic length is short/medium.
field_short = $field_short:expr,
// The field symbol and field length when the semantic length is long.
field_long = $field_long:expr,
// The type in ZoneFieldSet for this field set
resolved_type = $resolved_type:ident,
// Whether to skip tests and render a message instead.
$(skip_tests = $skip_tests:literal,)?
// Whether zone-essentials should be loaded.
$(zone_essentials = $zone_essentials_yes:ident,)?
// Whether locations formats can occur.
$(zone_locations = $zone_locations_yes:ident,)?
// Whether generic long formats can occur.
$(zone_generic_long = $zone_generic_long_yes:ident,)?
// Whether generic short formats can occur.
$(zone_generic_short = $zone_generic_short_yes:ident,)?
// Whether specific long formats can occur.
$(zone_specific_long = $zone_specific_long_yes:ident,)?
// Whether specific short formats can occur.
$(zone_specific_short = $zone_specific_short_yes:ident,)?
// Whether metazone periods are needed
$(metazone_periods = $metazone_periods_yes:ident,)?
// Whether to require the TimeZoneBcp47Id
$(input_tzid = $tzid_input_yes:ident,)?
// Whether to require the ZoneVariant
$(input_variant = $variant_input_yes:ident,)?
// Whether to require the Local Time
$(input_localtime = $localtime_input_yes:ident,)?
// Whether this time zone style is enumerated in ZoneFieldSet
$(enumerated = $enumerated_yes:ident,)?
) => {
impl_marker_with_options!(
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
///
#[doc = yes_or!("", $($skip_tests)?)]
///
/// # Examples
///
/// In [`DateTimeFormatter`](crate::neo::DateTimeFormatter):
///
#[doc = concat!("```", ternary!("compile_fail", "", $($skip_tests)?))]
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::datetime::DateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
/// use tinystr::tinystr;
/// use writeable::assert_try_writeable_eq;
///
#[doc = concat!("let fmt = DateTimeFormatter::<", stringify!($type), ">::try_new(")]
/// &locale!("en").into(),
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
/// )
/// .unwrap();
///
/// // Time zone info for America/Chicago in the summer
/// let zone = TimeZoneBcp47Id(tinystr!(8, "uschi"))
/// .with_offset("-05".parse().ok())
/// .at_time((Date::try_new_iso(2022, 8, 29).unwrap(), Time::midnight()))
/// .with_zone_variant(ZoneVariant::Daylight);
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&zone),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
///
/// In [`FixedCalendarDateTimeFormatter`](crate::neo::FixedCalendarDateTimeFormatter):
///
#[doc = concat!("```", ternary!("compile_fail", "", $($skip_tests)?))]
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
/// use tinystr::tinystr;
/// use writeable::assert_try_writeable_eq;
///
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::<Gregorian, ", stringify!($type), ">::try_new(")]
/// &locale!("en").into(),
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
/// )
/// .unwrap();
///
/// // Time zone info for America/Chicago in the summer
/// let zone = TimeZoneBcp47Id(tinystr!(8, "uschi"))
/// .with_offset("-05".parse().ok())
/// .at_time((Date::try_new_iso(2022, 8, 29).unwrap(), Time::midnight()))
/// .with_zone_variant(ZoneVariant::Daylight);
///
/// assert_try_writeable_eq!(
/// fmt.format(&zone),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
$(#[$attr])*
$type,
sample_length: $sample_length,
);
impl UnstableSealed for $type {}
impl DateTimeNamesMarker for $type {
type YearNames = datetime_marker_helper!(@names/year,);
type MonthNames = datetime_marker_helper!(@names/month,);
type WeekdayNames = datetime_marker_helper!(@names/weekday,);
type DayPeriodNames = datetime_marker_helper!(@names/dayperiod,);
type ZoneEssentials = datetime_marker_helper!(@names/zone/essentials, $($zone_essentials_yes)?);
type ZoneLocations = datetime_marker_helper!(@names/zone/locations, $($zone_locations_yes)?);
type ZoneGenericLong = datetime_marker_helper!(@names/zone/generic_long, $($zone_generic_long_yes)?);
type ZoneGenericShort = datetime_marker_helper!(@names/zone/generic_short, $($zone_generic_short_yes)?);
type ZoneSpecificLong = datetime_marker_helper!(@names/zone/specific_long, $($zone_specific_long_yes)?);
type ZoneSpecificShort = datetime_marker_helper!(@names/zone/specific_short, $($zone_specific_short_yes)?);
type MetazoneLookup = datetime_marker_helper!(@names/zone/metazone_periods, $($metazone_periods_yes)?);
}
impl ZoneMarkers for $type {
type TimeZoneIdInput = datetime_marker_helper!(@input/timezone/id, $($tzid_input_yes)?);
type TimeZoneOffsetInput = datetime_marker_helper!(@input/timezone/offset, yes);
type TimeZoneVariantInput = datetime_marker_helper!(@input/timezone/variant, $($variant_input_yes)?);
type TimeZoneLocalTimeInput = datetime_marker_helper!(@input/timezone/local_time, $($localtime_input_yes)?);
type EssentialsV1Marker = datetime_marker_helper!(@data/zone/essentials, $($zone_essentials_yes)?);
type LocationsV1Marker = datetime_marker_helper!(@data/zone/locations, $($zone_locations_yes)?);
type GenericLongV1Marker = datetime_marker_helper!(@data/zone/generic_long, $($zone_generic_long_yes)?);
type GenericShortV1Marker = datetime_marker_helper!(@data/zone/generic_short, $($zone_generic_short_yes)?);
type SpecificLongV1Marker = datetime_marker_helper!(@data/zone/specific_long, $($zone_specific_long_yes)?);
type SpecificShortV1Marker = datetime_marker_helper!(@data/zone/specific_short, $($zone_specific_short_yes)?);
type MetazonePeriodV1Marker = datetime_marker_helper!(@data/zone/metazone_periods, $($metazone_periods_yes)?);
}
impl DateTimeMarkers for $type {
type D = NeoNeverMarker;
type T = NeoNeverMarker;
type Z = Self;
type GluePatternV1Marker = datetime_marker_helper!(@glue,);
}
$(
const _: () = yes_to!((), $enumerated_yes); // condition for this macro block
impl_composite!($type, Zone, ZoneFieldSet);
impl $type {
pub(crate) fn to_field(self) -> (fields::TimeZone, fields::FieldLength) {
match self.length {
NeoSkeletonLength::Short | NeoSkeletonLength::Medium => $field_short,
NeoSkeletonLength::Long => $field_long,
}
}
}
)?
};
}
macro_rules! impl_zoneddatetime_marker {
(
$type:ident,
description = $description:literal,
sample_length = $sample_length:ident,
sample = $sample:literal,
datetime = $datetime:path,
zone = $zone:path,
) => {
#[doc = concat!("**“", $sample, "**” ⇒ ", $description)]
///
/// # Examples
///
/// In [`DateTimeFormatter`](crate::neo::DateTimeFormatter):
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{TimeZoneInfo, IxdtfParser};
/// use icu::datetime::DateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
#[doc = concat!("let fmt = DateTimeFormatter::<", stringify!($type), ">::try_new(")]
/// &locale!("en-GB").into(),
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
/// )
/// .unwrap();
///
/// let mut dtz = IxdtfParser::new().try_from_str("2024-05-17T15:47:50+01:00[Europe/London]").unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.convert_and_format(&dtz),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
///
/// In [`FixedCalendarDateTimeFormatter`](crate::neo::FixedCalendarDateTimeFormatter):
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{TimeZoneInfo, IxdtfParser};
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
#[doc = concat!("use icu::datetime::fieldset::", stringify!($type), ";")]
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
#[doc = concat!("let fmt = FixedCalendarDateTimeFormatter::<Gregorian, ", stringify!($type), ">::try_new(")]
/// &locale!("en-GB").into(),
#[doc = concat!(" ", length_option_helper!($type, $sample_length), ",")]
/// )
/// .unwrap();
///
/// let mut dtz = IxdtfParser::new().try_from_str("2024-05-17T15:47:50+01:00[Europe/London]")
/// .unwrap()
/// .to_calendar(Gregorian);
///
/// assert_try_writeable_eq!(
/// fmt.format(&dtz),
#[doc = concat!(" \"", $sample, "\"")]
/// );
/// ```
pub type $type = Combo<$datetime, $zone>;
}
}
impl_date_marker!(
/// This format may use ordinal formatting, such as "the 17th",
/// in the future. See CLDR-18040.
D,
DT,
NeoDateComponents::Day,
description = "day of month (standalone)",
sample_length = short,
sample = "17",
sample_time = "17, 3:47:50 PM",
input_day_of_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_date_marker!(
E,
ET,
NeoDateComponents::Weekday,
description = "weekday (standalone)",
sample_length = long,
sample = "Friday",
sample_time = "Friday 3:47:50 PM",
weekdays = yes,
input_day_of_week = yes,
);
impl_date_marker!(
/// This format may use ordinal formatting, such as "Friday the 17th",
/// in the future. See CLDR-18040.
DE,
DET,
NeoDateComponents::DayWeekday,
description = "day of month and weekday",
sample_length = long,
sample = "17 Friday",
sample_time = "17 Friday, 3:47:50 PM",
weekdays = yes,
input_day_of_month = yes,
input_day_of_week = yes,
option_alignment = yes,
);
impl_date_marker!(
MD,
MDT,
NeoDateComponents::MonthDay,
description = "month and day",
sample_length = medium,
sample = "May 17",
sample_time = "May 17, 3:47:50 PM",
months = yes,
input_month = yes,
input_day_of_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_date_marker!(
/// See CLDR-18040 for progress on improving this format.
MDE,
MDET,
NeoDateComponents::MonthDayWeekday,
description = "month, day, and weekday",
sample_length = medium,
sample = "Fri, May 17",
sample_time = "Fri, May 17, 3:47:50 PM",
months = yes,
weekdays = yes,
input_month = yes,
input_day_of_month = yes,
input_day_of_week = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_date_marker!(
YMD,
YMDT,
NeoDateComponents::YearMonthDay,
description = "year, month, and day",
sample_length = short,
sample = "5/17/24",
sample_time = "5/17/24, 3:47:50 PM",
years = yes,
months = yes,
input_year = yes,
input_month = yes,
input_day_of_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_date_marker!(
YMDE,
YMDET,
NeoDateComponents::YearMonthDayWeekday,
description = "year, month, day, and weekday",
sample_length = short,
sample = "Fri, 5/17/24",
sample_time = "Fri, 5/17/24, 3:47:50 PM",
years = yes,
months = yes,
weekdays = yes,
input_year = yes,
input_month = yes,
input_day_of_month = yes,
input_day_of_week = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_calendar_period_marker!(
Y,
NeoCalendarPeriodComponents::Year,
description = "year (standalone)",
sample_length = medium,
sample = "2024",
years = yes,
input_year = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_calendar_period_marker!(
M,
NeoCalendarPeriodComponents::Month,
description = "month (standalone)",
sample_length = long,
sample = "May",
months = yes,
input_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_calendar_period_marker!(
YM,
NeoCalendarPeriodComponents::YearMonth,
description = "year and month",
sample_length = medium,
sample = "May 2024",
years = yes,
months = yes,
input_year = yes,
input_month = yes,
input_any_calendar_kind = yes,
option_alignment = yes,
);
impl_time_marker!(
T,
NeoTimeComponents::Time,
description = "time (locale-dependent hour cycle)",
sample_length = medium,
sample = "3:47:50 PM",
dayperiods = yes,
input_hour = yes,
input_minute = yes,
input_second = yes,
input_nanosecond = yes,
);
impl_zone_marker!(
/// When a display name is unavailable, falls back to the localized offset format for short lengths, and
/// to the location format for long lengths:
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{IxdtfParser, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::Z;
/// use icu::locale::locale;
/// use tinystr::tinystr;
/// use writeable::assert_try_writeable_eq;
///
/// // Time zone info for Europe/Istanbul in the winter
/// let zone = TimeZoneBcp47Id(tinystr!(8, "trist"))
/// .with_offset("+02".parse().ok())
/// .at_time((Date::try_new_iso(2022, 1, 29).unwrap(), Time::midnight()))
/// .with_zone_variant(ZoneVariant::Standard);
///
/// let fmt = FixedCalendarDateTimeFormatter::<Gregorian, _>::try_new(
/// &locale!("en").into(),
/// Z::short(),
/// )
/// .unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.format(&zone),
/// "GMT+2"
/// );
///
/// let fmt = FixedCalendarDateTimeFormatter::<Gregorian, _>::try_new(
/// &locale!("en").into(),
/// Z::long(),
/// )
/// .unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.format(&zone),
/// "Türkiye Standard Time"
/// );
/// ```
///
/// This style requires a [`ZoneVariant`], so
/// only a full time zone info can be formatted with this style.
/// For example, [`TimeZoneInfo<AtTime>`] cannot be formatted.
///
/// ```compile_fail,E0271
/// use icu::calendar::{DateTime, Iso};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::Z;
/// use icu::timezone::{TimeZoneBcp47Id, UtcOffset, ZoneVariant};
/// use tinystr::tinystr;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let datetime = DateTime::try_new_gregorian(2024, 10, 18, 0, 0, 0).unwrap();
/// let time_zone_basic = TimeZoneBcp47Id(tinystr!(8, "uschi")).with_offset("-06".parse().ok());
/// let time_zone_at_time = time_zone_basic.at_time((datetime.date.to_iso(), datetime.time));
///
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
/// &locale!("en-US").into(),
/// Z::medium(),
/// )
/// .unwrap();
///
/// // error[E0271]: type mismatch resolving `<AtTime as TimeZoneModel>::ZoneVariant == ZoneVariant`
/// formatter.format(&time_zone_at_time);
/// ```
Z,
NeoTimeZoneStyle::Specific,
description = "time zone in specific non-location format",
sample_length = long,
sample = "Central Daylight Time",
field_short = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::One),
field_long = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::Four),
resolved_type = Z,
zone_essentials = yes,
zone_locations = yes,
zone_specific_long = yes,
zone_specific_short = yes,
metazone_periods = yes,
input_tzid = yes,
input_variant = yes,
input_localtime = yes,
enumerated = yes,
);
impl_zone_marker!(
/// This style requires a [`ZoneVariant`], so
/// only a full time zone info can be formatted with this style.
/// For example, [`TimeZoneInfo<AtTime>`] cannot be formatted.
///
/// ```compile_fail,E0271
/// use icu::calendar::{DateTime, Iso};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::{Combo, T, Zs};
/// use icu::timezone::{TimeZoneBcp47Id, UtcOffset, ZoneVariant};
/// use tinystr::tinystr;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let datetime = DateTime::try_new_gregorian(2024, 10, 18, 0, 0, 0).unwrap();
/// let time_zone_basic = TimeZoneBcp47Id(tinystr!(8, "uschi")).with_offset("-06".parse().ok());
/// let time_zone_at_time = time_zone_basic.at_time((datetime.date.to_iso(), datetime.time));
///
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
/// &locale!("en-US").into(),
/// Combo::<T, Zs>::medium(),
/// )
/// .unwrap();
///
/// // error[E0271]: type mismatch resolving `<AtTime as TimeZoneModel>::ZoneVariant == ZoneVariant`
/// // note: required by a bound in `FixedCalendarDateTimeFormatter::<C, FSet>::format`
/// formatter.format(&time_zone_at_time);
/// ```
Zs,
NeoTimeZoneStyle::Specific,
description = "time zone in specific non-location format (only short)",
sample_length = short,
sample = "CDT",
field_short = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::One),
field_long = (fields::TimeZone::SpecificNonLocation, fields::FieldLength::One),
resolved_type = Z,
skip_tests = "This field set can be used only in combination with others.",
zone_essentials = yes,
zone_specific_short = yes,
metazone_periods = yes,
input_tzid = yes,
input_variant = yes,
input_localtime = yes,
);
impl_zone_marker!(
/// All shapes of time zones can be formatted with this style.
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::O;
/// use icu::timezone::{TimeZoneBcp47Id, UtcOffset, ZoneVariant};
/// use tinystr::tinystr;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let utc_offset = "-06".parse().unwrap();
/// let time_zone_basic = TimeZoneBcp47Id(tinystr!(8, "uschi")).with_offset(Some(utc_offset));
///
/// let date = Date::try_new_iso(2024, 10, 18).unwrap();
/// let time = Time::midnight();
/// let time_zone_at_time = time_zone_basic.at_time((date, time));
///
/// let time_zone_full = time_zone_at_time.with_zone_variant(ZoneVariant::Standard);
///
/// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
/// &locale!("en-US").into(),
/// O::medium(),
/// )
/// .unwrap();
///
/// assert_try_writeable_eq!(
/// formatter.format(&utc_offset),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&time_zone_basic),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&time_zone_at_time),
/// "GMT-6"
/// );
///
/// assert_try_writeable_eq!(
/// formatter.format(&time_zone_full),
/// "GMT-6"
/// );
/// ```
O,
NeoTimeZoneStyle::Offset,
description = "UTC offset",
sample_length = medium,
sample = "GMT-5",
field_short = (fields::TimeZone::LocalizedOffset, fields::FieldLength::One),
field_long = (fields::TimeZone::LocalizedOffset, fields::FieldLength::Four),
resolved_type = O,
zone_essentials = yes,
enumerated = yes,
);
impl_zone_marker!(
/// When a display name is unavailable, falls back to the location format:
///
/// ```
/// use icu::calendar::{Date, Time};
/// use icu::timezone::{IxdtfParser, TimeZoneBcp47Id, TimeZoneInfo, UtcOffset, ZoneVariant};
/// use icu::calendar::Gregorian;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::V;
/// use icu::locale::locale;
/// use tinystr::tinystr;
/// use writeable::assert_try_writeable_eq;
///
/// // Time zone info for Europe/Istanbul
/// let zone = TimeZoneBcp47Id(tinystr!(8, "trist"))
/// .without_offset()
/// .at_time((Date::try_new_iso(2022, 1, 29).unwrap(), Time::midnight()));
///
/// let fmt = FixedCalendarDateTimeFormatter::<Gregorian, _>::try_new(
/// &locale!("en").into(),
/// V::short(),
/// )
/// .unwrap();
///
/// assert_try_writeable_eq!(
/// fmt.format(&zone),
/// "Türkiye Time"
/// );
/// ```
///
/// Since non-location names might change over time,
/// this time zone style requires a reference time.
///
/// ```compile_fail,E0271
/// use icu::calendar::{DateTime, Iso};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::V;
/// use icu::timezone::{TimeZoneBcp47Id, UtcOffset};
/// use tinystr::tinystr;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let time_zone_basic = TimeZoneBcp47Id(tinystr!(8, "uschi")).without_offset();
///
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
/// &locale!("en-US").into(),
/// V::medium(),
/// )
/// .unwrap();
///
/// // error[E0271]: type mismatch resolving `<Base as TimeZoneModel>::LocalTime == (Date<Iso>, Time)`
/// // note: required by a bound in `FixedCalendarDateTimeFormatter::<C, FSet>::format`
/// formatter.format(&time_zone_basic);
/// ```
V,
NeoTimeZoneStyle::Generic,
description = "time zone in generic non-location format",
sample_length = long,
sample = "Central Time",
field_short = (fields::TimeZone::GenericNonLocation, fields::FieldLength::One),
field_long = (fields::TimeZone::GenericNonLocation, fields::FieldLength::Four),
resolved_type = V,
zone_essentials = yes,
zone_locations = yes,
zone_generic_long = yes,
zone_generic_short = yes,
metazone_periods = yes,
input_tzid = yes,
input_localtime = yes,
enumerated = yes,
);
impl_zone_marker!(
/// Since non-location names might change over time,
/// this time zone style requires a reference time.
///
/// ```compile_fail,E0271
/// use icu::calendar::{DateTime, Iso};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::Vs;
/// use icu::timezone::{TimeZoneBcp47Id, UtcOffset};
/// use tinystr::tinystr;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let time_zone_basic = TimeZoneBcp47Id(tinystr!(8, "uschi")).with_offset("-06".parse().ok());1
///
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
/// &locale!("en-US").into(),
/// Vs::medium(),
/// )
/// .unwrap();
///
/// // error[E0271]: type mismatch resolving `<Base as TimeZoneModel>::LocalTime == (Date<Iso>, Time)`
/// // note: required by a bound in `FixedCalendarDateTimeFormatter::<C, FSet>::format`
/// formatter.format(&time_zone_basic);
/// ```
Vs,
NeoTimeZoneStyle::Generic,
description = "time zone in generic non-location format (only short)",
sample_length = short,
sample = "CT",
field_short = (fields::TimeZone::GenericNonLocation, fields::FieldLength::One),
field_long = (fields::TimeZone::GenericNonLocation, fields::FieldLength::One),
resolved_type = V,
skip_tests = "This field set can be used only in combination with others.",
zone_essentials = yes,
zone_locations = yes,
zone_generic_short = yes,
metazone_periods = yes,
input_tzid = yes,
input_localtime = yes,
);
impl_zone_marker!(
/// A time zone ID is required to format with this style.
/// For example, a raw [`UtcOffset`] cannot be used here.
///
/// ```compile_fail,E0277
/// use icu::calendar::{DateTime, Iso};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::L;
/// use icu::timezone::UtcOffset;
/// use tinystr::tinystr;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let utc_offset = UtcOffset::try_from_str("-06").unwrap();
///
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
/// &locale!("en-US").into(),
/// L::medium(),
/// )
/// .unwrap();
///
/// // error[E0277]: the trait bound `UtcOffset: AllInputMarkers<L>` is not satisfied
/// // note: required by a bound in `FixedCalendarDateTimeFormatter::<C, FSet>::format`
/// formatter.format(&utc_offset);
/// ```
L,
NeoTimeZoneStyle::Location,
description = "time zone in location format",
sample_length = long,
sample = "Chicago Time",
field_short = (fields::TimeZone::Location, fields::FieldLength::Four),
field_long = (fields::TimeZone::Location, fields::FieldLength::Four),
resolved_type = L,
zone_essentials = yes,
zone_locations = yes,
input_tzid = yes,
enumerated = yes,
);
impl_zoneddatetime_marker!(
YMDTV,
description = "locale-dependent date and time fields with a time zone",
sample_length = medium,
sample = "17 May 2024, 15:47:50 GMT",
datetime = YMDT,
zone = Vs,
);
impl_zoneddatetime_marker!(
YMDTZ,
description = "locale-dependent date and time fields with a time zone",
sample_length = medium,
sample = "17 May 2024, 15:47:50 BST",
datetime = YMDT,
zone = Zs,
);
impl_zoneddatetime_marker!(
YMDTO,
description = "locale-dependent date and time fields with a time zone",
sample_length = medium,
sample = "17 May 2024, 15:47:50 GMT+1",
datetime = YMDT,
zone = O,
);
impl_zone_combo_helpers!(DateFieldSet, DateZone, UNREACHABLE, no_wrap);
impl_zone_combo_helpers!(TimeFieldSet, TimeZone, UNREACHABLE, no_wrap);
impl_zone_combo_helpers!(DateAndTimeFieldSet, DateTimeZone, UNREACHABLE, no_wrap);