-
Notifications
You must be signed in to change notification settings - Fork 275
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge 'Add partial support for datetime() function' from Preston Thorpe
This PR adds the `datetime` function, with all the support currently that date/time have for modifiers, and `julianday` function, as well as some additional modifiers for date/time/datetime. There are a couple considerations here, I left a couple comments but essentially there is going to have to be some more work done to track the state of the expression during the application of modifiers, to handle a bunch of edge-cases like re-applying the same timezone modifier to itself, or converting an integer automatically assumed to be julianday, into epoch, or `ceiling`/`floor` which will determine relative addition of time in cases like ``` 2024-01-31 +1 month = 2024-03-02 ``` which was painful enough to get working to begin with. I couldn't get the `julianday_converter` library to get the exact same float precision as sqlite, so function is included that matches their output, for some reason floating point math + `.floor()` would give the correct result. They seem to 'round' to 8 decimal places, and I was able to get this to work with the same output as sqlite, except in cases like `2234.5`, in which case we return `2234.5000000` because of the `fmt` precision: ```rust pub fn exec_julianday(time_value: &OwnedValue) -> Result<String> { let dt = parse_naive_date_time(time_value); match dt { // if we did something heinous like: parse::<f64>().unwrap().to_string() // that would solve the precision issue, but dear lord... Some(dt) => Ok(format!("{:.1$}", to_julian_day_exact(&dt), 8)), None => Ok(String::new()), } } ``` Suggestions would be appreciated on the float precision issue. Reviewed-by: Sonny <[email protected]> Closes #600
- Loading branch information
Showing
6 changed files
with
944 additions
and
136 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.