aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-10-26 13:07:22 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-10-26 13:07:22 +0000
commitfabf34848eda7656f7a7f79647167e0fdd16f682 (patch)
tree6736de2f1a4d68bfe386e99ce4ebeca1109e9e6f /activesupport/lib
parenta8eea0b04b2989bd054d7c852d636f1cc5494957 (diff)
downloadrails-fabf34848eda7656f7a7f79647167e0fdd16f682.tar.gz
rails-fabf34848eda7656f7a7f79647167e0fdd16f682.tar.bz2
rails-fabf34848eda7656f7a7f79647167e0fdd16f682.zip
Added Time#end_of_month to accompany Time#beginning_of_month (closes #2514) [Jens-Christian Fischer]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2745 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb8
1 files changed, 8 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 85cd318a22..43424df8f4 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -145,6 +145,14 @@ module ActiveSupport #:nodoc:
end
alias :at_beginning_of_month :beginning_of_month
+ # Returns a new Time representing the end of the month (last day of the month, 0:00)
+ def end_of_month
+ #self - ((self.mday-1).days + self.seconds_since_midnight)
+ last_day = ::Time.days_in_month( self.month, self.year )
+ change(:mday => last_day,:hour => 0, :min => 0, :sec => 0, :usec => 0)
+ end
+ alias :at_end_of_month :end_of_month
+
# Returns a new Time representing the start of the year (1st of january, 0:00)
def beginning_of_year
change(:month => 1,:mday => 1,:hour => 0, :min => 0, :sec => 0, :usec => 0)