mirror of
https://github.com/github/rails.git
synced 2026-01-31 01:08:19 -05:00
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
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Added Time#beginning_of_quarter #3607 [cohen.jeff@gmail.com]
|
||||
|
||||
* Fix Object.subclasses_of to only return currently defined objects [Jonathan Viney <jonathan@bluewire.net.nz>]
|
||||
|
||||
* Fix constantize to properly handle names beginning with '::'. [Nicholas Seckar]
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -30,6 +30,13 @@ class TimeExtCalculationsTest < Test::Unit::TestCase
|
||||
assert_equal Time.local(2005,2,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_month
|
||||
end
|
||||
|
||||
def test_beginning_of_quarter
|
||||
assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,15,10,10,10).beginning_of_quarter
|
||||
assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,1,1,0,0,0).beginning_of_quarter
|
||||
assert_equal Time.local(2005,10,1,0,0,0), Time.local(2005,12,31,10,10,10).beginning_of_quarter
|
||||
assert_equal Time.local(2005,4,1,0,0,0), Time.local(2005,6,30,23,59,59).beginning_of_quarter
|
||||
end
|
||||
|
||||
def test_end_of_month
|
||||
assert_equal Time.local(2005,3,31,0,0,0), Time.local(2005,3,20,10,10,10).end_of_month
|
||||
assert_equal Time.local(2005,2,28,0,0,0), Time.local(2005,2,20,10,10,10).end_of_month
|
||||
|
||||
Reference in New Issue
Block a user