aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/types/time_with_zone.rb
diff options
context:
space:
mode:
authorEric Chapweske <eric@chapweske.com>2009-10-17 12:37:15 -0500
committerJoshua Peek <josh@joshpeek.com>2009-10-17 12:37:15 -0500
commitf936a1f100e75082081e782e5cceb272885c2df7 (patch)
tree6c5091faa38f15765b3be153141b81d693b02d18 /activerecord/lib/active_record/types/time_with_zone.rb
parente13d232150921cdf0ec3d713caefa628d235152e (diff)
downloadrails-f936a1f100e75082081e782e5cceb272885c2df7.tar.gz
rails-f936a1f100e75082081e782e5cceb272885c2df7.tar.bz2
rails-f936a1f100e75082081e782e5cceb272885c2df7.zip
Refactoring attributes/types [#3348 state:resolved]
Signed-off-by: Joshua Peek <josh@joshpeek.com>
Diffstat (limited to 'activerecord/lib/active_record/types/time_with_zone.rb')
-rw-r--r--activerecord/lib/active_record/types/time_with_zone.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/types/time_with_zone.rb b/activerecord/lib/active_record/types/time_with_zone.rb
new file mode 100644
index 0000000000..3a8b9292f9
--- /dev/null
+++ b/activerecord/lib/active_record/types/time_with_zone.rb
@@ -0,0 +1,20 @@
+module ActiveRecord
+ module Type
+ class TimeWithZone < Object
+
+ def cast(time)
+ time = super(time)
+ time.acts_like?(:time) ? time.in_time_zone : time
+ end
+
+ def precast(time)
+ unless time.acts_like?(:time)
+ time = time.is_a?(String) ? ::Time.zone.parse(time) : time.to_time rescue time
+ end
+ time = time.in_time_zone rescue nil if time
+ super(time)
+ end
+
+ end
+ end
+end