Hi Josi,

So do people want these methods? How frequently do you use time ranges?


I'd find the `surrounding`-methods useful for debugging in the console.

I'll occasionally use a range to find incoming webhook events that arrived 
around the same time a buggy user was created. When I'm typing it, it does 
feel like it could be improved:

# buggy user
u = User.find(123)

# Find webhook events that happened around the same time
# the buggy user was created.
events = WebhookEvent.where(created_at: (u.created_at - 
2.minutes)..(u.created_at 
+ 2.minutes))


My first reaction is I do prefer it with using `and_the_surrounding`:

# Same query using proposed method:
events = WebhookEvent.where(created_at: u.created_at.and_the_surrounding(
2.minutes))



Eliot


On Saturday, 13 April 2019 01:56:02 UTC+1, Josi McClellan wrote:
>
> Hello, this is my first (very tiny) attempt to get involved.
>
> My thought is to supplement the #since / #ago family with methods that 
> return a Range. Durations and dates/times could each get three methods: one 
> for the future, one for the past, and one for both:
> 2.weeks.following 1.year.ago
> 2.weeks.preceding 1.year.ago
> 2.weeks.surrounding 1.year.ago
> 1.year.ago.and_the_following weeks: 2
> 1.year.ago.and_the_preceding weeks: 2
> 1.year.ago.and_the_surrounding weeks: 2
>
> Also, infinite ranges will someday be universal. Currently endless (min..) 
> are in 2.6, and beginless (..max) are in development. The following 
> no-argument form will then be possible:
> case updated_at
> when 10.years.ago.and_the_preceding then #...
> when 1.year.ago.and_the_preceding then #...
> when 1.month.ago.and_the_preceding then #...
>
> Obviously implementing this is trivial since they'd just use #since/#ago 
> for durations and #advance for times/dates. So do people want these 
> methods? How frequently do you use time ranges?
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at https://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/d/optout.

Reply via email to