Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrap time ranges with timezones, closes #8807
(cherry picked from commit e2e5136) (cherry picked from commit dcdde7d) Backport of #6183, original issue was #6179 Conflicts: activesupport/lib/active_support/core_ext/time/calculations.rb activesupport/test/core_ext/time_ext_test Signed-off-by: Andrew White <andyw@pixeltrix.co.uk>
- Loading branch information
Showing
5 changed files
with
67 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -217,7 +217,7 @@ def beginning_of_day | |
|
||
# Returns a new Time representing the end of the day, 23:59:59.999999 (.999999999 in ruby1.9) | ||
def end_of_day | ||
change(:hour => 23, :min => 59, :sec => 59, :usec => 999999.999) | ||
change(:hour => 23, :min => 59, :sec => 59, :usec => Rational(999999999, 1000)) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
pixeltrix
Contributor
|
||
end | ||
|
||
# Returns a new Time representing the start of the hour (x:00) | ||
|
@@ -228,11 +228,7 @@ def beginning_of_hour | |
|
||
# Returns a new Time representing the end of the hour, x:59:59.999999 (.999999999 in ruby1.9) | ||
def end_of_hour | ||
change( | ||
:min => 59, | ||
:sec => 59, | ||
:usec => 999999.999 | ||
) | ||
change(:min => 59, :sec => 59, :usec => Rational(999999999, 1000)) | ||
end | ||
|
||
# Returns a new Time representing the start of the month (1st of the month, 0:00) | ||
|
@@ -246,7 +242,7 @@ def beginning_of_month | |
def end_of_month | ||
#self - ((self.mday-1).days + self.seconds_since_midnight) | ||
last_day = ::Time.days_in_month(month, year) | ||
change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999) | ||
change(:day => last_day, :hour => 23, :min => 59, :sec => 59, :usec => Rational(999999999, 1000)) | ||
end | ||
alias :at_end_of_month :end_of_month | ||
|
||
|
@@ -270,7 +266,7 @@ def beginning_of_year | |
|
||
# Returns a new Time representing the end of the year (end of the 31st of december) | ||
def end_of_year | ||
change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59, :usec => 999999.999) | ||
change(:month => 12, :day => 31, :hour => 23, :min => 59, :sec => 59, :usec => Rational(999999999, 1000)) | ||
end | ||
alias :at_end_of_year :end_of_year | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This rational object is constructed in every call, and in several methods. Would it make sense to give it a meaningful name and extract it to a constant?