Skip to content

Commit

Permalink
Format docs in datetime crate
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Oct 19, 2024
1 parent c094eef commit 6c8e3e3
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 106 deletions.
23 changes: 15 additions & 8 deletions components/datetime/src/combo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ use icu_provider::marker::NeverMarker;
/// Format the weekday, hour, and location-based zone:
///
/// ```
/// use icu::timezone::CustomZonedDateTime;
/// use icu::datetime::DateTimeFormatter;
/// use icu::datetime::fieldset::{Combo, E, HM, L};
/// use icu::datetime::DateTimeFormatter;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use writeable::assert_try_writeable_eq;
///
/// let formatter = DateTimeFormatter::try_new(
/// &locale!("en-US").into(),
/// Combo::<E, HM, L>::short()
/// Combo::<E, HM, L>::short(),
/// )
/// .unwrap();
///
/// let zdt = CustomZonedDateTime::try_location_only_from_str("2024-10-18T15:44[America/Los_Angeles]").unwrap();
/// let zdt = CustomZonedDateTime::try_location_only_from_str(
/// "2024-10-18T15:44[America/Los_Angeles]",
/// )
/// .unwrap();
///
/// assert_try_writeable_eq!(
/// formatter.convert_and_format(&zdt),
Expand All @@ -40,19 +43,23 @@ use icu_provider::marker::NeverMarker;
///
/// ```
/// use icu::calendar::Gregorian;
/// use icu::timezone::CustomZonedDateTime;
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::datetime::fieldset::{Combo, E, HM, L};
/// use icu::datetime::FixedCalendarDateTimeFormatter;
/// use icu::locale::locale;
/// use icu::timezone::CustomZonedDateTime;
/// use writeable::assert_try_writeable_eq;
///
/// let formatter = FixedCalendarDateTimeFormatter::try_new(
/// &locale!("en-US").into(),
/// Combo::<E, HM, L>::short()
/// Combo::<E, HM, L>::short(),
/// )
/// .unwrap();
///
/// let zdt = CustomZonedDateTime::try_location_only_iso_from_str("2024-10-18T15:44[America/Los_Angeles]").unwrap().to_calendar(Gregorian);
/// let zdt = CustomZonedDateTime::try_location_only_iso_from_str(
/// "2024-10-18T15:44[America/Los_Angeles]",
/// )
/// .unwrap()
/// .to_calendar(Gregorian);
///
/// assert_try_writeable_eq!(
/// formatter.format(&zdt),
Expand Down
5 changes: 3 additions & 2 deletions components/datetime/src/format/neo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1427,14 +1427,15 @@ impl<C: CldrCalendar, R: DateTimeNamesMarker> TypedDateTimeNames<C, R> {
/// ```
/// use icu::calendar::Time;
/// use icu::datetime::neo_pattern::DateTimePattern;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::datetime::neo_skeleton::NeoTimeSkeleton;
/// use icu::datetime::TypedDateTimeNames;
/// use icu::locale::locale;
/// use writeable::assert_try_writeable_eq;
///
/// let locale = &locale!("bn").into();
///
/// let mut names = TypedDateTimeNames::<(), NeoTimeSkeleton>::try_new(&locale).unwrap();
/// let mut names =
/// TypedDateTimeNames::<(), NeoTimeSkeleton>::try_new(&locale).unwrap();
/// names.include_fixed_decimal_formatter();
///
/// // Create a pattern for the time, which is all numbers
Expand Down
13 changes: 6 additions & 7 deletions components/datetime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,24 @@
//!
//! ```
//! use icu::calendar::{DateTime, Gregorian};
//! use icu::datetime::{DateTimeFormatter, FixedCalendarDateTimeFormatter};
//! use icu::datetime::fieldset::YMDHM;
//! use icu::datetime::{DateTimeFormatter, FixedCalendarDateTimeFormatter};
//! use icu::locale::{locale, Locale};
//! use writeable::assert_try_writeable_eq;
//!
//! // You can work with a formatter that can select the calendar at runtime:
//! let locale = Locale::try_from_str("en-u-ca-gregory").unwrap();
//! let dtf = DateTimeFormatter::try_new(
//! &locale.into(),
//! YMDHM::medium(),
//! )
//! .expect("should successfully create DateTimeFormatter instance");
//! let dtf = DateTimeFormatter::try_new(&locale.into(), YMDHM::medium())
//! .expect("should successfully create DateTimeFormatter instance");
//!
//! // Or one that selects a calendar at compile time:
//! let typed_dtf = FixedCalendarDateTimeFormatter::<Gregorian, _>::try_new(
//! &locale!("en").into(),
//! YMDHM::medium(),
//! )
//! .expect("should successfully create FixedCalendarDateTimeFormatter instance");
//! .expect(
//! "should successfully create FixedCalendarDateTimeFormatter instance",
//! );
//!
//! let typed_date =
//! DateTime::try_new_gregorian(2020, 9, 12, 12, 34, 28).unwrap();
Expand Down
Loading

0 comments on commit 6c8e3e3

Please sign in to comment.