diff options
6 files changed, 18 insertions, 16 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb index a7551d9c64..02ae57b4a6 100644 --- a/activesupport/lib/active_support/core_ext/date/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date/calculations.rb @@ -28,7 +28,7 @@ class Date # Returns week start day symbol (e.g. :monday), or raises an ArgumentError for invalid day symbol. def find_beginning_of_week!(week_start) - raise ArgumentError, "Invalid beginning of week: #{week_start}" unless ::Date::DAYS_INTO_WEEK.keys.include?(week_start) + raise ArgumentError, "Invalid beginning of week: #{week_start}" unless ::Date::DAYS_INTO_WEEK.key?(week_start) week_start end diff --git a/activesupport/lib/active_support/core_ext/object.rb b/activesupport/lib/active_support/core_ext/object.rb index ec2157221f..ab01d7787a 100644 --- a/activesupport/lib/active_support/core_ext/object.rb +++ b/activesupport/lib/active_support/core_ext/object.rb @@ -1,14 +1,11 @@ require 'active_support/core_ext/object/acts_like' require 'active_support/core_ext/object/blank' -require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/object/deep_dup' -require 'active_support/core_ext/object/try' +require 'active_support/core_ext/object/duplicable' require 'active_support/core_ext/object/inclusion' - -require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/instance_variables' - require 'active_support/core_ext/object/to_json' require 'active_support/core_ext/object/to_param' require 'active_support/core_ext/object/to_query' +require 'active_support/core_ext/object/try' require 'active_support/core_ext/object/with_options' diff --git a/activesupport/lib/active_support/core_ext/object/conversions.rb b/activesupport/lib/active_support/core_ext/object/conversions.rb deleted file mode 100644 index 540f7aadb0..0000000000 --- a/activesupport/lib/active_support/core_ext/object/conversions.rb +++ /dev/null @@ -1,4 +0,0 @@ -require 'active_support/core_ext/object/to_param' -require 'active_support/core_ext/object/to_query' -require 'active_support/core_ext/array/conversions' -require 'active_support/core_ext/hash/conversions' diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 9dfa2cbf11..0b33a63460 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -1,7 +1,6 @@ require 'abstract_unit' require 'active_support/core_ext/array' require 'active_support/core_ext/big_decimal' -require 'active_support/core_ext/object/conversions' require 'active_support/core_ext' # FIXME: pulling in all to_xml extensions require 'active_support/hash_with_indifferent_access' diff --git a/activesupport/test/core_ext/hash_ext_test.rb b/activesupport/test/core_ext/hash_ext_test.rb index 01934dd2c3..53ea2aad16 100644 --- a/activesupport/test/core_ext/hash_ext_test.rb +++ b/activesupport/test/core_ext/hash_ext_test.rb @@ -3,7 +3,6 @@ require 'active_support/core_ext/hash' require 'bigdecimal' require 'active_support/core_ext/string/access' require 'active_support/ordered_hash' -require 'active_support/core_ext/object/conversions' require 'active_support/core_ext/object/deep_dup' require 'active_support/inflections' diff --git a/guides/source/active_support_core_extensions.md b/guides/source/active_support_core_extensions.md index 2a84242b9c..645498437d 100644 --- a/guides/source/active_support_core_extensions.md +++ b/guides/source/active_support_core_extensions.md @@ -3097,7 +3097,8 @@ Time.local(2000, 11, 31).next_quarter # => Wed, 28 Feb 2001 The methods `beginning_of_week` and `end_of_week` return the dates for the beginning and end of the week, respectively. Weeks are assumed to start on -Monday, but that can be changed passing an argument. +Monday, but that can be changed passing an argument, setting thread local +`Date.beginning_of_week` or `config.beginning_of_week`. ```ruby d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 @@ -3111,18 +3112,24 @@ d.end_of_week(:sunday) # => Sat, 08 May 2010 ##### `monday`, `sunday` -The methods `monday` and `sunday` return the dates for the beginning and -end of the week, respectively. Weeks are assumed to start on Monday. +The methods `monday` and `sunday` return the dates for the previous Monday and +next Sunday, respectively. ```ruby d = Date.new(2010, 5, 8) # => Sat, 08 May 2010 d.monday # => Mon, 03 May 2010 d.sunday # => Sun, 09 May 2010 + +d = Date.new(2012, 9, 10) # => Mon, 10 Sep 2012 +d.monday # => Mon, 10 Sep 2012 + +d = Date.new(2012, 9, 16) # => Sun, 16 Sep 2012 +d.sunday # => Sun, 16 Sep 2012 ``` ##### `prev_week`, `next_week` -The method `next_week` receives a symbol with a day name in English (in lowercase, default is `:monday`) and it returns the date corresponding to that day: +The method `next_week` receives a symbol with a day name in English (default is the thread local `Date.beginning_of_week`, or `config.beginning_of_week`, or `:monday`) and it returns the date corresponding to that day. ```ruby d = Date.new(2010, 5, 9) # => Sun, 09 May 2010 @@ -3140,6 +3147,8 @@ d.prev_week(:friday) # => Fri, 30 Apr 2010 `prev_week` is aliased to `last_week`. +Both `next_week` and `prev_week` work as expected when `Date.beginning_of_week` or `config.beginning_of_week` are set. + ##### `beginning_of_month`, `end_of_month` The methods `beginning_of_month` and `end_of_month` return the dates for the beginning and end of the month: @@ -3617,6 +3626,8 @@ now = Time.current # => Mon, 09 Aug 2010 23:20:05 UTC +00:00 now.all_week # => Mon, 09 Aug 2010 00:00:00 UTC +00:00..Sun, 15 Aug 2010 23:59:59 UTC +00:00 +now.all_week(:sunday) +# => Sun, 16 Sep 2012 00:00:00 UTC +00:00..Sat, 22 Sep 2012 23:59:59 UTC +00:00 now.all_month # => Sat, 01 Aug 2010 00:00:00 UTC +00:00..Tue, 31 Aug 2010 23:59:59 UTC +00:00 now.all_quarter |