diff options
author | Geoff Buesing <gbuesing@gmail.com> | 2007-11-24 03:57:11 +0000 |
---|---|---|
committer | Geoff Buesing <gbuesing@gmail.com> | 2007-11-24 03:57:11 +0000 |
commit | d84846a636fbc180b3d6fcf52aa8559e1b7bb960 (patch) | |
tree | 5f7a074b5f146396011f273863d9ebc66c9e645b | |
parent | 96add62ecc46354de3522b00d52a8cfa7ff7bb92 (diff) | |
download | rails-d84846a636fbc180b3d6fcf52aa8559e1b7bb960.tar.gz rails-d84846a636fbc180b3d6fcf52aa8559e1b7bb960.tar.bz2 rails-d84846a636fbc180b3d6fcf52aa8559e1b7bb960.zip |
Change Time and DateTime #end_of_month to return last second of month instead of beginning of last day of month. Closes #10200
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8198 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
5 files changed, 10 insertions, 10 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index a46c53a4f1..37748850a6 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Change Time and DateTime #end_of_month to return last second of month instead of beginning of last day of month. Closes #10200 [Geoff Buesing] + * Speedup String#blank? [Jeremy Kemper, Koz] * Add documentation for Hash#diff. Closes #9306 [tarmo] diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index 61db7e0f12..b82f7be496 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -157,7 +157,7 @@ module ActiveSupport #:nodoc: # Returns a new Date/DateTime representing the end of the month (last day of the month; DateTime objects will have time set to 0:00) def end_of_month last_day = ::Time.days_in_month( self.month, self.year ) - self.acts_like?(:time) ? change(:day => last_day,:hour => 0, :min => 0, :sec => 0) : change(:day => last_day) + self.acts_like?(:time) ? change(:day => last_day, :hour => 23, :min => 59, :sec => 59) : change(:day => last_day) end alias :at_end_of_month :end_of_month diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 19ac8f5a36..e9f1011563 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -177,7 +177,7 @@ module ActiveSupport #:nodoc: def end_of_month #self - ((self.mday-1).days + self.seconds_since_midnight) last_day = ::Time.days_in_month( self.month, self.year ) - change(:day => last_day,:hour => 0, :min => 0, :sec => 0, :usec => 0) + change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => 0) end alias :at_end_of_month :end_of_month diff --git a/activesupport/test/core_ext/date_time_ext_test.rb b/activesupport/test/core_ext/date_time_ext_test.rb index 0f2c788926..54af69c0ca 100644 --- a/activesupport/test/core_ext/date_time_ext_test.rb +++ b/activesupport/test/core_ext/date_time_ext_test.rb @@ -78,10 +78,9 @@ class DateTimeExtCalculationsTest < Test::Unit::TestCase end def test_end_of_month - assert_equal DateTime.civil(2005,3,31,0,0,0), DateTime.civil(2005,3,20,10,10,10).end_of_month - assert_equal DateTime.civil(2005,2,28,0,0,0), DateTime.civil(2005,2,20,10,10,10).end_of_month - assert_equal DateTime.civil(2005,4,30,0,0,0), DateTime.civil(2005,4,20,10,10,10).end_of_month - + assert_equal DateTime.civil(2005,3,31,23,59,59), DateTime.civil(2005,3,20,10,10,10).end_of_month + assert_equal DateTime.civil(2005,2,28,23,59,59), DateTime.civil(2005,2,20,10,10,10).end_of_month + assert_equal DateTime.civil(2005,4,30,23,59,59), DateTime.civil(2005,4,20,10,10,10).end_of_month end def test_beginning_of_year diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb index 8ead0d7fe6..fb60892b69 100644 --- a/activesupport/test/core_ext/time_ext_test.rb +++ b/activesupport/test/core_ext/time_ext_test.rb @@ -84,10 +84,9 @@ class TimeExtCalculationsTest < Test::Unit::TestCase end def test_end_of_month - assert_equal Time.local(2005,3,31,0,0,0), Time.local(2005,3,20,10,10,10).end_of_month - assert_equal Time.local(2005,2,28,0,0,0), Time.local(2005,2,20,10,10,10).end_of_month - assert_equal Time.local(2005,4,30,0,0,0), Time.local(2005,4,20,10,10,10).end_of_month - + assert_equal Time.local(2005,3,31,23,59,59), Time.local(2005,3,20,10,10,10).end_of_month + assert_equal Time.local(2005,2,28,23,59,59), Time.local(2005,2,20,10,10,10).end_of_month + assert_equal Time.local(2005,4,30,23,59,59), Time.local(2005,4,20,10,10,10).end_of_month end def test_beginning_of_year |