aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-06-20 11:42:21 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-06-20 11:42:21 -0300
commit4f700edcc094406155785c693363801d0277792c (patch)
treebbe0186dc87c3039abd13d59c39f8eee8bba14b1 /activesupport/lib
parent265f13495fb326bd2e6a5bc9cae7e297e42893d0 (diff)
parent2773257ac64c82affae527436b08e6d627853c1d (diff)
downloadrails-4f700edcc094406155785c693363801d0277792c.tar.gz
rails-4f700edcc094406155785c693363801d0277792c.tar.bz2
rails-4f700edcc094406155785c693363801d0277792c.zip
Merge pull request #6402 from paranoiase/prev-and-next-quarter
Add prev_quarter and next_quarter methods in Time/Date/DateTime calculations. Similar to prev_month and next_month, it returns the date with the same day in the previous or next quarter: t = Time.local(2010, 5, 8) # => Sat, 08 May 2010 t.prev_quarter # => Mon, 08 Feb 2010 t.next_quarter # => Sun, 08 Aug 2010 Closes #6402
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/date/calculations.rb11
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb11
-rw-r--r--activesupport/lib/active_support/log_subscriber.rb1
-rw-r--r--activesupport/lib/active_support/testing/isolation.rb2
4 files changed, 24 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/date/calculations.rb b/activesupport/lib/active_support/core_ext/date/calculations.rb
index 8a7eb6bc6b..7fe4161fb4 100644
--- a/activesupport/lib/active_support/core_ext/date/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/date/calculations.rb
@@ -202,6 +202,17 @@ class Date
acts_like?(:time) ? result.change(:hour => 0) : result
end
+ # Short-hand for months_ago(3)
+ def prev_quarter
+ months_ago(3)
+ end
+ alias_method :last_quarter, :prev_quarter
+
+ # Short-hand for months_since(3)
+ def next_quarter
+ months_since(3)
+ end
+
# Returns a new Date/DateTime representing the start of the month (1st of the month; DateTime objects will have time set to 0:00)
def beginning_of_month
acts_like?(:time) ? change(:day => 1, :hour => 0) : change(:day => 1)
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 92b8417150..28c8b53b78 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -186,6 +186,17 @@ class Time
months_since(1)
end
+ # Short-hand for months_ago(3)
+ def prev_quarter
+ months_ago(3)
+ end
+ alias_method :last_quarter, :prev_quarter
+
+ # Short-hand for months_since(3)
+ def next_quarter
+ months_since(3)
+ end
+
# Returns number of days to start of this week, week starts on start_day (default is :monday).
def days_to_week_start(start_day = :monday)
start_day_number = DAYS_INTO_WEEK[start_day]
diff --git a/activesupport/lib/active_support/log_subscriber.rb b/activesupport/lib/active_support/log_subscriber.rb
index 720954625a..8c3921c423 100644
--- a/activesupport/lib/active_support/log_subscriber.rb
+++ b/activesupport/lib/active_support/log_subscriber.rb
@@ -111,6 +111,7 @@ module ActiveSupport
finished = Time.now
event = @event_stack.pop
event.end = finished
+ event.payload.merge!(payload)
method = name.split('.').first
begin
diff --git a/activesupport/lib/active_support/testing/isolation.rb b/activesupport/lib/active_support/testing/isolation.rb
index 43cb16aefa..50ec50ca52 100644
--- a/activesupport/lib/active_support/testing/isolation.rb
+++ b/activesupport/lib/active_support/testing/isolation.rb
@@ -39,7 +39,7 @@ module ActiveSupport
include Enumerable
# default to 2 cores
- CORES = ENV['TEST_CORES'] || 2
+ CORES = (ENV['TEST_CORES'] || 2).to_i
def initialize list
@list = list