diff --git a/crates/core/src/model/scalar/datetime.rs b/crates/core/src/model/scalar/datetime.rs index 17540d69f..b86d00070 100644 --- a/crates/core/src/model/scalar/datetime.rs +++ b/crates/core/src/model/scalar/datetime.rs @@ -237,6 +237,8 @@ fn parse_date_time(s: &str) -> Option { None } else if let "now" | "today" = s.to_lowercase().trim() { Some(DateTimeImpl::now_utc()) + } else if s.parse::().is_ok() { + DateTimeImpl::parse(s, format_description!("[unix_timestamp]")).ok() } else { let offset_re = Regex::new(r"[+-][01][0-9]{3}$").unwrap(); @@ -375,6 +377,21 @@ mod test { assert!(actual.unwrap().unix_timestamp() == 1455616800); } + #[test] + fn parse_date_time_unix_timestamp_format() { + let input = "0"; // epoch + let actual = parse_date_time(input); + assert!(actual.unwrap().unix_timestamp() == 0); + + let input = "1455616800"; // positive + let actual = parse_date_time(input); + assert!(actual.unwrap().unix_timestamp() == 1455616800); + + let input = "-1455616800"; // negative + let actual = parse_date_time(input); + assert!(actual.unwrap().unix_timestamp() == -1455616800); + } + #[test] fn parse_date_time_to_string() { let date = DateTime::now();