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

A utility type that can hold time zone information

Examples

use icu::timezone::{GmtOffset, CustomTimeZone};

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

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

Fields

gmt_offset: Option<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<TimeVariant>

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

Implementations

Creates a new CustomTimeZone. 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.

Overwrite the metazone id in MockTimeZone.

Examples
use icu::timezone::GmtOffset;
use icu::timezone::MetaZoneCalculator;
use icu::timezone::CustomTimeZone;
use icu::timezone::provider::{MetaZoneId, TimeZoneBcp47Id};
use icu_calendar::DateTime;
use icu_locid::locale;
use tinystr::tinystr;

let provider = icu_testdata::get_provider();
let mzc = MetaZoneCalculator::try_new_with_buffer_provider(&provider).expect("data exists");
let mut tz = CustomTimeZone::new(
    /* gmt_offset */ Some("+11".parse().expect("Failed to parse a GMT offset.")),
    /* time_zone_id */ Some(TimeZoneBcp47Id(tinystr!(8, "gugum"))),
    /* metazone_id */ None,
    /* time_variaint */ None,
);
tz.maybe_set_metazone(
    &DateTime::new_iso_datetime(1971, 10, 31, 2, 0, 0).unwrap(),
    &mzc,
);
assert_eq!(tz.metazone_id, Some(MetaZoneId(tinystr!(4, "guam"))));

Trait Implementations

Formats the value using the given formatter. Read more

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

Parse a CustomTimeZone 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::timezone::CustomTimeZone;

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

The associated error which can be returned from parsing.

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.