Skip to main content

parse_datetime_at_date

Function parse_datetime_at_date 

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

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

§Arguments

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

§Examples

use jiff::Zoned;
use parse_datetime::{parse_datetime_at_date, ParsedDateTime};

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

 match after {
     ParsedDateTime::InRange(z) => assert_eq!("2024-09-16", z.strftime("%F").to_string()),
     ParsedDateTime::Extended(_) => unreachable!("unexpected for this input"),
 }

§Returns

  • Ok(ParsedDateTime) - If the input string can be parsed as a time
  • Err(ParseDateTimeError) - If the input string cannot be parsed

§Errors

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