Struct icu::timezone::CustomTimeZone
source · [−]pub struct CustomTimeZone {
pub gmt_offset: Option<GmtOffset>,
pub time_zone_id: Option<TimeZoneBcp47Id>,
pub metazone_id: Option<MetazoneId>,
pub zone_variant: Option<ZoneVariant>,
}
Expand description
A utility type that can hold time zone information.
The GMT offset is used as a final fallback for formatting. The other three fields are used for more human-friendly rendering of the time zone.
This type does not enforce that the four fields are consistent with each other. If they do not represent a real time zone, unexpected results when formatting may occur.
Examples
use icu::timezone::{CustomTimeZone, GmtOffset};
let tz1 = CustomTimeZone {
gmt_offset: Some(GmtOffset::default()),
time_zone_id: None,
metazone_id: None,
zone_variant: 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
zone_variant: Option<ZoneVariant>
The time variant e.g. “daylight” or “standard”
Implementations
sourceimpl CustomTimeZone
impl CustomTimeZone
sourcepub const fn new_with_offset(gmt_offset: GmtOffset) -> CustomTimeZone
pub const fn new_with_offset(gmt_offset: GmtOffset) -> CustomTimeZone
Creates a new CustomTimeZone
with the given GMT offset.
sourcepub const fn new_empty() -> CustomTimeZone
pub const fn new_empty() -> CustomTimeZone
Creates a time zone with no information.
One or more fields must be specified before this time zone is usable.
sourcepub const fn utc() -> CustomTimeZone
pub const fn utc() -> CustomTimeZone
Creates a new CustomTimeZone
with the GMT offset set to UTC.
All other fields are left empty.
sourcepub fn maybe_calculate_metazone(
&mut self,
metazone_calculator: &MetazoneCalculator,
local_datetime: &DateTime<Iso>
) -> &mut CustomTimeZone
pub fn maybe_calculate_metazone(
&mut self,
metazone_calculator: &MetazoneCalculator,
local_datetime: &DateTime<Iso>
) -> &mut CustomTimeZone
Overwrite the metazone id in MockTimeZone.
Examples
use icu::timezone::provider::{MetazoneId, TimeZoneBcp47Id};
use icu::timezone::CustomTimeZone;
use icu::timezone::GmtOffset;
use icu::timezone::MetazoneCalculator;
use icu_calendar::DateTime;
use icu_locid::locale;
use tinystr::tinystr;
let mzc = MetazoneCalculator::try_new_unstable(&icu_testdata::unstable())
.expect("data exists");
let mut tz = CustomTimeZone {
gmt_offset: Some("+11".parse().expect("Failed to parse a GMT offset.")),
time_zone_id: Some(TimeZoneBcp47Id(tinystr!(8, "gugum"))),
metazone_id: None,
zone_variant: None,
};
tz.maybe_calculate_metazone(
&mzc,
&DateTime::try_new_iso_datetime(1971, 10, 31, 2, 0, 0).unwrap(),
);
assert_eq!(tz.metazone_id, Some(MetazoneId(tinystr!(4, "guam"))));
Trait Implementations
sourceimpl Debug for CustomTimeZone
impl Debug for CustomTimeZone
sourceimpl FromStr for CustomTimeZone
impl FromStr for CustomTimeZone
sourcefn from_str(
input: &str
) -> Result<CustomTimeZone, <CustomTimeZone as FromStr>::Err>
fn from_str(
input: &str
) -> Result<CustomTimeZone, <CustomTimeZone as FromStr>::Err>
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;
use icu::timezone::GmtOffset;
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.");
assert_eq!(tz0.gmt_offset.map(GmtOffset::offset_seconds), Some(0));
assert_eq!(tz1.gmt_offset.map(GmtOffset::offset_seconds), Some(7200));
assert_eq!(tz2.gmt_offset.map(GmtOffset::offset_seconds), Some(-9000));
assert_eq!(tz3.gmt_offset.map(GmtOffset::offset_seconds), Some(9000));
type Err = TimeZoneError
type Err = TimeZoneError
The associated error which can be returned from parsing.
sourceimpl TimeZoneInput for CustomTimeZone
impl TimeZoneInput for CustomTimeZone
sourcefn gmt_offset(&self) -> Option<GmtOffset>
fn gmt_offset(&self) -> Option<GmtOffset>
The GMT offset in Nanoseconds.
sourcefn time_zone_id(&self) -> Option<TimeZoneBcp47Id>
fn time_zone_id(&self) -> Option<TimeZoneBcp47Id>
The IANA time-zone identifier.
sourcefn metazone_id(&self) -> Option<MetazoneId>
fn metazone_id(&self) -> Option<MetazoneId>
The metazone identifier.
sourcefn zone_variant(&self) -> Option<ZoneVariant>
fn zone_variant(&self) -> Option<ZoneVariant>
The time variant (e.g. “daylight”, “standard”)
Auto Trait Implementations
impl RefUnwindSafe for CustomTimeZone
impl Send for CustomTimeZone
impl Sync for CustomTimeZone
impl Unpin for CustomTimeZone
impl UnwindSafe for CustomTimeZone
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more