Struct icu_datetime::mock::time_zone::MockTimeZone[][src]

pub struct MockTimeZone {
    pub gmt_offset: GmtOffset,
    pub time_zone_id: Option<String>,
    pub metazone_id: Option<String>,
    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<String>

The IANA time-zone identifier

metazone_id: Option<String>

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. TODO(#606) switch this to BCP-47 identifier. Read more

The metazone identifier. TODO(#528) switch to a compact, stable ID. Read more

The time variant (e.g. “daylight”, “standard”) TODO(#619) use TinyStr for time variants. Read more

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

Clone this trait object reference, returning a boxed trait object.

Return this boxed trait object as Box<dyn Any>. Read more

Return this trait object reference as &dyn Any. Read more

Performs the conversion.

Performs the conversion.

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.