aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2007-05-31 16:37:09 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2007-05-31 16:37:09 +0000
commitff5c7c8c40ba24431ec5c9cdad23ddb9963d2c67 (patch)
treed290a2887c2e388894feb33f39ddfc4bf7459312 /activesupport/lib/active_support
parent1edd21bb0288526fc3a79ac1f960f4d5e6e6a2f5 (diff)
downloadrails-ff5c7c8c40ba24431ec5c9cdad23ddb9963d2c67.tar.gz
rails-ff5c7c8c40ba24431ec5c9cdad23ddb9963d2c67.tar.bz2
rails-ff5c7c8c40ba24431ec5c9cdad23ddb9963d2c67.zip
Added Date#change (like Time#change) [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@6910 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb14
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb2
2 files changed, 15 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index b104e5271a..c522256aea 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -38,6 +38,20 @@ module ActiveSupport #:nodoc:
d = d + options.delete(:days) if options[:days]
d
end
+
+ # Returns a new Date where one or more of the elements have been changed according to the +options+ parameter.
+ #
+ # Examples:
+ #
+ # Date.new(2007, 5, 12).change(:day => 1) # => Date.new(2007, 5, 12)
+ # Date.new(2007, 5, 12).change(:year => 2005, :month => 1) # => Date.new(2005, 1, 12)
+ def change(options)
+ ::Date.new(
+ options[:year] || self.year,
+ options[:month] || self.month,
+ options[:day] || options[:mday] || self.day # mday is deprecated
+ )
+ end
end
end
end
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 1fdfbcdf45..8f9c2ffa70 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -61,7 +61,7 @@ module ActiveSupport #:nodoc:
self.utc? ? :utc_time : :local_time,
options[:year] || self.year,
options[:month] || self.month,
- options[:mday] || self.mday,
+ options[:day] || options[:mday] || self.day, # mday is deprecated
options[:hour] || self.hour,
options[:min] || (options[:hour] ? 0 : self.min),
options[:sec] || ((options[:hour] || options[:min]) ? 0 : self.sec),