On May 14, 2007, at 4:02 PM, Mike Hamilton wrote:
> Glen Holcomb wrote:
>> Does it have to be a time object?  Date has some methods that will do
>> what
>> you want without much if any hassle.
>>
>> On 5/14/07, Mike Hamilton <mikehamiltonca / gmail.com> wrote:
>>> I have 2 time objects and want to iterate over them by day. I  
>>> figured
>>> out that I can do:
>>> a = Time.mktime(2007,5,1,0,0,0)
>>> b = Time.mktime(2007,5,7,0,0,0)
>>> (a..b).each { |val|
>>>     code goes here
>>> }
>>> but when I do that it iterates over seconds. Does anyone have a
>>> suggestion on how to iterate over a different period when using Time
>>> objects?
>>
>> --
>> "Hey brother christian with your high and mighty errand, Your actions
>> speak
>> so loud, I can't hear a word you're saying."
>>
>> -Greg Graffin (Bad Religion)
> Well - I know how to do it with a date object but the objects I'm  
> using
> are already Time objects. The actual problem is that the dates that  
> I'm
> iterating over are entered in a local timezone and then converted to
> gmtime for a SQL query. All the date values are stored in the database
> in gmtime, so in order to run the query I have to have the time
> included. That's why iterating over the time object would be ideal, so
> that I can include the appropriate gmtime adjustment in the query
> values.

Why do you need to iterate over them?  If these values are already in  
the database, can't you just use:

:conditions => { :some_gmt_datetime_column => a..b }

which becomes a where clause like "some_gmt_datetime_column BETWEEN  
'2007-05-01' AND '2007-05-07'" (or whatever a.to_s(:db) gives)

If this doesn't help, perhaps you could explain your query a bit more  
and where you think the iteration is needed.

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com