Struct dateparser::DateTimeUtc[][src]

pub struct DateTimeUtc(pub DateTime<Utc>);
Expand description

DateTimeUtc is an alias for chrono’s DateTime<UTC>. It implements std::str::FromStr’s from_str method, and it makes str’s parse method to understand the accepted date formats from this crate.

use dateparser::DateTimeUtc;

let accepted = vec![
    "1511648546",
    "1620021848429",
    "1620024872717915000",
    "2021-05-01T01:17:02.604456Z",
    "2017-11-25T22:34:50Z",
    "Wed, 02 Jun 2021 06:31:39 GMT",
    "2019-11-29 08:08:05-08",
    "2021-05-02 23:31:36.0741-07",
    "2021-05-02 23:31:39.12689-07",
    "2019-11-29 08:15:47.624504-08",
    "2021-04-30 21:14:10",
    "2021-04-30 21:14:10.052282",
    "2017-11-25 13:31:15 PST",
    "2017-11-25 13:31 PST",
    "2021-02-21",
    "2021-02-21 PST",
    "01:06:06",
    "4:00pm",
    "6:00 AM",
    "01:06:06 PST",
    "4:00pm PST",
    "6:00 AM PST",
    "May 02, 2021 15:51:31 UTC",
    "May 02, 2021 15:51 UTC",
];

for date_str in accepted {
    // parsed is DateTimeUTC and parsed.0 is chrono's DateTime<Utc>
    match date_str.parse::<DateTimeUtc>() {
        Ok(parsed) => println!("PARSED {} into UTC datetime {:?}", date_str, parsed.0),
        Err(err) => println!("ERROR from parsing {}: {}", date_str, err)
    }
}

Trait Implementations

impl FromStr for DateTimeUtc[src]

type Err = Error

The associated error which can be returned from parsing.

fn from_str(s: &str) -> Result<Self>[src]

Parses a string s to return a value of this type. Read more

Auto Trait Implementations

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.