From cd89ac0873fe18eb553a5f15f7b406691acc7b60 Mon Sep 17 00:00:00 2001 From: Suraj N. Kurapati Date: Thu, 11 Dec 2008 14:28:00 -0800 Subject: [PATCH] postgresql_adapter: Include time zone in result of quoted_date() When the time zone is not included in a quoted date (as was the case before this patch), we make the assumption that the database server resides in (or is configured as if it resides in) the same time zone as the application which is using the ActiveRecord library to quote SQL dates. This patch removes the above assumption by including the time zone in quoted dates, so that ActiveRecord generates SQL queries that work regardless of whether your application happens to be running in the same time zone as your Postgres database server. Signed-off-by: Suraj N. Kurapati --- .../connection_adapters/postgresql_adapter.rb | 9 ++++++--- 1 files changed, 6 insertions(+), 3 deletions(-) diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 60ec01b..19f7996 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -394,10 +394,13 @@ module ActiveRecord end # Quote date/time values for use in SQL input. Includes microseconds - # if the value is a Time responding to usec. + # if the value is a Time responding to usec. Includes timezone if + # the value is a Time responding to zone. def quoted_date(value) #:nodoc: - if value.acts_like?(:time) && value.respond_to?(:usec) - "#{super}.#{sprintf("%06d", value.usec)}" + if value.acts_like?(:time) + usec = sprintf(".%06d", value.usec) if value.respond_to?(:usec) + zone = " #{value.zone}" if value.respond_to?(:zone) + "#{super}#{usec}#{zone}" else super end -- 1.6.0.2.1172.ga5ed0