aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/types/time_with_zone.rb
diff options
context:
space:
mode:
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