Add DateTime type and operations

This commit introduces the `DateTime` type to the language, enabling
users to work with dates and times. It includes:

- A new `DateTime` variant in the `Value` and `StaticType` enums.
- A `date` function for parsing date strings into `DateTime` values.
- Overloads for `+` and `-` operators to support `DateTime` arithmetic.
- Comparison operators (`>`, `<`) for `DateTime` values.
- Corresponding unit tests for `DateTime` operations.
- Updates to the `gemini.md` documentation to reflect the new
  functionality.
  Add DateTime type and operations

Introduce a new `DateTime` type to the language, allowing for date and
time manipulation. This includes:

*   Parsing dates and datetimes from strings.
*   Performing arithmetic operations (addition and subtraction) between
    `DateTime` and `Int` (representing milliseconds) and between two
    `DateTime` values (resulting in an `Int` duration).
*   Enabling comparison operations (`>`, `<`) between `DateTime` values.
This commit is contained in:
Michael Schimmel
2026-02-19 13:27:44 +01:00
parent 49db73800a
commit a5957f524b
4 changed files with 54 additions and 2 deletions
+12
View File
@@ -291,4 +291,16 @@ mod tests {
assert_eq!(check_source("(+ \"a\" \"b\")").ty, StaticType::Text);
assert_eq!(check_source("(/ 1 2)").ty, StaticType::Float);
}
#[test]
fn test_datetime_inference() {
// date("2023-01-01") -> DateTime
assert_eq!(check_source("(date \"2023-01-01\")").ty, StaticType::DateTime);
// DateTime + Int -> DateTime
assert_eq!(check_source("(+ (date \"2023-01-01\") 86400000)").ty, StaticType::DateTime);
// DateTime - DateTime -> Int (Duration)
assert_eq!(check_source("(- (date \"2023-01-02\") (date \"2023-01-01\"))").ty, StaticType::Int);
// DateTime comparison -> Bool
assert_eq!(check_source("(> (date \"2023-01-02\") (date \"2023-01-01\"))").ty, StaticType::Bool);
}
}