diff options
author | Eric Chapweske <eric@chapweske.com> | 2009-10-17 12:37:15 -0500 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2009-10-17 12:37:15 -0500 |
commit | f936a1f100e75082081e782e5cceb272885c2df7 (patch) | |
tree | 6c5091faa38f15765b3be153141b81d693b02d18 /activerecord/lib/active_record/types/time_with_zone.rb | |
parent | e13d232150921cdf0ec3d713caefa628d235152e (diff) | |
download | rails-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.rb | 20 |
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 |