aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/date_time
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-10-13 21:44:48 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-10-13 21:44:48 +0000
commitc7dd2a1c11c4cf66eac1b6c00ded956b1c3d55f6 (patch)
treec0b67cf0106dfb07ace77017256d3613a22e5a9b /activesupport/lib/active_support/core_ext/date_time
parent003df72d007725ac19aaf95c406dfb36f38ccd43 (diff)
downloadrails-c7dd2a1c11c4cf66eac1b6c00ded956b1c3d55f6.tar.gz
rails-c7dd2a1c11c4cf66eac1b6c00ded956b1c3d55f6.tar.bz2
rails-c7dd2a1c11c4cf66eac1b6c00ded956b1c3d55f6.zip
Time and DateTime#advance accept :hours, :minutes, and :seconds options. Closes #9825.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7866 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/date_time')
-rw-r--r--activesupport/lib/active_support/core_ext/date_time/calculations.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
index 4ec75288ca..9cb7455dec 100644
--- a/activesupport/lib/active_support/core_ext/date_time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date_time/calculations.rb
@@ -28,10 +28,12 @@ module ActiveSupport #:nodoc:
end
# Uses Date to provide precise Time calculations for years, months, and days. The +options+ parameter takes a hash with
- # any of these keys: :months, :days, :years.
+ # any of these keys: :years, :months, :days, :hours, :minutes, :seconds.
def advance(options)
d = to_date.advance(options)
- change(options.merge(:year => d.year, :month => d.month, :day => d.day))
+ datetime_advanced_by_date = change(:year => d.year, :month => d.month, :day => d.day)
+ seconds_to_advance = (options[:seconds] || 0) + (options[:minutes] || 0) * 60 + (options[:hours] || 0) * 3600
+ seconds_to_advance == 0 ? datetime_advanced_by_date : datetime_advanced_by_date.since(seconds_to_advance)
end
# Returns a new DateTime representing the time a number of seconds ago