Expand description

Date and Time operations

This API provides necessary functionality for formatting date and time to user readable textual representation.

DateTimeFormat is the main structure of the component. It accepts a set of arguments which allow it to collect necessary data from the DataProvider, and once instantiated, can be used to quickly format any date and time provided.

Examples

use icu::locid::Locale;
use icu::locid::macros::langid;
use icu::datetime::{DateTimeFormat, options::length, mock::parse_gregorian_from_str};

let provider = icu_testdata::get_provider();

let locale: Locale = langid!("en").into();

let options = length::Bag {
    date: Some(length::Date::Medium),
    time: Some(length::Time::Short),
    ..Default::default()
}.into();

let dtf = DateTimeFormat::try_new(locale, &provider, &options)
    .expect("Failed to create DateTimeFormat instance.");

let date = parse_gregorian_from_str("2020-09-12T12:35:00")
    .expect("Failed to parse date.");

let formatted_date = dtf.format(&date);
assert_eq!(formatted_date.to_string(), "Sep 12, 2020, 12:35 PM");

Modules

A collection of utilities for representing and working with dates as an input to formatting operations.

The collection of code that is needed for handling formatting operations for DateTimes. Central to this is the DateTimeFormat.

A collection of temporary structs and utilities to input data for tests, benchmarks, and examples.

DateTimeFormatOptions is a bag of options which, together with Locale, defines how dates will be formatted with a DateTimeFormat instance.

Data provider struct definitions for this ICU4X component.

Structs

DateTimeFormat is the main structure of the icu_datetime component. When constructed, it uses data from the [DataProvider], selected Locale and provided options to collect all data necessary to format any dates into that locale.

FormattedDateTime is a intermediate structure which can be retrieved as an output from DateTimeFormat.

TimeZoneFormat uses data from the [DataProvider], the selected Locale, and the provided TimeZoneFormatConfig to collect all data necessary to format time zones into that locale.

Enums

A list of possible error outcomes for the DateTimeFormat struct.

A bag of options which, together with Locale, defines how dates will be formatted with a DateTimeFormat instance.

A config enum for initializing TimeZoneFormat.

Traits

A calendar that can be found in CLDR