Skip to content

Commit

Permalink
Fixed Time#at_beginning_of_week returned the next Monday instead of t…
Browse files Browse the repository at this point in the history
…he 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
  • Loading branch information
dhh committed Jun 16, 2005
1 parent 4351419 commit a3659d5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions activesupport/CHANGELOG
@@ -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)
Expand Down
Expand Up @@ -87,7 +87,8 @@ def next_month

# 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
Expand Down
7 changes: 7 additions & 0 deletions activesupport/test/core_ext/time_ext_test.rb
Expand Up @@ -13,6 +13,13 @@ def test_seconds_since_midnight

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
Expand Down

0 comments on commit a3659d5

Please sign in to comment.