Hi all,

I'm building an application that will allow store owners to keep track
of the opening and closing times of their shops.  For example, a store
owner might input that their shop is open Monday, Wednesday, and
Friday from 9am to 5pm.

To keep track of these store hours, I'm using Store and Opening
models, where each store has many openings.

The openings table looks like:
id
day (string -- day of the week, in words)
opens_at (time)
closes_at (time)

It seems that ActiveRecord (2.1.1) insists on appending a bogus date
to the time for inserts & queries.  For example, for a named scope to
allow quick searches for whether a store is opened for a given day &
time, I have to use this:

  named_scope :open_for, lambda { |day, time| { :conditions =>["day
= ? AND opens_at <= ? AND closes_at >= ?", day, "2001-00-01 " <<
time.to_s(:time) << ":00", "2000-01-01 " << time.to_s(:time) << ":
00" ] } }

when I would much prefer something like:

  named_scope :open_for, lambda { |day, time| { :conditions =>["day
= ? AND opens_at <= ? AND closes_at >= ?", day, time, time] } }

Does anyone know of a way to handle time columns more elegantly?

best,

Jacob Patton

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to