From f4dc83497612bbd458213fccd161e1a38939ad5f Mon Sep 17 00:00:00 2001 From: Geoff Buesing Date: Wed, 2 Apr 2008 06:56:44 +0000 Subject: TimeWithZone#method_missing: send to utc to advance with dst correctness, otherwise send to time. Adding tests for time calculations methods git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@9208 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activesupport/lib/active_support/time_with_zone.rb | 25 ++++++---------------- 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'activesupport/lib/active_support') diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index b3e83b57e1..b91480cd48 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -144,25 +144,10 @@ module ActiveSupport end end - %w(asctime day hour min mon sec wday yday year to_date).each do |name| - define_method(name) do - time.__send__(name) - end - end - alias_method :ctime, :asctime - alias_method :mday, :day - alias_method :month, :mon - def usec time.respond_to?(:usec) ? time.usec : 0 end - %w(sunday? monday? tuesday? wednesday? thursday? friday? saturday?).each do |name| - define_method(name) do - time.__send__(name) - end - end unless RUBY_VERSION < '1.9' - def to_a [time.sec, time.min, time.hour, time.day, time.mon, time.year, time.wday, time.yday, dst?, zone] end @@ -219,9 +204,13 @@ module ActiveSupport # Send the missing method to time instance, and wrap result in a new TimeWithZone with the existing time_zone def method_missing(sym, *args, &block) - result = utc.__send__(sym, *args, &block) - result = result.in_time_zone(time_zone) if result.acts_like?(:time) - result + if %w(+ - since ago advance).include?(sym.to_s) + result = utc.__send__(sym, *args, &block) + result.acts_like?(:time) ? result.in_time_zone(time_zone) : result + else + result = time.__send__(sym, *args, &block) + result.acts_like?(:time) ? self.class.new(nil, time_zone, result) : result + end end private -- cgit v1.2.3