@@ -30,6 +30,19 @@ pub mod dynamic {
30
30
pub use crate :: dynamic:: * ;
31
31
}
32
32
33
+ /// 🚧 \[Experimental\] Types for dealing with serialization of semantic skeletons.
34
+ ///
35
+ /// <div class="stab unstable">
36
+ /// 🚧 This code is experimental; it may change at any time, in breaking or non-breaking ways,
37
+ /// including in SemVer minor releases. Use with caution.
38
+ /// <a href="https://github.com/unicode-org/icu4x/issues/5825">#5825</a>
39
+ /// </div>
40
+ #[ cfg( all( feature = "experimental" , feature = "serde" ) ) ]
41
+ pub mod serde {
42
+ pub use crate :: neo_serde:: CompositeFieldSetSerde ;
43
+ pub use crate :: neo_serde:: CompositeFieldSetSerdeError ;
44
+ }
45
+
33
46
#[ cfg( doc) ]
34
47
use icu_timezone:: TimeZoneInfo ;
35
48
@@ -1147,6 +1160,88 @@ impl_calendar_period_marker!(
1147
1160
) ;
1148
1161
1149
1162
impl_time_marker ! (
1163
+ /// Hours can be switched between 12-hour and 24-hour time via the `u-hc` locale keyword.
1164
+ ///
1165
+ /// ```
1166
+ /// use icu::calendar::Time;
1167
+ /// use icu::datetime::fieldset::T;
1168
+ /// use icu::datetime::FixedCalendarDateTimeFormatter;
1169
+ /// use icu::locale::locale;
1170
+ /// use writeable::assert_try_writeable_eq;
1171
+ ///
1172
+ /// // By default, en-US uses 12-hour time and fr-FR uses 24-hour time,
1173
+ /// // but we can set overrides.
1174
+ ///
1175
+ /// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
1176
+ /// &locale!("en-US-u-hc-h12").into(),
1177
+ /// T::short().hm(),
1178
+ /// )
1179
+ /// .unwrap();
1180
+ /// assert_try_writeable_eq!(
1181
+ /// formatter.format(&Time::try_new(16, 12, 20, 0).unwrap()),
1182
+ /// "4:12 PM"
1183
+ /// );
1184
+ ///
1185
+ /// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
1186
+ /// &locale!("en-US-u-hc-h23").into(),
1187
+ /// T::short().hm(),
1188
+ /// )
1189
+ /// .unwrap();
1190
+ /// assert_try_writeable_eq!(
1191
+ /// formatter.format(&Time::try_new(16, 12, 20, 0).unwrap()),
1192
+ /// "16:12"
1193
+ /// );
1194
+ ///
1195
+ /// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
1196
+ /// &locale!("fr-FR-u-hc-h12").into(),
1197
+ /// T::short().hm(),
1198
+ /// )
1199
+ /// .unwrap();
1200
+ /// assert_try_writeable_eq!(
1201
+ /// formatter.format(&Time::try_new(16, 12, 20, 0).unwrap()),
1202
+ /// "4:12 PM"
1203
+ /// );
1204
+ ///
1205
+ /// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
1206
+ /// &locale!("fr-FR-u-hc-h23").into(),
1207
+ /// T::short().hm(),
1208
+ /// )
1209
+ /// .unwrap();
1210
+ /// assert_try_writeable_eq!(
1211
+ /// formatter.format(&Time::try_new(16, 12, 20, 0).unwrap()),
1212
+ /// "16:12"
1213
+ /// );
1214
+ /// ```
1215
+ ///
1216
+ /// Hour cycles `h11` and `h24` are supported, too:
1217
+ ///
1218
+ /// ```
1219
+ /// use icu::calendar::Time;
1220
+ /// use icu::datetime::fieldset::T;
1221
+ /// use icu::datetime::FixedCalendarDateTimeFormatter;
1222
+ /// use icu::locale::locale;
1223
+ /// use writeable::assert_try_writeable_eq;
1224
+ ///
1225
+ /// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
1226
+ /// &locale!("und-u-hc-h11").into(),
1227
+ /// T::short().hm(),
1228
+ /// )
1229
+ /// .unwrap();
1230
+ /// assert_try_writeable_eq!(
1231
+ /// formatter.format(&Time::try_new(0, 0, 0, 0).unwrap()),
1232
+ /// "0:00 AM"
1233
+ /// );
1234
+ ///
1235
+ /// let formatter = FixedCalendarDateTimeFormatter::<(), _>::try_new(
1236
+ /// &locale!("und-u-hc-h24").into(),
1237
+ /// T::short().hm(),
1238
+ /// )
1239
+ /// .unwrap();
1240
+ /// assert_try_writeable_eq!(
1241
+ /// formatter.format(&Time::try_new(0, 0, 0, 0).unwrap()),
1242
+ /// "24:00"
1243
+ /// );
1244
+ /// ```
1150
1245
T ,
1151
1246
NeoTimeComponents :: Time ,
1152
1247
description = "time (locale-dependent hour cycle)" ,
@@ -1381,6 +1476,56 @@ impl_zone_marker!(
1381
1476
/// );
1382
1477
/// ```
1383
1478
///
1479
+ /// Can also fall back to the UTC offset:
1480
+ ///
1481
+ /// ```
1482
+ /// use icu::calendar::{Date, Time};
1483
+ /// use icu::timezone::{TimeZoneInfo, UtcOffset, TimeZoneIdMapper, TimeZoneBcp47Id};
1484
+ /// use icu::datetime::FixedCalendarDateTimeFormatter;
1485
+ /// use icu::datetime::fieldset::V;
1486
+ /// use icu::datetime::DateTimeWriteError;
1487
+ /// use icu::locale::locale;
1488
+ /// use tinystr::tinystr;
1489
+ /// use writeable::assert_try_writeable_eq;
1490
+ ///
1491
+ /// // Set up the formatter
1492
+ /// let mut tzf = FixedCalendarDateTimeFormatter::<(), _>::try_new(
1493
+ /// &locale!("en").into(),
1494
+ /// V::short(),
1495
+ /// )
1496
+ /// .unwrap();
1497
+ ///
1498
+ /// // "uschi" - has symbol data for short generic non-location
1499
+ /// let time_zone = TimeZoneIdMapper::new()
1500
+ /// .iana_to_bcp47("America/Chicago")
1501
+ /// .with_offset("-05".parse().ok())
1502
+ /// .at_time((Date::try_new_iso(2022, 8, 29).unwrap(), Time::midnight()));
1503
+ /// assert_try_writeable_eq!(
1504
+ /// tzf.format(&time_zone),
1505
+ /// "CT"
1506
+ /// );
1507
+ ///
1508
+ /// // "ushnl" - has time zone override symbol data for short generic non-location
1509
+ /// let time_zone = TimeZoneIdMapper::new()
1510
+ /// .iana_to_bcp47("Pacific/Honolulu")
1511
+ /// .with_offset("-10".parse().ok())
1512
+ /// .at_time((Date::try_new_iso(2022, 8, 29).unwrap(), Time::midnight()));
1513
+ /// assert_try_writeable_eq!(
1514
+ /// tzf.format(&time_zone),
1515
+ /// "HST"
1516
+ /// );
1517
+ ///
1518
+ /// // Mis-spelling of "America/Chicago" results in a fallback to offset format
1519
+ /// let time_zone = TimeZoneIdMapper::new()
1520
+ /// .iana_to_bcp47("America/Chigagou")
1521
+ /// .with_offset("-05".parse().ok())
1522
+ /// .at_time((Date::try_new_iso(2022, 8, 29).unwrap(), Time::midnight()));
1523
+ /// assert_try_writeable_eq!(
1524
+ /// tzf.format(&time_zone),
1525
+ /// "GMT-5"
1526
+ /// );
1527
+ /// ```
1528
+ ///
1384
1529
/// Since non-location names might change over time,
1385
1530
/// this time zone style requires a reference time.
1386
1531
///
0 commit comments