-
Notifications
You must be signed in to change notification settings - Fork 296
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add partial support for datetime() function #600
Conversation
2c93c59
to
878bad6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
### Date and Time Modifiers | ||
| Modifier | Status| Comment | | ||
|----------------|-------|---------------------------------| | ||
| Days | Yes | | | ||
| Hours | Yes | | | ||
| Minutes | Yes | | | ||
| Seconds | Yes | | | ||
| Months | Yes | | | ||
| Years | Yes | | | ||
| TimeOffset | Yes | | | ||
| DateOffset | Yes | | | ||
| DateTimeOffset | Yes | | | ||
| Ceiling | No | | | ||
| Floor | No | | | ||
| StartOfMonth | Yes | | | ||
| StartOfYear | Yes | | | ||
| StartOfDay | Yes | | | ||
| Weekday(N) | Yes | | | ||
| Auto | No | | | ||
| UnixEpoch | No | | | ||
| JulianDay | No | | | ||
| Localtime |Partial| requires fixes to avoid double conversions.| | ||
| Utc |Partial| requires fixes to avoid double conversions.| | ||
| Subsec | Yes | | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great! adding the time modifiers makes it very clear 🥇
let mut start_reg = 0; | ||
match args { | ||
Some(args) if args.len() > 1 => { | ||
crate::bail_parse_error!("epoch function with > 1 arguments. Modifiers are not yet supported."); | ||
crate::bail_parse_error!("epoch or julianday function with > 1 arguments. Modifiers are not yet supported."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added #602 for supporting modifiers for these functions later.
This PR adds the
datetime
function, with all the support currently that date/time have for modifiers, andjulianday
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 likewhich 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 like2234.5
, in which case we return2234.5000000
because of thefmt
precision:Suggestions would be appreciated on the float precision issue.