-
Notifications
You must be signed in to change notification settings - Fork 0
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
Inspiration #4
Comments
Sorry for my late reply, somehow I didn't get an email from this topic.
I can see why
The
👍
Great ideas, will work in those!
I've actually been working on this, you can see the progress in this PR: #5
We did the same and came up with a gem. I'm not sure how useful the DateRange is for every Rails app to make it into Rails Core. Have been discussing this with Rails core members. |
In #6 you can find the intersection support. Subtracting is a bit more difficult, will look into that later! |
Great! We'll work on replacing our own code with this gem, let's hope it becomes somewhat of a standard! |
Can you maybe explain a bit further what the use case is for subtracting date ranges? There are many edge cases that might make this function not behave like expected. It might be a challenge to make sure these edge cases are handled correctly in the caller of the subtraction method. |
It's useful in scenarios where we want to do calculations on date ranges as if they were sets. Operations such as union, intersection, subtraction, can be used to answer questions such as:
For union and intersection, I would expect a single range to be returned. For subtraction, guess an array of either 0, 1 or 2 ranges would make sense? |
I'd suggest supporting different settings for inclusive/exclusive bounds: See postgres documentation: https://www.postgresql.org/docs/9.3/rangetypes.html Should also affect to_s and inspect by printing either (),[],[) or (] |
Hey, I just stumbed upon this. We have a very similar class in our code base - It might be helpful to look at some of the ideas we've been discussing:
since_date
should be inclusive anduntil_date
should be exclusive. See here for more details on why this is a good idea: https://stackoverflow.com/questions/9795391/is-there-a-standard-for-inclusive-exclusive-ends-of-time-intervals2012-02-01..2012-03-01
format. Is..
standard? We've been usingself.parse(start, end)
instead.split_to
is great - it looks like you've done the same thing within_groups_of
. Keep that name, it's better.intersection
of two date ranges, as well assubtracting
two date ranges could also be useful.I hope we can get this into ActiveSupport so we don't have to come up with our own classes all the time ;-)
The text was updated successfully, but these errors were encountered: