mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Fixed Time#at_beginning_of_week returned the next Monday instead of the previous one when called on a Sunday #1403 [jean.helou@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1431 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Fixed Time#at_beginning_of_week returned the next Monday instead of the previous one when called on a Sunday #1403 [jean.helou@gmail.com]
|
||||
|
||||
* Increased the speed of indifferent hash access by using Hash#default. #1436 [Nicholas Seckar]
|
||||
|
||||
* Added that " " is now also blank? (using strip if available)
|
||||
|
||||
@@ -87,7 +87,8 @@ module ActiveSupport #:nodoc:
|
||||
|
||||
# Returns a new Time representing the "start" of this week (Monday, 0:00)
|
||||
def beginning_of_week
|
||||
(self - self.wday.days).midnight + 1.day
|
||||
days_to_monday = self.wday!=0 ? self.wday-1 : 6
|
||||
(self - days_to_monday.days).midnight
|
||||
end
|
||||
alias :monday :beginning_of_week
|
||||
alias :at_beginning_of_week :beginning_of_week
|
||||
|
||||
@@ -13,6 +13,13 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
|
||||
|
||||
def test_begining_of_week
|
||||
assert_equal Time.local(2005,1,31), Time.local(2005,2,4,10,10,10).beginning_of_week
|
||||
assert_equal Time.local(2005,11,28), Time.local(2005,11,28,0,0,0).beginning_of_week #monday
|
||||
assert_equal Time.local(2005,11,28), Time.local(2005,11,29,0,0,0).beginning_of_week #tuesday
|
||||
assert_equal Time.local(2005,11,28), Time.local(2005,11,30,0,0,0).beginning_of_week #wednesday
|
||||
assert_equal Time.local(2005,11,28), Time.local(2005,12,01,0,0,0).beginning_of_week #thursday
|
||||
assert_equal Time.local(2005,11,28), Time.local(2005,12,02,0,0,0).beginning_of_week #friday
|
||||
assert_equal Time.local(2005,11,28), Time.local(2005,12,03,0,0,0).beginning_of_week #saturday
|
||||
assert_equal Time.local(2005,11,28), Time.local(2005,12,04,0,0,0).beginning_of_week #sunday
|
||||
end
|
||||
|
||||
def test_beginning_of_day
|
||||
|
||||
Reference in New Issue
Block a user