From e57bd727df9d1e259b4ea9f2ab84595fe5a85b07 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 26 Feb 2006 00:46:18 +0000 Subject: 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 --- activesupport/lib/active_support/core_ext/time/calculations.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'activesupport/lib/active_support/core_ext/time') 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 -- cgit v1.2.3