From d39d878d2b250636256ecf54473d365ffb62eb6d Mon Sep 17 00:00:00 2001 From: Vasiliy Ermolovich Date: Sun, 6 May 2012 23:33:12 +0300 Subject: Wrap time ranges with timezones, closes #8807 (cherry picked from commit e2e513621d732abb8efff9120bd9a444836720d6) (cherry picked from commit dcdde7da481e11660634278a8004175a1ce20f39) 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 --- .../lib/active_support/core_ext/time/calculations.rb | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'activesupport/lib/active_support/core_ext') diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index 34d4d88bd3..9146d82bd8 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -217,7 +217,7 @@ class Time # 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)) end # Returns a new Time representing the start of the hour (x:00) @@ -228,11 +228,7 @@ class Time # 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 @@ class Time 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 @@ class Time # 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 -- cgit v1.2.3