Function parse_date

Source
pub fn parse_date(input: &str) -> IResult<&str, DateTime>
Expand description

Parse a date literal in ISO 8601 format.

This is the main entry point for parsing date literals in AIMX. It supports multiple ISO 8601 date formats in order of preference:

  1. Date with time and timezone: YYYY-MM-DDTHH:MM:SS[.sss]Z
  2. Date with time: YYYY-MM-DD[ T]HH:MM:SS[.sss]
  3. Date only: YYYY-MM-DD

This function is used internally by the literal parsing system and is not typically called directly by user code. For parsing date strings in your own code, consider using the date functions like as_date() instead.

§Arguments

  • input - The input string slice to parse

§Returns

A IResult containing the remaining unparsed input and parsed DateTime.

§Examples

use aimx::literals::date::parse_date;
use jiff::civil::DateTime;

// Date only
let result = parse_date("2023-01-15");
assert!(result.is_ok());
let (remaining, datetime) = result.unwrap();
assert_eq!(remaining, "");
assert_eq!(datetime.year(), 2023);
assert_eq!(datetime.month(), 1);
assert_eq!(datetime.day(), 15);

// Date with time (space separator)
let result = parse_date("2023-01-15 10:30:00");
assert!(result.is_ok());

// Date with time and timezone
let result = parse_date("2023-01-15T10:30:00Z");
assert!(result.is_ok());

// Date with milliseconds
let result = parse_date("2023-01-15T10:30:00.123Z");
assert!(result.is_ok());

§See Also