Summary: Queries using a Time object do not take in to account the Base.default_timezone.
A Ruby Time object represents time independently of it's internal storage. This leads to each of the following evaluating to true:
time = Time.utc(2000,1,1,15,28)
time.gmt?
time.to_i == time.getlocal.to_i
time.to_s != time.getlocal.to_s
activerecord currently uses the Time.strftime method to quote date/time's. The problem comes when you store times in the database in one zone, say UTC, but construct an SQL query with a time object in the other zone (local). The problem is that strftime simply plucks out the hours, mins, etc components from the Time object, irrespective of the databases timezone. In such a case, the hours, mins, etc components will not correspond to the database, despite the actual time (seconds since epoch/to_i) being logically equivalent.
To rectify this problem, Time objects need to be translated to the applications Base.default_timezone before being access with strftime.
Please find attached a patch for the postgresql adapter and the base quoting module, as well as a test case.
Tested with mysql and postgresql before submitting.