pub struct MockTimeZone {
    pub gmt_offset: GmtOffset,
    pub time_zone_id: Option<TimeZoneBcp47Id>,
    pub metazone_id: Option<MetaZoneId>,
    pub time_variant: Option<TinyStr8>,
}
Expand description

A temporary struct that implements TimeZoneInput and is used in tests, benchmarks and examples of this component.

Notice: Rust at the moment does not have a canonical way to represent time zones. We are introducing MockTimeZone as an example of the data necessary for ICU TimeZoneFormat to work, and we hope to work with the community to develop core date and time APIs that will work as an input for this component.

Examples

use icu::datetime::mock::time_zone::MockTimeZone;
use icu::datetime::date::GmtOffset;

let tz1 = MockTimeZone::new(
    GmtOffset::default(),
    /* time_zone_id  */ None,
    /* metazone_id   */ None,
    /* time_variaint */ None,
);

let tz2: MockTimeZone = "+05:00".parse()
    .expect("Failed to parse a time zone.");

Fields

gmt_offset: GmtOffset

The GMT offset in seconds.

time_zone_id: Option<TimeZoneBcp47Id>

The IANA time-zone identifier

metazone_id: Option<MetaZoneId>

The CLDR metazone identifier

time_variant: Option<TinyStr8>

The time variant e.g. “daylight” or “standard”

Implementations

Creates a new MockTimeZone. A GMT offset is required, as it is used as a final fallback for formatting. The other arguments optionally allow access to more robust formats.

Trait Implementations

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Parse a MockTimeZone from a string.

This utility is for easily creating time zones, not a complete robust solution.

The offset must range from GMT-12 to GMT+14. The string must be an ISO-8601 time zone designator: e.g. Z e.g. +05 e.g. +0500 e.g. +05:00

Examples
use icu::datetime::mock::time_zone::MockTimeZone;

let tz0: MockTimeZone = "Z".parse().expect("Failed to parse a time zone.");
let tz1: MockTimeZone = "+02".parse().expect("Failed to parse a time zone.");
let tz2: MockTimeZone = "-0230".parse().expect("Failed to parse a time zone.");
let tz3: MockTimeZone = "+02:30".parse().expect("Failed to parse a time zone.");

The associated error which can be returned from parsing.

The GMT offset in Nanoseconds.

The IANA time-zone identifier.

The metazone identifier.

The time variant (e.g. “daylight”, “standard”)

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.