diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2013-08-04 07:11:35 +0100 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2013-08-04 07:11:35 +0100 |
commit | 72293857c7e757efe1d79b1b51b9d15a4ac99fb6 (patch) | |
tree | f2fc040a8e45b559fe2b751ebba2683ee01dfe16 | |
parent | dfcef831b5cc612495323114dd1bbb9366f05128 (diff) | |
download | rails-72293857c7e757efe1d79b1b51b9d15a4ac99fb6.tar.gz rails-72293857c7e757efe1d79b1b51b9d15a4ac99fb6.tar.bz2 rails-72293857c7e757efe1d79b1b51b9d15a4ac99fb6.zip |
No need to use blocks here
-rw-r--r-- | activesupport/lib/active_support/core_ext/date_and_time/calculations.rb | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb index 0d14cba7cc..c869a0e210 100644 --- a/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/date_and_time/calculations.rb @@ -78,7 +78,7 @@ module DateAndTime # Returns a new date/time at the start of the month. # DateTime objects will have a time set to 0:00. def beginning_of_month - first_hour{ change(:day => 1) } + first_hour(change(:day => 1)) end alias :at_beginning_of_month :beginning_of_month @@ -113,7 +113,7 @@ module DateAndTime # which is determined by +Date.beginning_of_week+ or +config.beginning_of_week+ # when set. +DateTime+ objects have their time set to 0:00. def next_week(given_day_in_next_week = Date.beginning_of_week) - first_hour{ weeks_since(1).beginning_of_week.days_since(days_span(given_day_in_next_week)) } + first_hour(weeks_since(1).beginning_of_week.days_since(days_span(given_day_in_next_week))) end # Short-hand for months_since(1). @@ -136,7 +136,7 @@ module DateAndTime # +Date.beginning_of_week+ or +config.beginning_of_week+ when set. # DateTime objects have their time set to 0:00. def prev_week(start_day = Date.beginning_of_week) - first_hour{ weeks_ago(1).beginning_of_week.days_since(days_span(start_day)) } + first_hour(weeks_ago(1).beginning_of_week.days_since(days_span(start_day))) end alias_method :last_week, :prev_week @@ -188,7 +188,7 @@ module DateAndTime # +Date.beginning_of_week+ or +config.beginning_of_week+ when set. # DateTime objects have their time set to 23:59:59. def end_of_week(start_day = Date.beginning_of_week) - last_hour{ days_since(6 - days_to_week_start(start_day)) } + last_hour(days_since(6 - days_to_week_start(start_day))) end alias :at_end_of_week :end_of_week @@ -202,7 +202,7 @@ module DateAndTime # DateTime objects will have a time set to 23:59:59. def end_of_month last_day = ::Time.days_in_month(month, year) - last_hour{ days_since(last_day - day) } + last_hour(days_since(last_day - day)) end alias :at_end_of_month :end_of_month @@ -215,14 +215,12 @@ module DateAndTime private - def first_hour - result = yield - acts_like?(:time) ? result.change(:hour => 0) : result + def first_hour(date_or_time) + date_or_time.acts_like?(:time) ? date_or_time.beginning_of_day : date_or_time end - def last_hour - result = yield - acts_like?(:time) ? result.end_of_day : result + def last_hour(date_or_time) + date_or_time.acts_like?(:time) ? date_or_time.end_of_day : date_or_time end def days_span(day) |