aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/duration.rb
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-06-04 22:00:53 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-06-04 22:00:53 +0000
commit1b32a305df40829c650a5254441eaec491e9f086 (patch)
tree8656077640d3c3c1117259a6936d81b3440d1279 /activesupport/lib/active_support/duration.rb
parent4685fa0c20fbf3e78eaad94756e0f4a644447a10 (diff)
downloadrails-1b32a305df40829c650a5254441eaec491e9f086.tar.gz
rails-1b32a305df40829c650a5254441eaec491e9f086.tar.bz2
rails-1b32a305df40829c650a5254441eaec491e9f086.zip
Add Date#since, ago, beginning_of_day, and end_of_day. Date + seconds works now. Closes #8575.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6937 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/duration.rb')
-rw-r--r--activesupport/lib/active_support/duration.rb5
1 files changed, 1 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/duration.rb b/activesupport/lib/active_support/duration.rb
index 721bc18795..0d3016a690 100644
--- a/activesupport/lib/active_support/duration.rb
+++ b/activesupport/lib/active_support/duration.rb
@@ -65,15 +65,12 @@ module ActiveSupport
def sum(sign, time = ::Time.now) #:nodoc:
parts.inject(time) do |t,(type,number)|
- if t.acts_like?(:time)
+ if t.acts_like?(:time) || t.acts_like?(:date)
if type == :seconds
t.since(sign * number)
else
t.advance(type => sign * number)
end
- elsif t.acts_like?(:date)
- raise ArgumentError, "Adding seconds to a Date does not make sense" if type == :seconds
- t.advance(type => sign * number)
else
raise ArgumentError, "expected a time or date, got #{time.inspect}"
end