@@ -180,6 +180,10 @@ macro_rules! impl_time_precision_constructors {
180
180
pub fn hms( ) -> Self {
181
181
Self :: for_length( Default :: default ( ) ) . with_time_precision( TimePrecision :: Second )
182
182
}
183
+ #[ doc = concat!( "Creates a " , stringify!( $type) , " that formats hours, minutes, seconds, and subseconds with the default length." ) ]
184
+ pub fn hmss( subsecond_digits: SubsecondDigits ) -> Self {
185
+ Self :: for_length( Default :: default ( ) ) . with_time_precision( TimePrecision :: Subsecond ( subsecond_digits) )
186
+ }
183
187
}
184
188
} ;
185
189
}
@@ -303,6 +307,17 @@ macro_rules! impl_date_to_time_helpers {
303
307
}
304
308
}
305
309
/// Shorthand to associate this field set with [`TimePrecision::Minute`].
310
+ ///
311
+ /// # Examples
312
+ ///
313
+ /// ```
314
+ #[ doc = concat!( "use icu::datetime::fieldsets::" , stringify!( $type) , ";" ) ]
315
+ /// use icu::datetime::options::TimePrecision;
316
+ ///
317
+ #[ doc = concat!( "let fs1 = " , stringify!( $type) , "::medium().with_time(TimePrecision::Minute);" ) ]
318
+ #[ doc = concat!( "let fs2 = " , stringify!( $type) , "::medium().with_time_hm();" ) ]
319
+ /// assert_eq!(fs1, fs2);
320
+ /// ```
306
321
pub fn with_time_hm( self ) -> $type_time {
307
322
$type_time {
308
323
length: self . length,
@@ -312,6 +327,17 @@ macro_rules! impl_date_to_time_helpers {
312
327
}
313
328
}
314
329
/// Shorthand to associate this field set with [`TimePrecision::Second`].
330
+ ///
331
+ /// # Examples
332
+ ///
333
+ /// ```
334
+ #[ doc = concat!( "use icu::datetime::fieldsets::" , stringify!( $type) , ";" ) ]
335
+ /// use icu::datetime::options::TimePrecision;
336
+ ///
337
+ #[ doc = concat!( "let fs1 = " , stringify!( $type) , "::medium().with_time(TimePrecision::Second);" ) ]
338
+ #[ doc = concat!( "let fs2 = " , stringify!( $type) , "::medium().with_time_hms();" ) ]
339
+ /// assert_eq!(fs1, fs2);
340
+ /// ```
315
341
pub fn with_time_hms( self ) -> $type_time {
316
342
$type_time {
317
343
length: self . length,
@@ -320,6 +346,27 @@ macro_rules! impl_date_to_time_helpers {
320
346
$( year_style: yes_to!( self . year_style, $yearstyle_yes) , ) ?
321
347
}
322
348
}
349
+ /// Shorthand to associate this field set with [`TimePrecision::Subsecond`].
350
+ ///
351
+ /// # Examples
352
+ ///
353
+ /// ```
354
+ #[ doc = concat!( "use icu::datetime::fieldsets::" , stringify!( $type) , ";" ) ]
355
+ /// use icu::datetime::options::TimePrecision;
356
+ /// use icu::datetime::options::SubsecondDigits::S2;
357
+ ///
358
+ #[ doc = concat!( "let fs1 = " , stringify!( $type) , "::medium().with_time(TimePrecision::Subsecond(S2));" ) ]
359
+ #[ doc = concat!( "let fs2 = " , stringify!( $type) , "::medium().with_time_hmss(S2);" ) ]
360
+ /// assert_eq!(fs1, fs2);
361
+ /// ```
362
+ pub fn with_time_hmss( self , subsecond_digits: SubsecondDigits ) -> $type_time {
363
+ $type_time {
364
+ length: self . length,
365
+ time_precision: Some ( TimePrecision :: Subsecond ( subsecond_digits) ) ,
366
+ alignment: ternary!( self . alignment, Default :: default ( ) , $( $alignment_yes) ?) ,
367
+ $( year_style: yes_to!( self . year_style, $yearstyle_yes) , ) ?
368
+ }
369
+ }
323
370
}
324
371
} ;
325
372
}
@@ -1192,6 +1239,28 @@ impl_time_marker!(
1192
1239
/// );
1193
1240
/// ```
1194
1241
///
1242
+ /// Conveniently construct a time formatter with subseconds:
1243
+ ///
1244
+ /// ```
1245
+ /// use icu::datetime::input::Time;
1246
+ /// use icu::datetime::fieldsets::T;
1247
+ /// use icu::datetime::options::SubsecondDigits;
1248
+ /// use icu::datetime::NoCalendarFormatter;
1249
+ /// use icu::locale::locale;
1250
+ /// use writeable::assert_writeable_eq;
1251
+ ///
1252
+ /// let formatter = NoCalendarFormatter::try_new(
1253
+ /// locale!("en").into(),
1254
+ /// T::hmss(SubsecondDigits::S4),
1255
+ /// )
1256
+ /// .unwrap();
1257
+ ///
1258
+ /// assert_writeable_eq!(
1259
+ /// formatter.format(&Time::try_new(18, 24, 36, 987654321).unwrap()),
1260
+ /// "6:24:36.9876 PM"
1261
+ /// );
1262
+ /// ```
1263
+ ///
1195
1264
/// [`DateTimeFormatterPreferences`]: crate::DateTimeFormatterPreferences
1196
1265
T ,
1197
1266
description = "time (locale-dependent hour cycle)" ,
0 commit comments