Function dateparser::parse_with_timezone [−][src]
pub fn parse_with_timezone<Tz2: TimeZone>(
input: &str,
tz: &Tz2
) -> Result<DateTime<Utc>>
Expand description
Similar to parse()
, this function takes a datetime string and a custom chrono::TimeZone
,
and tries to parse the datetime string. When timezone is not given in the string, this function
will assume and parse the datetime by the custom timezone provided in this function’s arguments.
use dateparser::parse_with_timezone; use chrono::offset::{Local, Utc}; use chrono_tz::US::Pacific; let parsed_in_local = parse_with_timezone("6:15pm", &Local).unwrap(); assert_eq!( parsed_in_local, Local::now().date().and_hms(18, 15, 0).with_timezone(&Utc), ); let parsed_in_utc = parse_with_timezone("6:15pm", &Utc).unwrap(); assert_eq!( parsed_in_utc, Utc::now().date().and_hms(18, 15, 0), ); let parsed_in_pacific = parse_with_timezone("6:15pm", &Pacific).unwrap(); assert_eq!( parsed_in_pacific, Utc::now().with_timezone(&Pacific).date().and_hms(18, 15, 0).with_timezone(&Utc), );