Struct icu_datetime::mock::time_zone::MockTimeZone
source · [−]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
sourceimpl MockTimeZone
impl MockTimeZone
sourcepub const fn new(
gmt_offset: GmtOffset,
time_zone_id: Option<TimeZoneBcp47Id>,
metazone_id: Option<MetaZoneId>,
time_variant: Option<TinyStr8>
) -> Self
pub const fn new(
gmt_offset: GmtOffset,
time_zone_id: Option<TimeZoneBcp47Id>,
metazone_id: Option<MetaZoneId>,
time_variant: Option<TinyStr8>
) -> Self
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
sourceimpl Debug for MockTimeZone
impl Debug for MockTimeZone
sourceimpl Default for MockTimeZone
impl Default for MockTimeZone
sourcefn default() -> MockTimeZone
fn default() -> MockTimeZone
Returns the “default value” for a type. Read more
sourceimpl FromStr for MockTimeZone
impl FromStr for MockTimeZone
sourcefn from_str(input: &str) -> Result<Self, Self::Err>
fn from_str(input: &str) -> Result<Self, Self::Err>
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.");
type Err = DateTimeError
type Err = DateTimeError
The associated error which can be returned from parsing.
sourceimpl TimeZoneInput for MockTimeZone
impl TimeZoneInput for MockTimeZone
sourcefn gmt_offset(&self) -> GmtOffset
fn gmt_offset(&self) -> 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 time_variant(&self) -> Option<&TinyStr8>
fn time_variant(&self) -> Option<&TinyStr8>
The time variant (e.g. “daylight”, “standard”)
Auto Trait Implementations
impl RefUnwindSafe for MockTimeZone
impl Send for MockTimeZone
impl Sync for MockTimeZone
impl Unpin for MockTimeZone
impl UnwindSafe for MockTimeZone
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