aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-02-05 20:31:02 +0900
committerkennyj <kennyj@gmail.com>2012-02-06 00:20:16 +0900
commit9abdabf18588068ef979499dbfd4a8d436a45dd5 (patch)
tree9a9732657217038eed71dd1c99a5ad5f83b556af /activesupport
parentb0d05f4bee6960b70d0ef46f44390a796f19c9d5 (diff)
downloadrails-9abdabf18588068ef979499dbfd4a8d436a45dd5.tar.gz
rails-9abdabf18588068ef979499dbfd4a8d436a45dd5.tar.bz2
rails-9abdabf18588068ef979499dbfd4a8d436a45dd5.zip
Optional start_day argument for Time#all_week.
Closes #4883
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb6
-rw-r--r--activesupport/test/core_ext/time_ext_test.rb1
2 files changed, 4 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 5e433f5dd9..4f300329f5 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -273,9 +273,9 @@ class Time
beginning_of_day..end_of_day
end
- # Returns a Range representing the whole week of the current time.
- def all_week
- beginning_of_week..end_of_week
+ # Returns a Range representing the whole week of the current time. Week starts on start_day (default is :monday, i.e. end of Sunday).
+ def all_week(start_day = :monday)
+ beginning_of_week(start_day)..end_of_week(start_day)
end
# Returns a Range representing the whole month of the current time.
diff --git a/activesupport/test/core_ext/time_ext_test.rb b/activesupport/test/core_ext/time_ext_test.rb
index d45ab70f53..eda8066579 100644
--- a/activesupport/test/core_ext/time_ext_test.rb
+++ b/activesupport/test/core_ext/time_ext_test.rb
@@ -807,6 +807,7 @@ class TimeExtCalculationsTest < ActiveSupport::TestCase
def test_all_week
assert_equal Time.local(2011,6,6,0,0,0)..Time.local(2011,6,12,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_week
+ assert_equal Time.local(2011,6,5,0,0,0)..Time.local(2011,6,11,23,59,59,999999.999), Time.local(2011,6,7,10,10,10).all_week(:sunday)
end
def test_all_month