aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/core_ext/time
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-02-26 00:46:18 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-02-26 00:46:18 +0000
commite57bd727df9d1e259b4ea9f2ab84595fe5a85b07 (patch)
tree1e3a9fea8f985b7ad28ffbb7971c0dde081e386a /activesupport/lib/active_support/core_ext/time
parent3d0a9ff437c5e06f8baa6e9a40049411dda8bd0e (diff)
downloadrails-e57bd727df9d1e259b4ea9f2ab84595fe5a85b07.tar.gz
rails-e57bd727df9d1e259b4ea9f2ab84595fe5a85b07.tar.bz2
rails-e57bd727df9d1e259b4ea9f2ab84595fe5a85b07.zip
Added Time#beginning_of_quarter (closes #3607) [cohen.jeff@gmail.com]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3659 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'activesupport/lib/active_support/core_ext/time')
-rw-r--r--activesupport/lib/active_support/core_ext/time/calculations.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb
index 43424df8f4..6a80762a62 100644
--- a/activesupport/lib/active_support/core_ext/time/calculations.rb
+++ b/activesupport/lib/active_support/core_ext/time/calculations.rb
@@ -152,6 +152,12 @@ module ActiveSupport #:nodoc:
change(:mday => last_day,:hour => 0, :min => 0, :sec => 0, :usec => 0)
end
alias :at_end_of_month :end_of_month
+
+ # Returns a new Time representing the start of the quarter (1st of january, april, july, october, 0:00)
+ def beginning_of_quarter
+ beginning_of_month.change(:month => [10, 7, 4, 1].detect { |m| m <= self.month })
+ end
+ alias :at_beginning_of_quarter :beginning_of_quarter
# Returns a new Time representing the start of the year (1st of january, 0:00)
def beginning_of_year