diff options
author | Tom Lea <commit@tomlea.co.uk> | 2008-09-04 17:38:53 +0100 |
---|---|---|
committer | gbuesing <gbuesing@gmail.com> | 2008-10-13 20:00:09 -0500 |
commit | 27c70ff386e76ed0af41b53f2ba8cdb09bc94ace (patch) | |
tree | a6de54ec663f6822323023982fdf7a12714b68a0 /activesupport/lib | |
parent | 1abdc8752d7fbc0733da763e751a2671db42961a (diff) | |
download | rails-27c70ff386e76ed0af41b53f2ba8cdb09bc94ace.tar.gz rails-27c70ff386e76ed0af41b53f2ba8cdb09bc94ace.tar.bz2 rails-27c70ff386e76ed0af41b53f2ba8cdb09bc94ace.zip |
Time#advance recognizes fractional days and weeks [#970 state:resolved]
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 3cc6d59907..00078de692 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -98,6 +98,16 @@ module ActiveSupport #:nodoc: # <tt>:months</tt>, <tt>:weeks</tt>, <tt>:days</tt>, <tt>:hours</tt>, # <tt>:minutes</tt>, <tt>:seconds</tt>. def advance(options) + unless options[:weeks].nil? + options[:weeks], partial_weeks = options[:weeks].divmod(1) + options[:days] = (options[:days] || 0) + 7 * partial_weeks + end + + unless options[:days].nil? + options[:days], partial_days = options[:days].divmod(1) + options[:hours] = (options[:hours] || 0) + 24 * partial_days + end + d = to_date.advance(options) time_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 |