-
Notifications
You must be signed in to change notification settings - Fork 27
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 Interval math with DateTime #180
Comments
Initially, I preferred not to add conversions or interop methods, which can suddenly lead to a decrease in accuracy Now I think for some frequently used ypes we can add such conversion, with careful check that accuracy/range isn't lost (corresponding exception type already implemented) |
Yeah, I have this function in my code now. Not sure if std.datetime can deal with the overflow: @safe DateTime addInterval(DateTime date, dpq2.conv.time.Interval delta) {
if(delta.months != 0) {
date.add!"months"(delta.months);
}
// create a duration from the days/usecs
import core.time : days, usecs;
return date + (delta.days.days + delta.usecs.usecs);
} I verified that postgres applies the months interval before the days/hours, so this should mimic that behavior. |
Note that std.datetime also has an Interval type making this a bit awkward... |
Looks good. Can you make PR? If it's not urgent, then I can do it myself, but a little later |
It's not urgent. I just wanted to note it as something that is needed. I can use our internal function. If it gets added, I will switch to using the official one. |
If I find some time, I'll make a PR. |
A postgres Interval type cannot be mapped to a Duration, because it has a "months" field.
But all time math on DateTime involves Duration. There should at least be a way to add an Interval to a DateTime.
The text was updated successfully, but these errors were encountered: