Skip to content

Commit

Permalink
Fixed Date#end_of_quarter to not blow up on May 31st [#289 state:reso…
Browse files Browse the repository at this point in the history
…lved] (Danger)
  • Loading branch information
dhh committed Jun 3, 2008
1 parent e7a305f commit 64fea9c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
5 changes: 5 additions & 0 deletions activesupport/CHANGELOG
@@ -1,3 +1,8 @@
*Edge*

* Fixed Date#end_of_quarter to not blow up on May 31st [#289 state:resolved] (Danger)


*2.1.0 (May 31st, 2008)*

* TimeZone#to_s shows offset as GMT instead of UTC, because GMT will be more familiar to end users (see time zone selects used by Windows OS, google.com and yahoo.com.) Reverts [8370] [Geoff Buesing]
Expand Down
Expand Up @@ -184,7 +184,7 @@ def beginning_of_quarter

# Returns a new Date/DateTime representing the end of the quarter (last day of march, june, september, december; DateTime objects will have time set to 23:59:59)
def end_of_quarter
change(:month => [3, 6, 9, 12].detect { |m| m >= self.month }).end_of_month
beginning_of_month.change(:month => [3, 6, 9, 12].detect { |m| m >= self.month }).end_of_month
end
alias :at_end_of_quarter :end_of_quarter

Expand Down
1 change: 1 addition & 0 deletions activesupport/test/core_ext/date_ext_test.rb
Expand Up @@ -76,6 +76,7 @@ def test_end_of_quarter
assert_equal Date.new(2008,3,31), Date.new(2008,3,31).end_of_quarter
assert_equal Date.new(2008,12,31), Date.new(2008,10,8).end_of_quarter
assert_equal Date.new(2008,6,30), Date.new(2008,4,14).end_of_quarter
assert_equal Date.new(2008,6,30), Date.new(2008,5,31).end_of_quarter
assert_equal Date.new(2008,9,30), Date.new(2008,8,21).end_of_quarter
end

Expand Down

1 comment on commit 64fea9c

@carlosbrando
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Time#end_of_quarter have the same problem.

> > Date.new(2008, 5, 31).to_time.end_of_quarter
> > => Thu Jul 31 23:59:59 -0300 2008

It’s wrong!

Please sign in to comment.