Module icu_datetime::fieldsets::builder

source ·
Expand description

Builder APIs for dynamic field sets.

These APIs are designed for when the field set is not known at compile time. This could happen if:

  1. The field set is sent over the network or read from a data file
  2. Implementing another interface with different types

If the field set is known at compile time, use the static fieldset APIs instead of the builder exported in this module.

All examples below will show both ways to build a field set.

§Examples

use icu::datetime::fieldsets;
use icu::datetime::fieldsets::builder::*;
use icu::datetime::fieldsets::enums::*;
use icu::datetime::options::*;

// Year, Month, Day
// Medium length
// Always display the era

let static_field_set = fieldsets::YMD::medium()
    .with_year_style(YearStyle::Always);

let mut builder = FieldSetBuilder::default();
builder.date_fields = Some(DateFields::YMD);
builder.length = Some(Length::Medium);
builder.year_style = Some(YearStyle::Always);
let dynamic_field_set = builder.build_date().unwrap();

assert_eq!(
    dynamic_field_set,
    DateFieldSet::YMD(static_field_set),
);

// Weekday and Time of day
// Medium length, implicit in the builder
// Display time to the minute

let static_field_set = fieldsets::ET::medium()
    .with_time_precision(TimePrecision::MinuteExact);

let mut builder = FieldSetBuilder::default();
builder.date_fields = Some(DateFields::E);
builder.time_precision = Some(TimePrecision::MinuteExact);
let dynamic_field_set = builder.build_date_and_time().unwrap();

assert_eq!(
    dynamic_field_set,
    DateAndTimeFieldSet::ET(static_field_set),
);

// Time and Time Zone
// Short length
// Long specific non-location time zone
// Display time to the millisecond
// Render for column alignment

let static_field_set = fieldsets::T::short()
    .with_time_precision(TimePrecision::SecondExact(FractionalSecondDigits::F3))
    .with_alignment(Alignment::Column)
    .with_zone_specific_long();

let mut builder = FieldSetBuilder::default();
builder.length = Some(Length::Short);
builder.time_precision = Some(TimePrecision::SecondExact(FractionalSecondDigits::F3));
builder.alignment = Some(Alignment::Column);
builder.zone_style = Some(ZoneStyle::Z);
let dynamic_field_set = builder.build_composite().unwrap();

assert_eq!(
    dynamic_field_set,
    CompositeFieldSet::TimeZone(static_field_set.into_enums()),
);

Structs§

Enums§

  • An error that occurs when creating a field set from a builder.
  • An enumeration over all possible date and calendar period field sets without options.
  • An enumeration over all possible time zone styles.