Function parse_datetime_at_date

Source
pub fn parse_datetime_at_date<S: AsRef<str> + Clone>(
    date: DateTime<Local>,
    input: S,
) -> Result<DateTime<FixedOffset>, ParseDateTimeError>
Expand description

Parses a time string at a specific date and returns a DateTime representing the absolute time of the string.

§Arguments

  • date - The date represented in local time
  • s - A string slice representing the time.

§Examples

use chrono::{Duration, Local};
use parse_datetime::parse_datetime_at_date;

 let now = Local::now();
 let after = parse_datetime_at_date(now, "2024-09-13UTC +3 days");

 assert_eq!(
   "2024-09-16",
   after.unwrap().naive_utc().format("%F").to_string()
 );

§Returns

  • Ok(DateTime<FixedOffset>) - If the input string can be parsed as a time
  • Err(ParseDateTimeError) - If the input string cannot be parsed as a relative time

§Errors

This function will return Err(ParseDateTimeError::InvalidInput) if the input string cannot be parsed as a relative time.