What do you mean that it adds a second? For the test I have here it shows it
querying like this:
SELECT * FROM "events" WHERE ("events"."start_time" >= '2009-10-20 00:00:00'
AND "events"."start_time" <= '2009-10-20 23:59:59')

So everything starting from and including the first second and ending on and
including the final second of that day. Yours will only get up to 23:59:58.
What happens when something happens in that last second? ;)



2009/10/20 Jeremy Grant <[email protected]>

> Hey Ryan,
> I've added a branch using by_star called radar, however it fails because
> the following line from lib/shared.rb adds 1 second:
> ["#{field} >= ? AND #{field} <= ?", start_time.utc, end_time.utc]
> it would need to be should be to work
> ["#{field} >= ? AND #{field} < ?", start_time.utc, end_time.utc]
> However, I haven't had time to check if that would the cause other types of
> ranges by_star does.
>
> Cheers,
> Jeremy
>
>
> On Mon, Oct 19, 2009 at 4:46 PM, Ryan Bigg <[email protected]>wrote:
>
>> Or http://github.com/radar/by_star will let you do:
>> Model.by_day(time)
>>
>> 2009/10/19 Lawrence Pit <[email protected]>
>>
>>
>>> Hi Jeremy,
>>>
>>> Alternatively:
>>>
>>>   def self.by_published(time)
>>>     scoped_by_published_at(time.beginning_of_day..time.end_of_day)
>>>   end
>>>
>>>
>>> (instead of Date.parse you need to use Time.zone.parse in your tests
>>> though)
>>>
>>>
>>>
>>> Lawrence
>>>
>>>
>>> Ah yeah of course, sorry didn't read it properly. I really can't see why
>>> you would do an IN like that though.
>>>
>>> On Mon, Oct 19, 2009 at 2:01 PM, Lawrence Pit <[email protected]>wrote:
>>>
>>>>
>>>> The doc is correct.
>>>>
>>>> If you use hash conditions with a range having Time objects, you're
>>>> fine.
>>>>
>>>> If you use it with array conditions however, then you're in trouble.
>>>>
>>>>
>>>>
>>>> Lawrence
>>>>
>>>> Yeah I think that documentation might be old, since in my test I got >=
>>>> and < not and sql IN when I used a range.
>>>>
>>>> On Mon, Oct 19, 2009 at 1:37 PM, Lawrence Pit 
>>>> <[email protected]>wrote:
>>>>
>>>>>
>>>>> It's described here:
>>>>>
>>>>>
>>>>> http://guides.rubyonrails.org/active_record_querying.html#time-and-date-conditions
>>>>>
>>>>>
>>>>>
>>>>> Lawrence
>>>>>
>>>>>  Be wary of passing in a Time-based Range object to ActiveRecord's
>>>>> conditions like that as I've seen behaviour where it will check for
>>>>> every second of that range. It could have changed since I've looked
>>>>> though.
>>>>>
>>>>>
>>>>>  There's been much discussion re. this on the list so far, with code
>>>>> examples and all. Mind expanding on what exactly Jeremy should be wary
>>>>> of? Code would be good?
>>>>>
>>>>> -- tim
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>
>>
>> --
>> Ryan Bigg
>>
>>
>>
>
> >
>


-- 
Ryan Bigg

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rails-oceania?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to