Struct icu_datetime::mock::datetime::MockDateTime[][src]

pub struct MockDateTime {
    pub year: i32,
    pub month: u32,
    pub day: u32,
    pub hour: IsoHour,
    pub minute: IsoMinute,
    pub second: IsoSecond,
}

A temporary struct that implements DateTimeInput and is used in tests, benchmarks and examples of this component.

All fields in MockDateTime are 0-based. For example, January is represented as 0, not 1.

Notice: Rust at the moment does not have a canonical way to represent date and time. We are introducing MockDateTime as an example of the data necessary for ICU DateTimeFormat 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::datetime::MockDateTime;

let dt1 = MockDateTime::try_new(2020, 9, 24, 13, 21, 0)
    .expect("Failed to construct DateTime.");

let dt2: MockDateTime = "2020-10-14T13:21:00".parse()
    .expect("Failed to parse a datetime.");

Fields

year: i32

ISO-8601 year (proleptic Gregorian).

month: u32

0-based month index.

day: u32

0-based day index.

hour: IsoHour

0-based hour.

minute: IsoMinute

0-based minute.

second: IsoSecond

0-based second.

Implementations

impl MockDateTime[src]

pub const fn new(
    year: i32,
    month: u32,
    day: u32,
    hour: IsoHour,
    minute: IsoMinute,
    second: IsoSecond
) -> Self
[src]

Creates a new MockDateTime from a list of already validated date/time parameters.

pub fn try_new(
    year: usize,
    month: usize,
    day: usize,
    hour: usize,
    minute: usize,
    second: usize
) -> Result<Self, DateTimeError>
[src]

Constructor for MockDateTime.

Examples

use icu::datetime::mock::datetime::MockDateTime;

let dt = MockDateTime::try_new(2020, 9, 24, 13, 21, 0)
    .expect("Failed to construct a DateTime");

Trait Implementations

impl DateInput for MockDateTime[src]

impl Debug for MockDateTime[src]

impl Default for MockDateTime[src]

impl FromStr for MockDateTime[src]

type Err = DateTimeError

The associated error which can be returned from parsing.

fn from_str(input: &str) -> Result<Self, Self::Err>[src]

Parse a MockDateTime 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:ss.

use icu::datetime::mock::datetime::MockDateTime;

let date: MockDateTime = "2020-10-14T13:21:00".parse()
    .expect("Failed to parse a datetime.");

impl IsoTimeInput for MockDateTime[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DateTimeInput for T where
    T: DateInput + IsoTimeInput
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.