Function chrono_systemd_time::parse_timestamp_tz
source · pub fn parse_timestamp_tz<S, T, Tz>(
timestamp: S,
timezone: T
) -> Result<LocalDateTime<Tz>, Error>where
S: AsRef<str>,
T: Borrow<Tz>,
Tz: TimeZone,
Expand description
Parse a timestamp returning a DateTime
with the specified timezone.
Examples
use chrono::{DateTime, Duration, Local, TimeZone, Utc};
fn parse_timestamp_tz_aux<Tz: TimeZone>(timestamp: &str, timezone: Tz) -> DateTime<Tz> {
parse_timestamp_tz(timestamp, timezone)
.unwrap()
.single()
.unwrap()
}
assert_eq!(parse_timestamp_tz_aux("today + 2h", Utc),
parse_timestamp_tz_aux("today", Utc) + Duration::hours(2));
assert_eq!(parse_timestamp_tz_aux("yesterday", Local),
parse_timestamp_tz_aux("today - 1d", Local));
assert_eq!(parse_timestamp_tz_aux("2018-06-21", Utc),
parse_timestamp_tz_aux("18-06-21 1:00 - 1h", Utc));