Ticket #3607: beginning_of_quarter.diff
| File beginning_of_quarter.diff, 1.9 kB (added by cohen.jeff@gmail.com, 4 years ago) |
|---|
-
test/core_ext/time_ext_test.rb
old new 29 29 def test_beginning_of_month 30 30 assert_equal Time.local(2005,2,1,0,0,0), Time.local(2005,2,22,10,10,10).beginning_of_month 31 31 end 32 33 def test_beginning_of_quarter 34 assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,2,15,10,10,10).beginning_of_quarter 35 assert_equal Time.local(2005,1,1,0,0,0), Time.local(2005,1,1,0,0,0).beginning_of_quarter 36 assert_equal Time.local(2005,10,1,0,0,0), Time.local(2005,12,31,10,10,10).beginning_of_quarter 37 assert_equal Time.local(2005,4,1,0,0,0), Time.local(2005,6,30,23,59,59).beginning_of_quarter 38 end 32 39 33 40 def test_end_of_month 34 41 assert_equal Time.local(2005,3,31,0,0,0), Time.local(2005,3,20,10,10,10).end_of_month -
lib/active_support/core_ext/time/calculations.rb
old new 151 151 last_day = ::Time.days_in_month( self.month, self.year ) 152 152 change(:mday => last_day,:hour => 0, :min => 0, :sec => 0, :usec => 0) 153 153 end 154 alias :at_end_of_month :end_of_month 154 alias :at_end_of_month :end_of_month 155 156 # Returns a new Time representing the start of the quarter (1st of january, april, july, october, 0:00) 157 def beginning_of_quarter 158 beginning_of_month.change(:month => [10, 7, 4, 1].detect { |m| m <= self.month }) 159 end 160 alias :at_beginning_of_quarter :beginning_of_quarter 155 161 156 162 # Returns a new Time representing the start of the year (1st of january, 0:00) 157 163 def beginning_of_year