Struct icu_datetime::mock::zoned_datetime::MockZonedDateTime
source · [−]pub struct MockZonedDateTime {
pub datetime: DateTime<Gregorian>,
pub time_zone: MockTimeZone,
}
Expand description
A temporary struct that implements ZonedDateTimeInput
and is used in tests, benchmarks and examples of this component.
The composition of DateTime<Gregorian>
and MockTimeZone
.
Notice: Rust at the moment does not have a canonical way to represent date and time. We are introducing
MockZonedDateTime
as an example of the data necessary for ICU ZonedDateTimeFormat
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::parse_gregorian_from_str;
use icu::datetime::mock::time_zone::MockTimeZone;
use icu::calendar::{DateTime, Gregorian};
use icu::datetime::mock::zoned_datetime::MockZonedDateTime;
let dt: DateTime<Gregorian> = parse_gregorian_from_str("2020-10-14T13:21:00")
.expect("Failed to parse a datetime.");
let tz: MockTimeZone = "+05:00".parse()
.expect("Failed to parse a time zone.");
let zdt1 = MockZonedDateTime::new(dt, tz);
let zdt2: MockZonedDateTime = "2020-10-14T13:21:00+05:00".parse()
.expect("Failed to parse a zoned datetime.");
Fields
datetime: DateTime<Gregorian>
The datetime component.
time_zone: MockTimeZone
The time zone component.
Implementations
sourceimpl MockZonedDateTime
impl MockZonedDateTime
sourcepub const fn new(datetime: DateTime<Gregorian>, time_zone: MockTimeZone) -> Self
pub const fn new(datetime: DateTime<Gregorian>, time_zone: MockTimeZone) -> Self
Creates a new MockZonedDateTime
from an already validated DateTime<Gregorian>
and MockTimeZone
.
Trait Implementations
sourceimpl DateInput for MockZonedDateTime
impl DateInput for MockZonedDateTime
sourcefn day_of_month(&self) -> Option<DayOfMonth>
fn day_of_month(&self) -> Option<DayOfMonth>
Gets the day input.
sourcefn iso_weekday(&self) -> Option<IsoWeekday>
fn iso_weekday(&self) -> Option<IsoWeekday>
Gets the weekday input.
sourcefn day_of_year_info(&self) -> Option<DayOfYearInfo>
fn day_of_year_info(&self) -> Option<DayOfYearInfo>
Gets information on the position of the day within the year.
sourceimpl Debug for MockZonedDateTime
impl Debug for MockZonedDateTime
sourceimpl FromStr for MockZonedDateTime
impl FromStr for MockZonedDateTime
sourcefn from_str(input: &str) -> Result<Self, Self::Err>
fn from_str(input: &str) -> Result<Self, Self::Err>
Parse a MockZonedDateTime
from a string.
This utility is for easily creating dates, not a complete robust solution. The
string must take a specific form of the ISO 8601 format:
YYYY-MM-DDThh:mm:ssZ
,
YYYY-MM-DDThh:mm:ss±hh
,
YYYY-MM-DDThh:mm:ss±hhmm
,
YYYY-MM-DDThh:mm:ss±hh:mm
,
Examples
use icu::datetime::mock::zoned_datetime::MockZonedDateTime;
let date: MockZonedDateTime = "2020-10-14T13:21:00+05:30".parse()
.expect("Failed to parse a zoned datetime.");
type Err = DateTimeError
type Err = DateTimeError
The associated error which can be returned from parsing.
sourceimpl IsoTimeInput for MockZonedDateTime
impl IsoTimeInput for MockZonedDateTime
sourceimpl TimeZoneInput for MockZonedDateTime
impl TimeZoneInput for MockZonedDateTime
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 MockZonedDateTime
impl Send for MockZonedDateTime
impl Sync for MockZonedDateTime
impl Unpin for MockZonedDateTime
impl UnwindSafe for MockZonedDateTime
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