aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorGeoff Buesing <gbuesing@gmail.com>2008-04-02 06:56:44 +0000
committerGeoff Buesing <gbuesing@gmail.com>2008-04-02 06:56:44 +0000
commitf4dc83497612bbd458213fccd161e1a38939ad5f (patch)
tree093617bbe3cdf1b2338c88a23862ff556fd73198 /activesupport/lib
parentc4ccca1f847abedd9ae3863996552282e40d42ba (diff)
downloadrails-f4dc83497612bbd458213fccd161e1a38939ad5f.tar.gz
rails-f4dc83497612bbd458213fccd161e1a38939ad5f.tar.bz2
rails-f4dc83497612bbd458213fccd161e1a38939ad5f.zip
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
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/time_with_zone.rb25
1 files changed, 7 insertions, 18 deletions
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