Expand description
Date parsing utilities for ISO 8601 format strings.
This module provides parsing functions for ISO 8601 date and datetime formats used in AIMX expressions. It supports various date formats including date-only, date with time, and date with time and timezone specifications.
The parser is designed to integrate with the larger AIMX literal parsing system
and produces [jiff::civil::DateTime] objects that can be used throughout
the expression evaluation system.
§Supported Formats
- Date only:
YYYY-MM-DD - Date with time:
YYYY-MM-DDTHH:MM:SSorYYYY-MM-DD HH:MM:SS - Date with time and timezone:
YYYY-MM-DDTHH:MM:SSZorYYYY-MM-DD HH:MM:SSZ - Date with optional milliseconds:
YYYY-MM-DDTHH:MM:SS.sssZ
§Examples
2023-01-15 // Date only
2023-01-15T10:30:00 // Date with time (T separator)
2023-01-15 10:30:00 // Date with time (space separator)
2023-01-15T10:30:00.123Z // Date with time and milliseconds
2023-01-15T10:30:00Z // Date with time and UTC timezone§Integration with AIMX
This parser is used internally by the crate::literal::parse_literal function in the
crate::literal module to parse date literals. It’s not typically used
directly but rather through the main expression parsing system.
Date literals in expressions are automatically converted to crate::Literal::Date
variants which can then be used with date functions or in date arithmetic.
use aimx::{aimx_parse, ExpressionLike, Context, Literal};
let mut context = Context::new();
// Parse a date literal directly
let expression = aimx_parse("2023-01-15");
let result = expression.evaluate(&mut context).unwrap();
assert!(matches!(result, aimx::Value::Literal(Literal::Date(_))));
// Use in date functions
let expression = aimx_parse("year(2023-12-25)");
let result = expression.evaluate(&mut context).unwrap();
assert_eq!(result.to_string(), "2023");§Notes
- All dates are parsed into [
jiff::civil::DateTime] objects - The parser validates date components (e.g., rejects invalid months or days)
- Timezone information is currently ignored but the ‘Z’ suffix is supported
- Nanosecond precision is supported with up to 3 decimal places for milliseconds
- Whitespace is automatically trimmed before parsing
Functions§
- parse_
date - Parse a date literal in ISO 8601 format.