Permalink
Browse files

Change Time and DateTime #end_of_month to return last second of mont…

…h 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
  • Loading branch information...
1 parent 96add62 commit d84846a636fbc180b3d6fcf52aa8559e1b7bb960 @gbuesing gbuesing committed Nov 24, 2007
View
@@ -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]
@@ -157,7 +157,7 @@ def beginning_of_month
# 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
@@ -177,7 +177,7 @@ def beginning_of_month
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)
@donaldpiret

donaldpiret Apr 17, 2010

Should probably update the comment line for this, it should probably be "(last day of the month, 23:59)" instead of 0:00, no?

@fxn

fxn Apr 17, 2010

Owner

Where do you see 0:00? I read "end of the last day of the month", where "end of the last day" is defined by the method end_of_day.

@donaldpiret

donaldpiret Apr 17, 2010

Ah my bad, seems it's been fixed, the current version of the docs online http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Time/Calculations.html still have this wrong

@et

et Apr 18, 2010

Doesn't that API pertain to the last stable release of rails?

@fxn

fxn Apr 18, 2010

Owner

Yes, the API for master is in flux but can be checked out here http://edgeapi.rubyonrails.org

end
alias :at_end_of_month :end_of_month
@@ -78,10 +78,9 @@ def test_beginning_of_quarter
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
@@ -84,10 +84,9 @@ def test_beginning_of_quarter
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

0 comments on commit d84846a

Please sign in to comment.