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
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
// 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 ).

use super::{
    DateTimePattern, DateTimePatternFormatter, GetNameForDayPeriodError, GetNameForMonthError,
    GetNameForWeekdayError, GetSymbolForCyclicYearError, GetSymbolForEraError,
    MonthPlaceholderValue, PatternLoadError,
};
use crate::fields::{self, FieldLength, FieldSymbol};
use crate::fieldsets::enums::CompositeDateTimeFieldSet;
use crate::input;
use crate::provider::neo::*;
use crate::provider::pattern::PatternItem;
use crate::provider::time_zones::tz;
use crate::scaffold::*;
use crate::size_test_macro::size_test;
use crate::{external_loaders::*, DateTimeFormatterPreferences};
use core::fmt;
use core::marker::PhantomData;
use core::num::NonZeroU8;
use icu_calendar::types::FormattingEra;
use icu_calendar::types::MonthCode;
use icu_decimal::options::FixedDecimalFormatterOptions;
use icu_decimal::options::GroupingStrategy;
use icu_decimal::provider::{DecimalDigitsV1Marker, DecimalSymbolsV2Marker};
use icu_decimal::FixedDecimalFormatter;
use icu_provider::prelude::*;

pub struct EmptyDataProvider;

impl<M> DataProvider<M> for EmptyDataProvider
where
    M: DataMarker,
{
    fn load(&self, base_req: DataRequest) -> Result<DataResponse<M>, DataError> {
        Err(DataErrorKind::MarkerNotFound.with_req(M::INFO, base_req))
    }
}

size_test!(
    TypedDateTimeNames<icu_calendar::Gregorian>,
    typed_date_time_names_size,
    328
);

/// A low-level type that formats datetime patterns with localized names.
/// The calendar should be chosen at compile time.
#[doc = typed_date_time_names_size!()]
///
/// Type parameters:
///
/// 1. The calendar chosen at compile time for additional type safety
/// 2. A components object type containing the fields that might be formatted
///
/// By default, the components object is set to [`CompositeDateTimeFieldSet`],
/// meaning that dates and times, but not time zones, are supported. A smaller
/// components object results in smaller stack size.
///
/// To support all fields including time zones, use [`CompositeFieldSet`].
///
/// [`CompositeFieldSet`]: crate::fieldsets::enums::CompositeFieldSet
/// [`CompositeDateTimeFieldSet`]: crate::fieldsets::enums::CompositeDateTimeFieldSet
///
/// # Examples
///
/// ```
/// use icu::calendar::Gregorian;
/// use icu::calendar::DateTime;
/// use icu::datetime::pattern::TypedDateTimeNames;
/// use icu::datetime::fields::FieldLength;
/// use icu::datetime::fields;
/// use icu::datetime::pattern::DateTimePattern;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// // Create an instance that can format abbreviated month, weekday, and day period names:
/// let mut names: TypedDateTimeNames<Gregorian> =
///     TypedDateTimeNames::try_new(locale!("uk").into()).unwrap();
/// names
///     .include_month_names(fields::Month::Format, FieldLength::Three)
///     .unwrap()
///     .include_weekday_names(fields::Weekday::Format, FieldLength::Three)
///     .unwrap()
///     .include_day_period_names(FieldLength::Three)
///     .unwrap();
///
/// // Create a pattern from a pattern string (note: K is the hour with h11 hour cycle):
/// let pattern_str = "E MMM d y -- K:mm a";
/// let pattern: DateTimePattern = pattern_str.parse().unwrap();
///
/// // Test it:
/// let datetime = DateTime::try_new_gregorian(2023, 11, 20, 12, 35, 3).unwrap();
/// assert_try_writeable_eq!(names.with_pattern_unchecked(&pattern).format(&datetime), "пн лист. 20 2023 -- 0:35 пп");
/// ```
///
/// If the correct data is not loaded, and error will occur:
///
/// ```
/// use icu::calendar::Gregorian;
/// use icu::calendar::{Date, Time};
/// use icu::datetime::DateTimeWriteError;
/// use icu::datetime::parts;
/// use icu::datetime::pattern::TypedDateTimeNames;
/// use icu::datetime::fields::{Field, FieldLength, FieldSymbol, Weekday};
/// use icu::datetime::pattern::{DateTimePattern, PatternLoadError};
/// use icu::datetime::fieldsets::enums::CompositeFieldSet;
/// use icu::locale::locale;
/// use icu::timezone::{TimeZoneInfo, IxdtfParser};
/// use icu_provider_adapters::empty::EmptyDataProvider;
/// use writeable::{Part, assert_try_writeable_parts_eq};
///
/// // Create an instance that can format all fields (CompositeFieldSet):
/// let mut names: TypedDateTimeNames<Gregorian, CompositeFieldSet> =
///     TypedDateTimeNames::try_new(locale!("en").into()).unwrap();
///
/// // Create a pattern from a pattern string:
/// let pattern_str = "'It is:' E MMM d y G 'at' h:mm:ssSSS a zzzz";
/// let pattern: DateTimePattern = pattern_str.parse().unwrap();
///
/// // The pattern string contains lots of symbols including "E", "MMM", and "a",
/// // but we did not load any data!
///
/// let mut dtz = IxdtfParser::new().try_from_str("2023-11-20T11:35:03+00:00[Europe/London]").unwrap().to_calendar(Gregorian);
///
/// // Missing data is filled in on a best-effort basis, and an error is signaled.
/// assert_try_writeable_parts_eq!(
///     names.with_pattern_unchecked(&pattern).format(&dtz),
///     "It is: mon M11 20 2023 CE at 11:35:03.000 AM +0000",
///     Err(DateTimeWriteError::NamesNotLoaded(Field { symbol: FieldSymbol::Weekday(Weekday::Format), length: FieldLength::One })),
///     [
///         (7, 10, Part::ERROR), // mon
///         (7, 10, parts::WEEKDAY), // mon
///         (11, 14, Part::ERROR), // M11
///         (11, 14, parts::MONTH), // M11
///         (15, 17, icu::decimal::parts::INTEGER), // 20
///         (15, 17, parts::DAY), // 20
///         (18, 22, icu::decimal::parts::INTEGER), // 2023
///         (18, 22, parts::YEAR), // 2023
///         (23, 25, Part::ERROR), // CE
///         (23, 25, parts::ERA), // CE
///         (29, 31, icu::decimal::parts::INTEGER), // 11
///         (29, 31, parts::HOUR), // 11
///         (32, 34, icu::decimal::parts::INTEGER), // 35
///         (32, 34, parts::MINUTE), // 35
///         (35, 41, parts::SECOND), // 03.000
///         (35, 37, icu::decimal::parts::INTEGER), // 03
///         (37, 38, icu::decimal::parts::DECIMAL), // .
///         (38, 41, icu::decimal::parts::FRACTION), // 000
///         (42, 44, Part::ERROR), // AM
///         (42, 44, parts::DAY_PERIOD), // AM
///         (45, 50, Part::ERROR), // +0000
///         (45, 50, parts::TIME_ZONE_NAME), // +0000
///     ]
/// );
///
/// // To make the error occur sooner, one can use an EmptyDataProvider:
/// let empty = EmptyDataProvider::new();
/// assert!(matches!(
///     names.load_for_pattern(&empty, &pattern),
///     Err(PatternLoadError::Data(_, Field { symbol: FieldSymbol::Weekday(_), .. })),
/// ));
/// ```
///
/// If the pattern contains fields inconsistent with the receiver, an error will occur:
///
/// ```
/// use icu::calendar::Gregorian;
/// use icu::calendar::DateTime;
/// use icu::datetime::DateTimeWriteError;
/// use icu::datetime::parts;
/// use icu::datetime::pattern::TypedDateTimeNames;
/// use icu::datetime::fields::{Field, FieldLength, FieldSymbol, Weekday};
/// use icu::datetime::pattern::DateTimePattern;
/// use icu::datetime::fieldsets::O;
/// use icu::locale::locale;
/// use icu::timezone::TimeZoneInfo;
/// use writeable::{Part, assert_try_writeable_parts_eq};
///
/// // Create an instance that can format abbreviated month, weekday, and day period names:
/// let mut names: TypedDateTimeNames<Gregorian, O> =
///     TypedDateTimeNames::try_new(locale!("en").into()).unwrap();
///
/// // Create a pattern from a pattern string:
/// let pattern_str = "'It is:' E MMM d y G 'at' h:mm:ssSSS a zzzz";
/// let pattern: DateTimePattern = pattern_str.parse().unwrap();
///
/// // The pattern string contains lots of symbols including "E", "MMM", and "a",
/// // but the `TypedDateTimeNames` is configured to format only time zones!
/// // Further, the time zone we provide doesn't contain any offset into!
/// // Missing data is filled in on a best-effort basis, and an error is signaled.
/// assert_try_writeable_parts_eq!(
///     names.with_pattern_unchecked(&pattern).format(&TimeZoneInfo::unknown()),
///     "It is: {E} {M} {d} {y} {G} at {h}:{m}:{s} {a} {z}",
///     Err(DateTimeWriteError::MissingInputField("iso_weekday")),
///     [
///         (7, 10, Part::ERROR), // {E}
///         (7, 10, parts::WEEKDAY), // {E}
///         (11, 14, Part::ERROR), // {M}
///         (11, 14, parts::MONTH), // {M}
///         (15, 18, Part::ERROR), // {d}
///         (15, 18, parts::DAY), // {d}
///         (19, 22, Part::ERROR), // {y}
///         (19, 22, parts::YEAR), // {y}
///         (23, 26, Part::ERROR), // {G}
///         (23, 26, parts::ERA), // {G}
///         (30, 33, Part::ERROR), // {h}
///         (30, 33, parts::HOUR), // {h}
///         (34, 37, Part::ERROR), // {m}
///         (34, 37, parts::MINUTE), // {m}
///         (38, 41, Part::ERROR), // {s}
///         (38, 41, parts::SECOND), // {s}
///         (42, 45, Part::ERROR), // {a}
///         (42, 45, parts::DAY_PERIOD), // {a}
///         (46, 49, Part::ERROR), // {z}
///         (46, 49, parts::TIME_ZONE_NAME), // {z}
///     ]
/// );
/// ```
#[derive(Debug)]
pub struct TypedDateTimeNames<
    C: CldrCalendar,
    FSet: DateTimeNamesMarker = CompositeDateTimeFieldSet,
> {
    prefs: DateTimeFormatterPreferences,
    inner: RawDateTimeNames<FSet>,
    _calendar: PhantomData<C>,
}

pub(crate) struct RawDateTimeNames<FSet: DateTimeNamesMarker> {
    year_names: <FSet::YearNames as NamesContainer<YearNamesV1Marker, FieldLength>>::Container,
    month_names: <FSet::MonthNames as NamesContainer<
        MonthNamesV1Marker,
        (fields::Month, FieldLength),
    >>::Container,
    weekday_names: <FSet::WeekdayNames as NamesContainer<
        WeekdayNamesV1Marker,
        (fields::Weekday, FieldLength),
    >>::Container,
    dayperiod_names:
        <FSet::DayPeriodNames as NamesContainer<DayPeriodNamesV1Marker, FieldLength>>::Container,
    zone_essentials:
        <FSet::ZoneEssentials as NamesContainer<tz::EssentialsV1Marker, ()>>::Container,
    locations_root: <FSet::ZoneLocations as NamesContainer<tz::LocationsV1Marker, ()>>::Container,
    locations: <FSet::ZoneLocations as NamesContainer<tz::LocationsV1Marker, ()>>::Container,
    mz_generic_long:
        <FSet::ZoneGenericLong as NamesContainer<tz::MzGenericLongV1Marker, ()>>::Container,
    mz_generic_short:
        <FSet::ZoneGenericShort as NamesContainer<tz::MzGenericShortV1Marker, ()>>::Container,
    mz_specific_long:
        <FSet::ZoneSpecificLong as NamesContainer<tz::MzSpecificLongV1Marker, ()>>::Container,
    mz_specific_short:
        <FSet::ZoneSpecificShort as NamesContainer<tz::MzSpecificShortV1Marker, ()>>::Container,
    mz_periods: <FSet::MetazoneLookup as NamesContainer<tz::MzPeriodV1Marker, ()>>::Container,
    // TODO(#4340): Make the FixedDecimalFormatter optional
    fixed_decimal_formatter: Option<FixedDecimalFormatter>,
    _marker: PhantomData<FSet>,
}

// Need a custom impl because not all of the associated types impl Debug
impl<FSet: DateTimeNamesMarker> fmt::Debug for RawDateTimeNames<FSet> {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        f.debug_struct("RawDateTimeNames")
            .field("year_names", &self.year_names)
            .field("month_names", &self.month_names)
            .field("weekday_names", &self.weekday_names)
            .field("dayperiod_names", &self.dayperiod_names)
            .field("zone_essentials", &self.zone_essentials)
            .field("locations", &self.locations)
            .field("mz_generic_long", &self.mz_generic_long)
            .field("mz_generic_short", &self.mz_generic_short)
            .field("mz_specific_long", &self.mz_specific_long)
            .field("mz_specific_short", &self.mz_specific_short)
            .field("fixed_decimal_formatter", &self.fixed_decimal_formatter)
            .finish()
    }
}

impl<FSet: DateTimeNamesMarker> RawDateTimeNames<FSet> {
    pub(crate) fn with_fset<FSet2: DateTimeNamesFrom<FSet>>(self) -> RawDateTimeNames<FSet2> {
        RawDateTimeNames {
            year_names: FSet2::map_year_names(self.year_names),
            month_names: FSet2::map_month_names(self.month_names),
            weekday_names: FSet2::map_weekday_names(self.weekday_names),
            dayperiod_names: FSet2::map_day_period_names(self.dayperiod_names),
            zone_essentials: FSet2::map_zone_essentials(self.zone_essentials),
            locations_root: FSet2::map_zone_locations(self.locations_root),
            locations: FSet2::map_zone_locations(self.locations),
            mz_generic_long: FSet2::map_zone_generic_long(self.mz_generic_long),
            mz_generic_short: FSet2::map_zone_generic_short(self.mz_generic_short),
            mz_specific_long: FSet2::map_zone_specific_long(self.mz_specific_long),
            mz_specific_short: FSet2::map_zone_specific_short(self.mz_specific_short),
            mz_periods: FSet2::map_metazone_lookup(self.mz_periods),
            fixed_decimal_formatter: self.fixed_decimal_formatter,
            _marker: PhantomData,
        }
    }
}

#[derive(Debug, Copy, Clone)]
pub(crate) struct RawDateTimeNamesBorrowed<'l> {
    year_names: OptionalNames<FieldLength, &'l YearNamesV1<'l>>,
    month_names: OptionalNames<(fields::Month, FieldLength), &'l MonthNamesV1<'l>>,
    weekday_names: OptionalNames<(fields::Weekday, FieldLength), &'l LinearNamesV1<'l>>,
    dayperiod_names: OptionalNames<FieldLength, &'l LinearNamesV1<'l>>,
    zone_essentials: OptionalNames<(), &'l tz::EssentialsV1<'l>>,
    locations_root: OptionalNames<(), &'l tz::LocationsV1<'l>>,
    locations: OptionalNames<(), &'l tz::LocationsV1<'l>>,
    mz_generic_long: OptionalNames<(), &'l tz::MzGenericV1<'l>>,
    mz_generic_short: OptionalNames<(), &'l tz::MzGenericV1<'l>>,
    mz_specific_long: OptionalNames<(), &'l tz::MzSpecificV1<'l>>,
    mz_specific_short: OptionalNames<(), &'l tz::MzSpecificV1<'l>>,
    mz_periods: OptionalNames<(), &'l tz::MzPeriodV1<'l>>,
    pub(crate) fixed_decimal_formatter: Option<&'l FixedDecimalFormatter>,
}

impl<C: CldrCalendar, FSet: DateTimeNamesMarker> TypedDateTimeNames<C, FSet> {
    /// Constructor that takes a selected locale and creates an empty instance.
    ///
    /// For an example, see [`TypedDateTimeNames`].
    ///
    /// ✨ *Enabled with the `compiled_data` Cargo feature.*
    ///
    /// [📚 Help choosing a constructor](icu_provider::constructors)
    #[cfg(feature = "compiled_data")]
    pub fn try_new(prefs: DateTimeFormatterPreferences) -> Result<Self, DataError> {
        let mut names = Self {
            prefs,
            inner: RawDateTimeNames::new_without_number_formatting(),
            _calendar: PhantomData,
        };
        names.include_fixed_decimal_formatter()?;
        Ok(names)
    }

    #[doc = icu_provider::gen_any_buffer_unstable_docs!(UNSTABLE, Self::try_new)]
    pub fn try_new_unstable<P>(
        provider: &P,
        prefs: DateTimeFormatterPreferences,
    ) -> Result<Self, DataError>
    where
        P: DataProvider<DecimalSymbolsV2Marker> + DataProvider<DecimalDigitsV1Marker> + ?Sized,
    {
        let mut names = Self {
            prefs,
            inner: RawDateTimeNames::new_without_number_formatting(),
            _calendar: PhantomData,
        };
        names.load_fixed_decimal_formatter(provider)?;
        Ok(names)
    }

    /// Creates a completely empty instance, not even with number formatting.
    ///
    /// # Examples
    ///
    /// Errors occur if a number formatter is not loaded but one is required:
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::calendar::Date;
    /// use icu::datetime::parts;
    /// use icu::datetime::DateTimeWriteError;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::datetime::fields::{Field, FieldLength, FieldSymbol, Weekday};
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::fieldsets::enums::DateFieldSet;
    /// use icu::locale::locale;
    /// use writeable::{Part, assert_try_writeable_parts_eq};
    ///
    /// // Create an instance that can format only date fields:
    /// let names: TypedDateTimeNames<Gregorian, DateFieldSet> =
    ///     TypedDateTimeNames::new_without_number_formatting(locale!("en").into());
    ///
    /// // Create a pattern from a pattern string:
    /// let pattern_str = "'It is:' y-MM-dd";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// // The pattern string contains lots of numeric symbols,
    /// // but we did not load any data!
    ///
    /// let date = Date::try_new_gregorian(2024, 7, 1).unwrap();
    ///
    /// // Missing data is filled in on a best-effort basis, and an error is signaled.
    /// // (note that the padding is ignored in this fallback mode)
    /// assert_try_writeable_parts_eq!(
    ///     names.with_pattern_unchecked(&pattern).format(&date),
    ///     "It is: 2024-07-01",
    ///     Err(DateTimeWriteError::FixedDecimalFormatterNotLoaded),
    ///     [
    ///         (7, 11, Part::ERROR), // 2024
    ///         (7, 11, parts::YEAR), // 2024
    ///         (12, 14, Part::ERROR), // 07
    ///         (12, 14, parts::MONTH), // 07
    ///         (15, 17, Part::ERROR), // 01
    ///         (15, 17, parts::DAY), // 01
    ///     ]
    /// );
    /// ```
    pub fn new_without_number_formatting(prefs: DateTimeFormatterPreferences) -> Self {
        Self {
            prefs,
            inner: RawDateTimeNames::new_without_number_formatting(),
            _calendar: PhantomData,
        }
    }

    /// Loads year (era or cycle) names for the specified length.
    ///
    /// Does not support multiple field symbols or lengths. See #4337
    pub fn load_year_names<P>(
        &mut self,
        provider: &P,
        field_length: FieldLength,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<C::YearNamesV1Marker> + ?Sized,
    {
        self.inner.load_year_names(
            &C::YearNamesV1Marker::bind(provider),
            self.prefs,
            field_length,
        )?;
        Ok(self)
    }

    /// Includes year (era or cycle) names for the specified length.
    ///
    /// Does not support multiple field symbols or lengths. See #4337
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fields::FieldLength;
    /// use icu::datetime::pattern::PatternLoadError;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    ///
    /// let mut names =
    ///     TypedDateTimeNames::<Gregorian>::try_new(locale!("und").into())
    ///         .unwrap();
    ///
    /// // First length is successful:
    /// names.include_year_names(FieldLength::Four).unwrap();
    ///
    /// // Attempting to load the first length a second time will succeed:
    /// names.include_year_names(FieldLength::Four).unwrap();
    ///
    /// // But loading a new length fails:
    /// assert!(matches!(
    ///     names.include_year_names(FieldLength::Three),
    ///     Err(PatternLoadError::ConflictingField(_))
    /// ));
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_year_names(
        &mut self,
        field_length: FieldLength,
    ) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<<C as CldrCalendar>::YearNamesV1Marker>,
    {
        self.load_year_names(&crate::provider::Baked, field_length)
    }

    /// Loads month names for the specified symbol and length.
    ///
    /// Does not support multiple field symbols or lengths. See #4337
    pub fn load_month_names<P>(
        &mut self,
        provider: &P,
        field_symbol: fields::Month,
        field_length: FieldLength,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<C::MonthNamesV1Marker> + ?Sized,
    {
        self.inner.load_month_names(
            &C::MonthNamesV1Marker::bind(provider),
            self.prefs,
            field_symbol,
            field_length,
        )?;
        Ok(self)
    }

    /// Includes month names for the specified symbol and length.
    ///
    /// Does not support multiple field symbols or lengths. See #4337
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fields::FieldLength;
    /// use icu::datetime::pattern::PatternLoadError;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    ///
    /// let mut names =
    ///     TypedDateTimeNames::<Gregorian>::try_new(locale!("und").into())
    ///         .unwrap();
    /// let field_symbol = icu::datetime::fields::Month::Format;
    /// let alt_field_symbol = icu::datetime::fields::Month::StandAlone;
    ///
    /// // First length is successful:
    /// names
    ///     .include_month_names(field_symbol, FieldLength::Four)
    ///     .unwrap();
    ///
    /// // Attempting to load the first length a second time will succeed:
    /// names
    ///     .include_month_names(field_symbol, FieldLength::Four)
    ///     .unwrap();
    ///
    /// // But loading a new symbol or length fails:
    /// assert!(matches!(
    ///     names.include_month_names(alt_field_symbol, FieldLength::Four),
    ///     Err(PatternLoadError::ConflictingField(_))
    /// ));
    /// assert!(matches!(
    ///     names.include_month_names(field_symbol, FieldLength::Three),
    ///     Err(PatternLoadError::ConflictingField(_))
    /// ));
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_month_names(
        &mut self,
        field_symbol: fields::Month,
        field_length: FieldLength,
    ) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<<C as CldrCalendar>::MonthNamesV1Marker>,
    {
        self.load_month_names(&crate::provider::Baked, field_symbol, field_length)
    }

    /// Loads day period names for the specified length.
    ///
    /// Does not support multiple field symbols or lengths. See #4337
    pub fn load_day_period_names<P>(
        &mut self,
        provider: &P,
        field_length: FieldLength,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<DayPeriodNamesV1Marker> + ?Sized,
    {
        let provider = DayPeriodNamesV1Marker::bind(provider);
        self.inner
            .load_day_period_names(&provider, self.prefs, field_length)?;
        Ok(self)
    }

    /// Includes day period names for the specified length.
    ///
    /// Does not support multiple field symbols or lengths. See #4337
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fields::FieldLength;
    /// use icu::datetime::pattern::PatternLoadError;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    ///
    /// let mut names =
    ///     TypedDateTimeNames::<Gregorian>::try_new(locale!("und").into())
    ///         .unwrap();
    ///
    /// // First length is successful:
    /// names.include_day_period_names(FieldLength::Four).unwrap();
    ///
    /// // Attempting to load the first length a second time will succeed:
    /// names.include_day_period_names(FieldLength::Four).unwrap();
    ///
    /// // But loading a new length fails:
    /// assert!(matches!(
    ///     names.include_day_period_names(FieldLength::Three),
    ///     Err(PatternLoadError::ConflictingField(_))
    /// ));
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_day_period_names(
        &mut self,
        field_length: FieldLength,
    ) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<DayPeriodNamesV1Marker>,
    {
        self.load_day_period_names(&crate::provider::Baked, field_length)
    }

    /// Loads weekday names for the specified symbol and length.
    ///
    /// Does not support multiple field symbols or lengths. See #4337
    pub fn load_weekday_names<P>(
        &mut self,
        provider: &P,
        field_symbol: fields::Weekday,
        field_length: FieldLength,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<WeekdayNamesV1Marker> + ?Sized,
    {
        self.inner.load_weekday_names(
            &WeekdayNamesV1Marker::bind(provider),
            self.prefs,
            field_symbol,
            field_length,
        )?;
        Ok(self)
    }

    /// Includes weekday names for the specified symbol and length.
    ///
    /// Does not support multiple field symbols or lengths. See #4337
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fields::FieldLength;
    /// use icu::datetime::pattern::PatternLoadError;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    ///
    /// let mut names =
    ///     TypedDateTimeNames::<Gregorian>::try_new(locale!("und").into())
    ///         .unwrap();
    /// let field_symbol = icu::datetime::fields::Weekday::Format;
    /// let alt_field_symbol = icu::datetime::fields::Weekday::StandAlone;
    ///
    /// // First length is successful:
    /// names
    ///     .include_weekday_names(field_symbol, FieldLength::Four)
    ///     .unwrap();
    ///
    /// // Attempting to load the first length a second time will succeed:
    /// names
    ///     .include_weekday_names(field_symbol, FieldLength::Four)
    ///     .unwrap();
    ///
    /// // But loading a new symbol or length fails:
    /// assert!(matches!(
    ///     names.include_weekday_names(alt_field_symbol, FieldLength::Four),
    ///     Err(PatternLoadError::ConflictingField(_))
    /// ));
    /// assert!(matches!(
    ///     names.include_weekday_names(field_symbol, FieldLength::Three),
    ///     Err(PatternLoadError::ConflictingField(_))
    /// ));
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_weekday_names(
        &mut self,
        field_symbol: fields::Weekday,
        field_length: FieldLength,
    ) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<WeekdayNamesV1Marker>,
    {
        self.load_weekday_names(&crate::provider::Baked, field_symbol, field_length)
    }

    /// Loads shared essential patterns for time zone formatting.
    pub fn load_time_zone_essentials<P>(
        &mut self,
        provider: &P,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<tz::EssentialsV1Marker> + ?Sized,
    {
        self.inner
            .load_time_zone_essentials(&tz::EssentialsV1Marker::bind(provider), self.prefs)?;
        Ok(self)
    }

    /// Includes shared essential patterns for time zone formatting.
    ///
    /// This data should always be loaded when performing time zone formatting.
    /// By itself, it allows localized offset formats.
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fieldsets::enums::ZoneFieldSet;
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    /// use icu::timezone::IxdtfParser;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// let mut zone_london_winter = IxdtfParser::new()
    ///     .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    /// let mut zone_london_summer = IxdtfParser::new()
    ///     .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    ///
    /// let mut names = TypedDateTimeNames::<Gregorian, ZoneFieldSet>::try_new(
    ///     locale!("en-GB").into(),
    /// )
    /// .unwrap();
    ///
    /// names.include_time_zone_essentials().unwrap();
    ///
    /// // Create a pattern with symbol `OOOO`:
    /// let pattern_str = "'Your time zone is:' OOOO";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: GMT",
    /// );
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_summer),
    ///     "Your time zone is: GMT+01:00",
    /// );
    ///
    /// // Now try `V`:
    /// let pattern_str = "'Your time zone is:' V";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: gblon",
    /// );
    ///
    /// // Now try `Z`:
    /// let pattern_str = "'Your time zone is:' Z";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: +0000",
    /// );
    ///
    /// // Now try `ZZZZZ`:
    /// let pattern_str = "'Your time zone is:' ZZZZZ";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: Z",
    /// );
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_summer),
    ///     "Your time zone is: +01:00",
    /// );
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_time_zone_essentials(&mut self) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<tz::EssentialsV1Marker>,
    {
        self.load_time_zone_essentials(&crate::provider::Baked)
    }

    /// Loads location names for time zone formatting.
    pub fn load_time_zone_location_names<P>(
        &mut self,
        provider: &P,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<tz::LocationsV1Marker> + ?Sized,
    {
        self.inner
            .load_time_zone_location_names(&tz::LocationsV1Marker::bind(provider), self.prefs)?;
        Ok(self)
    }

    /// Includes location names for time zone formatting.
    ///
    /// Important: When performing manual time zone data loading, in addition to the
    /// specific time zone format data, also call either:
    ///
    /// - [`TypedDateTimeNames::include_time_zone_essentials`]
    /// - [`TypedDateTimeNames::load_time_zone_essentials`]
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fieldsets::enums::ZoneFieldSet;
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    /// use icu::timezone::IxdtfParser;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// let mut zone_london_winter = IxdtfParser::new()
    ///     .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    ///
    /// let mut names = TypedDateTimeNames::<Gregorian, ZoneFieldSet>::try_new(
    ///     locale!("en-GB").into(),
    /// )
    /// .unwrap();
    ///
    /// names.include_time_zone_essentials().unwrap();
    /// names.include_time_zone_location_names().unwrap();
    ///
    /// // Try `VVVV`:
    /// let pattern_str = "'Your time zone is:' VVVV";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: UK Time",
    /// );
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_time_zone_location_names(&mut self) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<tz::MzGenericShortV1Marker>,
    {
        self.load_time_zone_location_names(&crate::provider::Baked)
    }

    /// Loads generic non-location long time zone names.
    pub fn load_time_zone_generic_long_names<P>(
        &mut self,
        provider: &P,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<tz::MzGenericLongV1Marker> + DataProvider<tz::MzPeriodV1Marker> + ?Sized,
    {
        self.inner.load_time_zone_generic_long_names(
            &tz::MzGenericLongV1Marker::bind(provider),
            &tz::MzPeriodV1Marker::bind(provider),
            self.prefs,
        )?;
        Ok(self)
    }

    /// Includes generic non-location long time zone names.
    ///
    /// Important: When performing manual time zone data loading, in addition to the
    /// specific time zone format data, also call either:
    ///
    /// - [`TypedDateTimeNames::include_time_zone_essentials`]
    /// - [`TypedDateTimeNames::load_time_zone_essentials`]
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fieldsets::enums::ZoneFieldSet;
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    /// use icu::timezone::IxdtfParser;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// let mut zone_london_winter = IxdtfParser::new()
    ///     .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    /// let mut zone_london_summer = IxdtfParser::new()
    ///     .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    ///
    /// let mut names = TypedDateTimeNames::<Gregorian, ZoneFieldSet>::try_new(
    ///     locale!("en-GB").into(),
    /// )
    /// .unwrap();
    ///
    /// names.include_time_zone_essentials().unwrap();
    /// names.include_time_zone_generic_long_names().unwrap();
    ///
    /// // Create a pattern with symbol `vvvv`:
    /// let pattern_str = "'Your time zone is:' vvvv";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: Greenwich Mean Time",
    /// );
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_summer),
    ///     "Your time zone is: Greenwich Mean Time", // TODO
    /// );
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_time_zone_generic_long_names(&mut self) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<tz::MzGenericLongV1Marker>,
    {
        self.load_time_zone_generic_long_names(&crate::provider::Baked)
    }

    /// Loads generic non-location short time zone names.
    pub fn load_time_zone_generic_short_names<P>(
        &mut self,
        provider: &P,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<tz::MzGenericShortV1Marker> + DataProvider<tz::MzPeriodV1Marker> + ?Sized,
    {
        self.inner.load_time_zone_generic_short_names(
            &tz::MzGenericShortV1Marker::bind(provider),
            &tz::MzPeriodV1Marker::bind(provider),
            self.prefs,
        )?;
        Ok(self)
    }

    /// Includes generic non-location short time zone names.
    ///
    /// Important: When performing manual time zone data loading, in addition to the
    /// specific time zone format data, also call either:
    ///
    /// - [`TypedDateTimeNames::include_time_zone_essentials`]
    /// - [`TypedDateTimeNames::load_time_zone_essentials`]
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fieldsets::enums::ZoneFieldSet;
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    /// use icu::timezone::IxdtfParser;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// let mut zone_london_winter = IxdtfParser::new()
    ///     .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    /// let mut zone_london_summer = IxdtfParser::new()
    ///     .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    ///
    /// let mut names = TypedDateTimeNames::<Gregorian, ZoneFieldSet>::try_new(
    ///     locale!("en-GB").into(),
    /// )
    /// .unwrap();
    ///
    /// names.include_time_zone_essentials().unwrap();
    /// names.include_time_zone_generic_short_names().unwrap();
    ///
    /// // Create a pattern with symbol `v`:
    /// let pattern_str = "'Your time zone is:' v";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: GMT",
    /// );
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_summer),
    ///     "Your time zone is: GMT", // TODO
    /// );
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_time_zone_generic_short_names(&mut self) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<tz::MzGenericShortV1Marker>,
    {
        self.load_time_zone_generic_short_names(&crate::provider::Baked)
    }

    /// Loads specific non-location long time zone names.
    pub fn load_time_zone_specific_long_names<P>(
        &mut self,
        provider: &P,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<tz::MzSpecificLongV1Marker> + DataProvider<tz::MzPeriodV1Marker> + ?Sized,
    {
        self.inner.load_time_zone_specific_long_names(
            &tz::MzSpecificLongV1Marker::bind(provider),
            &tz::MzPeriodV1Marker::bind(provider),
            self.prefs,
        )?;
        Ok(self)
    }

    /// Includes specific non-location long time zone names.
    ///
    /// Important: When performing manual time zone data loading, in addition to the
    /// specific time zone format data, also call either:
    ///
    /// - [`TypedDateTimeNames::include_time_zone_essentials`]
    /// - [`TypedDateTimeNames::load_time_zone_essentials`]
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fieldsets::enums::ZoneFieldSet;
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    /// use icu::timezone::IxdtfParser;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// let mut zone_london_winter = IxdtfParser::new()
    ///     .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    /// let mut zone_london_summer = IxdtfParser::new()
    ///     .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    ///
    /// let mut names = TypedDateTimeNames::<Gregorian, ZoneFieldSet>::try_new(
    ///     locale!("en-GB").into(),
    /// )
    /// .unwrap();
    ///
    /// names.include_time_zone_essentials().unwrap();
    /// names.include_time_zone_specific_long_names().unwrap();
    ///
    /// // Create a pattern with symbol `zzzz`:
    /// let pattern_str = "'Your time zone is:' zzzz";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: Greenwich Mean Time",
    /// );
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_summer),
    ///     "Your time zone is: British Summer Time",
    /// );
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_time_zone_specific_long_names(&mut self) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<tz::MzSpecificLongV1Marker>,
    {
        self.load_time_zone_specific_long_names(&crate::provider::Baked)
    }

    /// Loads specific non-location short time zone names.
    pub fn load_time_zone_specific_short_names<P>(
        &mut self,
        provider: &P,
    ) -> Result<&mut Self, PatternLoadError>
    where
        P: DataProvider<tz::MzSpecificShortV1Marker> + DataProvider<tz::MzPeriodV1Marker> + ?Sized,
    {
        self.inner.load_time_zone_specific_short_names(
            &tz::MzSpecificShortV1Marker::bind(provider),
            &tz::MzPeriodV1Marker::bind(provider),
            self.prefs,
        )?;
        Ok(self)
    }

    /// Includes specific non-location short time zone names.
    ///
    /// Important: When performing manual time zone data loading, in addition to the
    /// specific time zone format data, also call either:
    ///
    /// - [`TypedDateTimeNames::include_time_zone_essentials`]
    /// - [`TypedDateTimeNames::load_time_zone_essentials`]
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::fieldsets::enums::ZoneFieldSet;
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    /// use icu::timezone::IxdtfParser;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// let mut zone_london_winter = IxdtfParser::new()
    ///     .try_from_str("2024-01-01T00:00:00+00:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    /// let mut zone_london_summer = IxdtfParser::new()
    ///     .try_from_str("2024-07-01T00:00:00+01:00[Europe/London]")
    ///     .unwrap()
    ///     .zone;
    ///
    /// let mut names = TypedDateTimeNames::<Gregorian, ZoneFieldSet>::try_new(
    ///     locale!("en-GB").into(),
    /// )
    /// .unwrap();
    ///
    /// names.include_time_zone_essentials().unwrap();
    /// names.include_time_zone_specific_short_names().unwrap();
    ///
    /// // Create a pattern with symbol `z`:
    /// let pattern_str = "'Your time zone is:' z";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_winter),
    ///     "Your time zone is: GMT",
    /// );
    /// assert_try_writeable_eq!(
    ///     names
    ///         .with_pattern_unchecked(&pattern)
    ///         .format(&zone_london_summer),
    ///     "Your time zone is: BST",
    /// );
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_time_zone_specific_short_names(&mut self) -> Result<&mut Self, PatternLoadError>
    where
        crate::provider::Baked: icu_provider::DataProvider<tz::MzSpecificShortV1Marker>,
    {
        self.load_time_zone_specific_short_names(&crate::provider::Baked)
    }

    /// Loads a [`FixedDecimalFormatter`] from a data provider.
    #[inline]
    pub fn load_fixed_decimal_formatter<P>(&mut self, provider: &P) -> Result<&mut Self, DataError>
    where
        P: DataProvider<DecimalSymbolsV2Marker> + DataProvider<DecimalDigitsV1Marker> + ?Sized,
    {
        self.inner
            .load_fixed_decimal_formatter(&ExternalLoaderUnstable(provider), self.prefs)?;
        Ok(self)
    }

    /// Loads a [`FixedDecimalFormatter`] with compiled data.
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Time;
    /// use icu::datetime::fieldsets::enums::TimeFieldSet;
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// let mut names =
    ///     TypedDateTimeNames::<(), TimeFieldSet>::try_new(locale!("bn").into())
    ///         .unwrap();
    /// names.include_fixed_decimal_formatter();
    ///
    /// // Create a pattern for the time, which is all numbers
    /// let pattern_str = "'The current 24-hour time is:' HH:mm";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// let time = Time::try_new(6, 40, 33, 0).unwrap();
    ///
    /// assert_try_writeable_eq!(
    ///     names.with_pattern_unchecked(&pattern).format(&time),
    ///     "The current 24-hour time is: ০৬:৪০",
    /// );
    /// ```
    #[cfg(feature = "compiled_data")]
    #[inline]
    pub fn include_fixed_decimal_formatter(&mut self) -> Result<&mut Self, DataError> {
        self.inner
            .load_fixed_decimal_formatter(&ExternalLoaderCompiledData, self.prefs)?;
        Ok(self)
    }

    /// Associates this [`TypedDateTimeNames`] with a pattern
    /// without checking that all necessary data is loaded.
    #[inline]
    pub fn with_pattern_unchecked<'l>(
        &'l self,
        pattern: &'l DateTimePattern,
    ) -> DateTimePatternFormatter<'l, C, FSet> {
        DateTimePatternFormatter::new(pattern.as_borrowed(), self.inner.as_borrowed())
    }

    /// Associates this [`TypedDateTimeNames`] with a datetime pattern
    /// and loads all data required for that pattern.
    ///
    /// Does not duplicate textual field symbols. See #4337
    pub fn load_for_pattern<'l, P>(
        &'l mut self,
        provider: &P,
        pattern: &'l DateTimePattern,
    ) -> Result<DateTimePatternFormatter<'l, C, FSet>, PatternLoadError>
    where
        P: DataProvider<C::YearNamesV1Marker>
            + DataProvider<C::MonthNamesV1Marker>
            + DataProvider<WeekdayNamesV1Marker>
            + DataProvider<DayPeriodNamesV1Marker>
            + DataProvider<tz::EssentialsV1Marker>
            + DataProvider<tz::LocationsV1Marker>
            + DataProvider<tz::MzGenericLongV1Marker>
            + DataProvider<tz::MzGenericShortV1Marker>
            + DataProvider<tz::MzSpecificLongV1Marker>
            + DataProvider<tz::MzSpecificShortV1Marker>
            + DataProvider<tz::MzPeriodV1Marker>
            + DataProvider<DecimalSymbolsV2Marker>
            + DataProvider<DecimalDigitsV1Marker>
            + ?Sized,
    {
        let locale = self.prefs;
        self.inner.load_for_pattern(
            &C::YearNamesV1Marker::bind(provider),
            &C::MonthNamesV1Marker::bind(provider),
            &WeekdayNamesV1Marker::bind(provider),
            &DayPeriodNamesV1Marker::bind(provider),
            // TODO: Consider making time zone name loading optional here (lots of data)
            &tz::EssentialsV1Marker::bind(provider),
            &tz::LocationsV1Marker::bind(provider),
            &tz::MzGenericLongV1Marker::bind(provider),
            &tz::MzGenericShortV1Marker::bind(provider),
            &tz::MzSpecificLongV1Marker::bind(provider),
            &tz::MzSpecificShortV1Marker::bind(provider),
            &tz::MzPeriodV1Marker::bind(provider),
            &ExternalLoaderUnstable(provider),
            locale,
            pattern.iter_items(),
        )?;
        Ok(DateTimePatternFormatter::new(
            pattern.as_borrowed(),
            self.inner.as_borrowed(),
        ))
    }

    /// Associates this [`TypedDateTimeNames`] with a pattern
    /// and includes all data required for that pattern.
    ///
    /// Does not support duplicate textual field symbols. See #4337
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::DateTime;
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::locale::locale;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// let mut names =
    ///     TypedDateTimeNames::<Gregorian>::try_new(locale!("en").into()).unwrap();
    ///
    /// // Create a pattern from a pattern string:
    /// let pattern_str = "MMM d (EEEE) 'of year' y G 'at' h:mm a";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    ///
    /// // Load data for the pattern and format:
    /// let datetime =
    ///     DateTime::try_new_gregorian(2023, 12, 5, 17, 43, 12).unwrap();
    /// assert_try_writeable_eq!(
    ///     names
    ///         .include_for_pattern(&pattern)
    ///         .unwrap()
    ///         .format(&datetime),
    ///     "Dec 5 (Tuesday) of year 2023 AD at 5:43 PM"
    /// );
    /// ```
    #[cfg(feature = "compiled_data")]
    pub fn include_for_pattern<'l>(
        &'l mut self,
        pattern: &'l DateTimePattern,
    ) -> Result<DateTimePatternFormatter<'l, C, FSet>, PatternLoadError>
    where
        crate::provider::Baked: DataProvider<C::YearNamesV1Marker>
            + DataProvider<C::MonthNamesV1Marker>
            + DataProvider<WeekdayNamesV1Marker>
            + DataProvider<DayPeriodNamesV1Marker>
            + DataProvider<tz::EssentialsV1Marker>
            + DataProvider<tz::MzGenericShortV1Marker>,
    {
        let locale = self.prefs;
        self.inner.load_for_pattern(
            &C::YearNamesV1Marker::bind(&crate::provider::Baked),
            &C::MonthNamesV1Marker::bind(&crate::provider::Baked),
            &WeekdayNamesV1Marker::bind(&crate::provider::Baked),
            &DayPeriodNamesV1Marker::bind(&crate::provider::Baked),
            &tz::EssentialsV1Marker::bind(&crate::provider::Baked),
            &tz::LocationsV1Marker::bind(&crate::provider::Baked),
            &tz::MzGenericLongV1Marker::bind(&crate::provider::Baked),
            &tz::MzGenericShortV1Marker::bind(&crate::provider::Baked),
            &tz::MzSpecificLongV1Marker::bind(&crate::provider::Baked),
            &tz::MzSpecificShortV1Marker::bind(&crate::provider::Baked),
            &tz::MzPeriodV1Marker::bind(&crate::provider::Baked),
            &ExternalLoaderCompiledData,
            locale,
            pattern.iter_items(),
        )?;
        Ok(DateTimePatternFormatter::new(
            pattern.as_borrowed(),
            self.inner.as_borrowed(),
        ))
    }

    /// Maps a [`TypedDateTimeNames`] of a specific `FSet` to a more general `FSet`.
    ///
    /// For example, this can transform a formatter for [`DateFieldSet`] to one for
    /// [`CompositeDateTimeFieldSet`].
    ///
    /// [`DateFieldSet`]: crate::fieldsets::enums::DateFieldSet
    /// [`CompositeDateTimeFieldSet`]: crate::fieldsets::enums::CompositeDateTimeFieldSet
    ///
    /// # Examples
    ///
    /// ```
    /// use icu::calendar::Gregorian;
    /// use icu::calendar::DateTime;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::datetime::fields::FieldLength;
    /// use icu::datetime::fields;
    /// use icu::datetime::fieldsets::enums::{DateFieldSet, CompositeDateTimeFieldSet};
    /// use icu::datetime::pattern::DateTimePattern;
    /// use icu::locale::locale;
    /// use writeable::assert_try_writeable_eq;
    ///
    /// // Create an instance that can format abbreviated month names:
    /// let mut names: TypedDateTimeNames<Gregorian, DateFieldSet> =
    ///     TypedDateTimeNames::try_new(locale!("uk").into()).unwrap();
    /// names
    ///     .include_month_names(fields::Month::Format, FieldLength::Three)
    ///     .unwrap();
    ///
    /// // Test it with a pattern:
    /// let pattern_str = "MMM d y";
    /// let pattern: DateTimePattern = pattern_str.parse().unwrap();
    /// let datetime = DateTime::try_new_gregorian(2023, 11, 20, 12, 35, 3).unwrap();
    /// assert_try_writeable_eq!(names.with_pattern_unchecked(&pattern).format(&datetime), "лист. 20 2023");
    ///
    /// // Convert the field set to `CompositeDateTimeFieldSet`:
    /// let composite_names = names.with_fset::<CompositeDateTimeFieldSet>();
    ///
    /// // It should still work:
    /// assert_try_writeable_eq!(composite_names.with_pattern_unchecked(&pattern).format(&datetime), "лист. 20 2023");
    /// ```
    ///
    /// Converting into a narrower type is not supported:
    ///
    /// ```compile_fail,E0277
    /// use icu::calendar::Gregorian;
    /// use icu::datetime::pattern::TypedDateTimeNames;
    /// use icu::datetime::fieldsets::enums::{DateFieldSet, CompositeDateTimeFieldSet};
    ///
    /// let composite_names: TypedDateTimeNames<Gregorian, CompositeDateTimeFieldSet> = todo!();
    ///
    /// // error[E0277]: the trait bound `(): From<DataPayloadWithVariables<DayPeriodNamesV1Marker, FieldLength>>` is not satisfied
    /// let narrow_names = composite_names.with_fset::<DateFieldSet>();
    /// ```
    pub fn with_fset<FSet2: DateTimeNamesFrom<FSet>>(self) -> TypedDateTimeNames<C, FSet2> {
        TypedDateTimeNames {
            prefs: self.prefs,
            inner: self.inner.with_fset(),
            _calendar: PhantomData,
        }
    }
}

impl<FSet: DateTimeNamesMarker> RawDateTimeNames<FSet> {
    pub(crate) fn new_without_number_formatting() -> Self {
        Self {
            year_names: <FSet::YearNames as NamesContainer<
                YearNamesV1Marker,
                FieldLength,
            >>::Container::new_empty(),
            month_names: <FSet::MonthNames as NamesContainer<
                MonthNamesV1Marker,
                (fields::Month, FieldLength),
            >>::Container::new_empty(),
            weekday_names: <FSet::WeekdayNames as NamesContainer<
                WeekdayNamesV1Marker,
                (fields::Weekday, FieldLength),
            >>::Container::new_empty(),
            dayperiod_names: <FSet::DayPeriodNames as NamesContainer<
                DayPeriodNamesV1Marker,
                FieldLength,
            >>::Container::new_empty(),
            zone_essentials: <FSet::ZoneEssentials as NamesContainer<
                tz::EssentialsV1Marker,
                (),
            >>::Container::new_empty(),
            locations_root: <FSet::ZoneLocations as NamesContainer<
                tz::LocationsV1Marker,
                (),
            >>::Container::new_empty(),
            locations: <FSet::ZoneLocations as NamesContainer<
                tz::LocationsV1Marker,
                (),
            >>::Container::new_empty(),
            mz_generic_long: <FSet::ZoneGenericLong as NamesContainer<
                tz::MzGenericLongV1Marker,
                (),
            >>::Container::new_empty(),
            mz_generic_short: <FSet::ZoneGenericShort as NamesContainer<
                tz::MzGenericShortV1Marker,
                (),
            >>::Container::new_empty(),
            mz_specific_long: <FSet::ZoneSpecificLong as NamesContainer<
                tz::MzSpecificLongV1Marker,
                (),
            >>::Container::new_empty(),
            mz_specific_short: <FSet::ZoneSpecificShort as NamesContainer<
                tz::MzSpecificShortV1Marker,
                (),
            >>::Container::new_empty(),
            mz_periods: <FSet::MetazoneLookup as NamesContainer<
                tz::MzPeriodV1Marker,
                (),
            >>::Container::new_empty(),
            fixed_decimal_formatter: None,
            _marker: PhantomData,
        }
    }

    pub(crate) fn as_borrowed(&self) -> RawDateTimeNamesBorrowed {
        RawDateTimeNamesBorrowed {
            year_names: self.year_names.get().inner,
            month_names: self.month_names.get().inner,
            weekday_names: self.weekday_names.get().inner,
            dayperiod_names: self.dayperiod_names.get().inner,
            zone_essentials: self.zone_essentials.get().inner,
            locations_root: self.locations_root.get().inner,
            locations: self.locations.get().inner,
            mz_generic_long: self.mz_generic_long.get().inner,
            mz_generic_short: self.mz_generic_short.get().inner,
            mz_specific_long: self.mz_specific_long.get().inner,
            mz_specific_short: self.mz_specific_short.get().inner,
            mz_periods: self.mz_periods.get().inner,
            fixed_decimal_formatter: self.fixed_decimal_formatter.as_ref(),
        }
    }

    pub(crate) fn load_year_names<P>(
        &mut self,
        provider: &P,
        prefs: DateTimeFormatterPreferences,
        field_length: FieldLength,
    ) -> Result<(), PatternLoadError>
    where
        P: BoundDataProvider<YearNamesV1Marker> + ?Sized,
    {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::Era,
            length: field_length,
        };
        // UTS 35 says that "G..GGG" are all Abbreviated
        let field_length = field_length.numeric_to_abbr();
        let variables = field_length;
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
                marker_attrs::name_attr_for(
                    marker_attrs::Context::Format,
                    match field_length {
                        FieldLength::Three => marker_attrs::Length::Abbr,
                        FieldLength::Five => marker_attrs::Length::Narrow,
                        FieldLength::Four => marker_attrs::Length::Wide,
                        _ => return Err(PatternLoadError::UnsupportedLength(field)),
                    },
                ),
                &locale,
            ),
            ..Default::default()
        };
        self.year_names
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        Ok(())
    }

    pub(crate) fn load_month_names<P>(
        &mut self,
        provider: &P,
        prefs: DateTimeFormatterPreferences,
        field_symbol: fields::Month,
        field_length: FieldLength,
    ) -> Result<(), PatternLoadError>
    where
        P: BoundDataProvider<MonthNamesV1Marker> + ?Sized,
    {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::Month(field_symbol),
            length: field_length,
        };
        let variables = (field_symbol, field_length);
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
                marker_attrs::name_attr_for(
                    match field_symbol {
                        fields::Month::Format => marker_attrs::Context::Format,
                        fields::Month::StandAlone => marker_attrs::Context::Standalone,
                    },
                    match field_length {
                        FieldLength::Three => marker_attrs::Length::Abbr,
                        FieldLength::Five => marker_attrs::Length::Narrow,
                        FieldLength::Four => marker_attrs::Length::Wide,
                        _ => return Err(PatternLoadError::UnsupportedLength(field)),
                    },
                ),
                &locale,
            ),
            ..Default::default()
        };
        self.month_names
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        Ok(())
    }

    pub(crate) fn load_day_period_names<P>(
        &mut self,
        provider: &P,
        prefs: DateTimeFormatterPreferences,
        field_length: FieldLength,
    ) -> Result<(), PatternLoadError>
    where
        P: BoundDataProvider<DayPeriodNamesV1Marker> + ?Sized,
    {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            // Names for 'a' and 'b' are stored in the same data marker
            symbol: FieldSymbol::DayPeriod(fields::DayPeriod::NoonMidnight),
            length: field_length,
        };
        // UTS 35 says that "a..aaa" are all Abbreviated
        let field_length = field_length.numeric_to_abbr();
        let variables = field_length;
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
                marker_attrs::name_attr_for(
                    marker_attrs::Context::Format,
                    match field_length {
                        FieldLength::Three => marker_attrs::Length::Abbr,
                        FieldLength::Five => marker_attrs::Length::Narrow,
                        FieldLength::Four => marker_attrs::Length::Wide,
                        _ => return Err(PatternLoadError::UnsupportedLength(field)),
                    },
                ),
                &locale,
            ),
            ..Default::default()
        };
        self.dayperiod_names
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        Ok(())
    }

    pub(crate) fn load_weekday_names<P>(
        &mut self,
        provider: &P,
        prefs: DateTimeFormatterPreferences,
        field_symbol: fields::Weekday,
        field_length: FieldLength,
    ) -> Result<(), PatternLoadError>
    where
        P: BoundDataProvider<WeekdayNamesV1Marker> + ?Sized,
    {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::Weekday(field_symbol),
            length: field_length,
        };
        // UTS 35 says that "E..EEE" are all Abbreviated
        // However, this doesn't apply to "e" and "c".
        let field_length = if matches!(field_symbol, fields::Weekday::Format) {
            field_length.numeric_to_abbr()
        } else {
            field_length
        };
        let variables = (field_symbol, field_length);
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_marker_attributes_and_locale(
                marker_attrs::name_attr_for(
                    match field_symbol {
                        // UTS 35 says that "e" and "E" have the same non-numeric names
                        fields::Weekday::Format | fields::Weekday::Local => {
                            marker_attrs::Context::Format
                        }
                        fields::Weekday::StandAlone => marker_attrs::Context::Standalone,
                    },
                    match field_length {
                        FieldLength::Three => marker_attrs::Length::Abbr,
                        FieldLength::Five => marker_attrs::Length::Narrow,
                        FieldLength::Four => marker_attrs::Length::Wide,
                        FieldLength::Six => marker_attrs::Length::Short,
                        _ => return Err(PatternLoadError::UnsupportedLength(field)),
                    },
                ),
                &locale,
            ),
            ..Default::default()
        };
        self.weekday_names
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        Ok(())
    }

    pub(crate) fn load_time_zone_essentials<P>(
        &mut self,
        provider: &P,
        prefs: DateTimeFormatterPreferences,
    ) -> Result<(), PatternLoadError>
    where
        P: BoundDataProvider<tz::EssentialsV1Marker> + ?Sized,
    {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::TimeZone(fields::TimeZone::LocalizedOffset),
            length: FieldLength::Four,
        };
        let variables = ();
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_locale(&locale),
            ..Default::default()
        };
        self.zone_essentials
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        Ok(())
    }

    pub(crate) fn load_time_zone_location_names<P>(
        &mut self,
        provider: &P,
        prefs: DateTimeFormatterPreferences,
    ) -> Result<(), PatternLoadError>
    where
        P: BoundDataProvider<tz::LocationsV1Marker> + ?Sized,
    {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::TimeZone(fields::TimeZone::Location),
            length: FieldLength::Four,
        };
        let variables = ();
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_locale(&locale),
            ..Default::default()
        };
        self.locations_root
            .load_put(provider, Default::default(), variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        self.locations
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        Ok(())
    }

    fn load_mz_periods<P>(
        &mut self,
        provider: &P,
        field: fields::Field,
    ) -> Result<(), PatternLoadError>
    where
        P: BoundDataProvider<tz::MzPeriodV1Marker> + ?Sized,
    {
        let variables = ();
        self.mz_periods
            .load_put(provider, Default::default(), variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        Ok(())
    }

    pub(crate) fn load_time_zone_generic_long_names(
        &mut self,
        provider: &(impl BoundDataProvider<tz::MzGenericLongV1Marker> + ?Sized),
        mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1Marker> + ?Sized),
        prefs: DateTimeFormatterPreferences,
    ) -> Result<(), PatternLoadError> {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::TimeZone(fields::TimeZone::GenericNonLocation),
            length: FieldLength::Four,
        };
        let variables = ();
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_locale(&locale),
            ..Default::default()
        };
        self.mz_generic_long
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        self.load_mz_periods(mz_period_provider, field)?;
        Ok(())
    }

    pub(crate) fn load_time_zone_generic_short_names(
        &mut self,
        provider: &(impl BoundDataProvider<tz::MzGenericShortV1Marker> + ?Sized),
        mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1Marker> + ?Sized),
        prefs: DateTimeFormatterPreferences,
    ) -> Result<(), PatternLoadError> {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::TimeZone(fields::TimeZone::GenericNonLocation),
            length: FieldLength::One,
        };
        let variables = ();
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_locale(&locale),
            ..Default::default()
        };
        self.mz_generic_short
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        self.load_mz_periods(mz_period_provider, field)?;
        Ok(())
    }

    pub(crate) fn load_time_zone_specific_long_names(
        &mut self,
        provider: &(impl BoundDataProvider<tz::MzSpecificLongV1Marker> + ?Sized),
        mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1Marker> + ?Sized),
        prefs: DateTimeFormatterPreferences,
    ) -> Result<(), PatternLoadError> {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::TimeZone(fields::TimeZone::SpecificNonLocation),
            length: FieldLength::Four,
        };
        let variables = ();
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_locale(&locale),
            ..Default::default()
        };
        self.mz_specific_long
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        self.load_mz_periods(mz_period_provider, field)?;
        Ok(())
    }

    pub(crate) fn load_time_zone_specific_short_names(
        &mut self,
        provider: &(impl BoundDataProvider<tz::MzSpecificShortV1Marker> + ?Sized),
        mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1Marker> + ?Sized),
        prefs: DateTimeFormatterPreferences,
    ) -> Result<(), PatternLoadError> {
        let locale = provider.bound_marker().make_locale(prefs.locale_prefs);
        let field = fields::Field {
            symbol: FieldSymbol::TimeZone(fields::TimeZone::SpecificNonLocation),
            length: FieldLength::One,
        };
        let variables = ();
        let req = DataRequest {
            id: DataIdentifierBorrowed::for_locale(&locale),
            ..Default::default()
        };
        self.mz_specific_short
            .load_put(provider, req, variables)
            .map_err(|e| MaybePayloadError::into_load_error(e, field))?
            .map_err(|e| PatternLoadError::Data(e, field))?;
        self.load_mz_periods(mz_period_provider, field)?;
        Ok(())
    }

    pub(crate) fn load_fixed_decimal_formatter(
        &mut self,
        loader: &impl FixedDecimalFormatterLoader,
        prefs: DateTimeFormatterPreferences,
    ) -> Result<(), DataError> {
        if self.fixed_decimal_formatter.is_some() {
            return Ok(());
        }
        let mut options = FixedDecimalFormatterOptions::default();
        options.grouping_strategy = GroupingStrategy::Never;
        self.fixed_decimal_formatter = Some(FixedDecimalFormatterLoader::load(
            loader,
            (&prefs).into(),
            options,
        )?);
        Ok(())
    }

    /// Loads all data required for formatting the given [`PatternItem`]s.
    ///
    /// This function has a lot of arguments because many of the arguments are generic,
    /// and pulling them out to an options struct would be cumbersome.
    #[allow(clippy::too_many_arguments)]
    pub(crate) fn load_for_pattern(
        &mut self,
        year_provider: &(impl BoundDataProvider<YearNamesV1Marker> + ?Sized),
        month_provider: &(impl BoundDataProvider<MonthNamesV1Marker> + ?Sized),
        weekday_provider: &(impl BoundDataProvider<WeekdayNamesV1Marker> + ?Sized),
        dayperiod_provider: &(impl BoundDataProvider<DayPeriodNamesV1Marker> + ?Sized),
        zone_essentials_provider: &(impl BoundDataProvider<tz::EssentialsV1Marker> + ?Sized),
        locations_provider: &(impl BoundDataProvider<tz::LocationsV1Marker> + ?Sized),
        mz_generic_long_provider: &(impl BoundDataProvider<tz::MzGenericLongV1Marker> + ?Sized),
        mz_generic_short_provider: &(impl BoundDataProvider<tz::MzGenericShortV1Marker> + ?Sized),
        mz_specific_long_provider: &(impl BoundDataProvider<tz::MzSpecificLongV1Marker> + ?Sized),
        mz_specific_short_provider: &(impl BoundDataProvider<tz::MzSpecificShortV1Marker> + ?Sized),
        mz_period_provider: &(impl BoundDataProvider<tz::MzPeriodV1Marker> + ?Sized),
        fixed_decimal_formatter_loader: &impl FixedDecimalFormatterLoader,
        prefs: DateTimeFormatterPreferences,
        pattern_items: impl Iterator<Item = PatternItem>,
    ) -> Result<(), PatternLoadError> {
        let mut numeric_field = None;

        for item in pattern_items {
            let PatternItem::Field(field) = item else {
                continue;
            };

            use fields::*;
            use FieldLength::*;
            use FieldSymbol as FS;

            match (field.symbol, field.length) {
                ///// Textual symbols /////

                // G..GGGGG
                (FS::Era, One | Two | Three | Four | Five) => {
                    self.load_year_names(year_provider, prefs, field.length)?;
                }

                // U..UUUUU
                (FS::Year(Year::Cyclic), One | Two | Three | Four | Five) => {
                    numeric_field = Some(field);
                    self.load_year_names(year_provider, prefs, field.length)?;
                }

                // MMM..MMMMM
                (FS::Month(Month::Format), Three | Four | Five) => {
                    self.load_month_names(month_provider, prefs, Month::Format, field.length)?;
                }

                // LLL..LLLLL
                (FS::Month(Month::StandAlone), Three | Four | Five) => {
                    self.load_month_names(month_provider, prefs, Month::StandAlone, field.length)?;
                }

                // E..EE
                (FS::Weekday(Weekday::Format), One | Two) => {
                    self.load_weekday_names(
                        weekday_provider,
                        prefs,
                        Weekday::Format,
                        field.length,
                    )?;
                }
                // EEE..EEEEEE, eee..eeeeee, ccc..cccccc
                (FS::Weekday(symbol), Three | Four | Five | Six) => {
                    self.load_weekday_names(weekday_provider, prefs, symbol, field.length)?;
                }

                // a..aaaaa, b..bbbbb
                (FS::DayPeriod(_), One | Two | Three | Four | Five) => {
                    self.load_day_period_names(dayperiod_provider, prefs, field.length)?;
                }

                ///// Time zone symbols /////

                // z..zzz
                (FS::TimeZone(TimeZone::SpecificNonLocation), One | Two | Three) => {
                    numeric_field = Some(field);
                    self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
                    self.load_time_zone_specific_short_names(
                        mz_specific_short_provider,
                        mz_period_provider,
                        prefs,
                    )?;
                }
                // zzzz
                (FS::TimeZone(TimeZone::SpecificNonLocation), Four) => {
                    numeric_field = Some(field);
                    self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
                    self.load_time_zone_specific_long_names(
                        mz_specific_long_provider,
                        mz_period_provider,
                        prefs,
                    )?;
                    self.load_time_zone_location_names(locations_provider, prefs)?;
                }

                // v
                (FS::TimeZone(TimeZone::GenericNonLocation), One) => {
                    numeric_field = Some(field);
                    self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
                    self.load_time_zone_generic_short_names(
                        mz_generic_short_provider,
                        mz_period_provider,
                        prefs,
                    )?;
                    // For fallback:
                    self.load_time_zone_location_names(locations_provider, prefs)?;
                }
                // vvvv
                (FS::TimeZone(TimeZone::GenericNonLocation), Four) => {
                    numeric_field = Some(field);
                    self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
                    self.load_time_zone_generic_long_names(
                        mz_generic_long_provider,
                        mz_period_provider,
                        prefs,
                    )?;
                    // For fallback:
                    self.load_time_zone_location_names(locations_provider, prefs)?;
                }

                // V
                (FS::TimeZone(TimeZone::Location), One) => {
                    // no data required
                }
                // VVVV
                (FS::TimeZone(TimeZone::Location), Four) => {
                    numeric_field = Some(field);
                    self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
                    self.load_time_zone_location_names(locations_provider, prefs)?;
                }

                // O, OOOO
                (FS::TimeZone(TimeZone::LocalizedOffset), One | Four) => {
                    self.load_time_zone_essentials(zone_essentials_provider, prefs)?;
                    numeric_field = Some(field);
                }

                // X..XXXXX, x..xxxxx
                (
                    FS::TimeZone(TimeZone::IsoWithZ | TimeZone::Iso),
                    One | Two | Three | Four | Five,
                ) => {
                    // no data required
                }

                ///// Numeric symbols /////

                // y+
                (FS::Year(Year::Calendar), _) => numeric_field = Some(field),
                // r+
                (FS::Year(Year::RelatedIso), _) => {
                    // always formats as ASCII
                }

                // M..MM, L..LL
                (FS::Month(_), One | Two) => numeric_field = Some(field),

                // e..ee, c..cc
                (FS::Weekday(Weekday::Local | Weekday::StandAlone), One | Two) => {
                    // TODO(#5643): Requires locale-aware day-of-week calculation
                    return Err(PatternLoadError::UnsupportedLength(field));
                }

                // d..dd
                (FS::Day(Day::DayOfMonth), One | Two) => numeric_field = Some(field),
                // D..DDD
                (FS::Day(Day::DayOfYear), One | Two | Three) => numeric_field = Some(field),
                // F
                (FS::Day(Day::DayOfWeekInMonth), One) => numeric_field = Some(field),

                // K..KK, h..hh, H..HH, k..kk
                (FS::Hour(_), One | Two) => numeric_field = Some(field),

                // m..mm
                (FS::Minute, One | Two) => numeric_field = Some(field),

                // s..ss
                (FS::Second(Second::Second), One | Two) => numeric_field = Some(field),

                // A+
                (FS::Second(Second::MillisInDay), _) => numeric_field = Some(field),

                // s.S+, ss.S+ (s is modelled by length, S+ by symbol)
                (FS::DecimalSecond(_), One | Two) => numeric_field = Some(field),

                ///// Unsupported symbols /////
                _ => {
                    return Err(PatternLoadError::UnsupportedLength(field));
                }
            }
        }

        if let Some(field) = numeric_field {
            self.load_fixed_decimal_formatter(fixed_decimal_formatter_loader, prefs)
                .map_err(|e| PatternLoadError::Data(e, field))?;
        }

        Ok(())
    }
}

impl<'data> RawDateTimeNamesBorrowed<'data> {
    pub(crate) fn get_name_for_month(
        &self,
        field_symbol: fields::Month,
        field_length: FieldLength,
        code: MonthCode,
    ) -> Result<MonthPlaceholderValue, GetNameForMonthError> {
        let month_names = self
            .month_names
            .get_with_variables((field_symbol, field_length))
            .ok_or(GetNameForMonthError::NotLoaded)?;
        let Some((month_number, is_leap)) = code.parsed() else {
            return Err(GetNameForMonthError::Invalid);
        };
        let Some(month_index) = month_number.checked_sub(1) else {
            return Err(GetNameForMonthError::Invalid);
        };
        let month_index = usize::from(month_index);
        let name = match month_names {
            MonthNamesV1::Linear(linear) => {
                if is_leap {
                    None
                } else {
                    linear.get(month_index)
                }
            }
            MonthNamesV1::LeapLinear(leap_linear) => {
                let num_months = leap_linear.len() / 2;
                if is_leap {
                    leap_linear.get(month_index + num_months)
                } else if month_index < num_months {
                    leap_linear.get(month_index)
                } else {
                    None
                }
            }
            MonthNamesV1::LeapNumeric(leap_numeric) => {
                if is_leap {
                    return Ok(MonthPlaceholderValue::NumericPattern(leap_numeric));
                } else {
                    return Ok(MonthPlaceholderValue::Numeric);
                }
            }
        };
        // Note: Always return `false` for the second argument since neo MonthNames
        // knows how to handle leap months and we don't need the fallback logic
        name.map(MonthPlaceholderValue::PlainString)
            .ok_or(GetNameForMonthError::Invalid)
    }

    pub(crate) fn get_name_for_weekday(
        &self,
        field_symbol: fields::Weekday,
        field_length: FieldLength,
        day: input::IsoWeekday,
    ) -> Result<&str, GetNameForWeekdayError> {
        // UTS 35 says that "e" and "E" have the same non-numeric names
        let field_symbol = field_symbol.to_format_symbol();
        // UTS 35 says that "E..EEE" are all Abbreviated
        // However, this doesn't apply to "e" and "c".
        let field_length = if matches!(field_symbol, fields::Weekday::Format) {
            field_length.numeric_to_abbr()
        } else {
            field_length
        };
        let weekday_names = self
            .weekday_names
            .get_with_variables((field_symbol, field_length))
            .ok_or(GetNameForWeekdayError::NotLoaded)?;
        weekday_names
            .names
            .get((day as usize) % 7)
            // TODO: make weekday_names length 7 in the type system
            .ok_or(GetNameForWeekdayError::NotLoaded)
    }

    /// Gets the era symbol, or `None` if data is loaded but symbol isn't found.
    ///
    /// `None` should fall back to the era code directly, if, for example,
    /// a japanext datetime is formatted with a `DateTimeFormat<Japanese>`
    pub(crate) fn get_name_for_era(
        &self,
        field_length: FieldLength,
        era: FormattingEra,
    ) -> Result<&str, GetSymbolForEraError> {
        // UTS 35 says that "G..GGG" are all Abbreviated
        let field_length = field_length.numeric_to_abbr();
        let year_names = self
            .year_names
            .get_with_variables(field_length)
            .ok_or(GetSymbolForEraError::NotLoaded)?;

        match (year_names, era) {
            (YearNamesV1::VariableEras(era_names), FormattingEra::Code(era_code)) => era_names
                .get(era_code.0.as_str().into())
                .ok_or(GetSymbolForEraError::Invalid),
            (YearNamesV1::FixedEras(era_names), FormattingEra::Index(index, _fallback)) => {
                era_names
                    .get(index.into())
                    .ok_or(GetSymbolForEraError::Invalid)
            }
            _ => Err(GetSymbolForEraError::Invalid),
        }
    }

    pub(crate) fn get_name_for_cyclic(
        &self,
        field_length: FieldLength,
        cyclic: NonZeroU8,
    ) -> Result<&str, GetSymbolForCyclicYearError> {
        // UTS 35 says that "U..UUU" are all Abbreviated
        let field_length = field_length.numeric_to_abbr();
        let year_names = self
            .year_names
            .get_with_variables(field_length)
            .ok_or(GetSymbolForCyclicYearError::NotLoaded)?;

        let YearNamesV1::Cyclic(cyclics) = year_names else {
            return Err(GetSymbolForCyclicYearError::Invalid { max: 0 });
        };

        cyclics
            .get((cyclic.get() as usize) - 1)
            .ok_or(GetSymbolForCyclicYearError::Invalid {
                max: cyclics.len() + 1,
            })
    }

    pub(crate) fn get_name_for_day_period(
        &self,
        field_symbol: fields::DayPeriod,
        field_length: FieldLength,
        hour: input::IsoHour,
        is_top_of_hour: bool,
    ) -> Result<&str, GetNameForDayPeriodError> {
        use fields::DayPeriod::NoonMidnight;
        // UTS 35 says that "a..aaa" are all Abbreviated
        let field_length = field_length.numeric_to_abbr();
        let dayperiod_names = self
            .dayperiod_names
            .get_with_variables(field_length)
            .ok_or(GetNameForDayPeriodError::NotLoaded)?;
        let option_value: Option<&str> = match (field_symbol, u8::from(hour), is_top_of_hour) {
            (NoonMidnight, 00, true) => dayperiod_names.midnight().or_else(|| dayperiod_names.am()),
            (NoonMidnight, 12, true) => dayperiod_names.noon().or_else(|| dayperiod_names.pm()),
            (_, hour, _) if hour < 12 => dayperiod_names.am(),
            _ => dayperiod_names.pm(),
        };
        option_value.ok_or(GetNameForDayPeriodError::NotLoaded)
    }
}

/// A container contains all data payloads for time zone formatting (borrowed version).
#[derive(Debug, Copy, Clone, Default)]
pub(crate) struct TimeZoneDataPayloadsBorrowed<'a> {
    /// The data that contains meta information about how to display content.
    pub(crate) essentials: Option<&'a tz::EssentialsV1<'a>>,
    /// The root location names, e.g. Toronto
    pub(crate) locations_root: Option<&'a tz::LocationsV1<'a>>,
    /// The language specific location names, e.g. Italy
    pub(crate) locations: Option<&'a tz::LocationsV1<'a>>,
    /// The generic long metazone names, e.g. Pacific Time
    pub(crate) mz_generic_long: Option<&'a tz::MzGenericV1<'a>>,
    /// The generic short metazone names, e.g. PT
    pub(crate) mz_generic_short: Option<&'a tz::MzGenericV1<'a>>,
    /// The specific long metazone names, e.g. Pacific Daylight Time
    pub(crate) mz_specific_long: Option<&'a tz::MzSpecificV1<'a>>,
    /// The specific short metazone names, e.g. Pacific Daylight Time
    pub(crate) mz_specific_short: Option<&'a tz::MzSpecificV1<'a>>,
    /// The metazone lookup
    pub(crate) mz_periods: Option<&'a tz::MzPeriodV1<'a>>,
}

impl<'data> RawDateTimeNamesBorrowed<'data> {
    pub(crate) fn get_payloads(&self) -> TimeZoneDataPayloadsBorrowed<'data> {
        TimeZoneDataPayloadsBorrowed {
            essentials: self.zone_essentials.get_option(),
            locations_root: self.locations_root.get_option(),
            locations: self.locations.get_option(),
            mz_generic_long: self.mz_generic_long.get_option(),
            mz_generic_short: self.mz_generic_short.get_option(),
            mz_specific_long: self.mz_specific_long.get_option(),
            mz_specific_short: self.mz_specific_short.get_option(),
            mz_periods: self.mz_periods.get_option(),
        }
    }
}