diff options
author | Vasiliy Ermolovich + Sergey Nartimov <younash@gmail.com> | 2012-05-18 13:07:52 +0300 |
---|---|---|
committer | Vasiliy Ermolovich <younash@gmail.com> | 2012-05-18 13:07:52 +0300 |
commit | dcdde7da481e11660634278a8004175a1ce20f39 (patch) | |
tree | c30f862c6fe10403152ffe0aa89ccc79a85ba005 /activesupport/lib | |
parent | e2e513621d732abb8efff9120bd9a444836720d6 (diff) | |
download | rails-dcdde7da481e11660634278a8004175a1ce20f39.tar.gz rails-dcdde7da481e11660634278a8004175a1ce20f39.tar.bz2 rails-dcdde7da481e11660634278a8004175a1ce20f39.zip |
respect nsec in TimeWithZone
when we pass fractional usec to Time methods we should use Rational
instead of Float because of accuracy problem
Time.local(2011,6,12,23,59,59,999999.999).nsec
# => 999999998
Time.local(2011,6,12,23,59,59,Rational(999999999, 1000)).nsec
# => 999999999
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/core_ext/time/calculations.rb | 8 | ||||
-rw-r--r-- | activesupport/lib/active_support/time_with_zone.rb | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/core_ext/time/calculations.rb b/activesupport/lib/active_support/core_ext/time/calculations.rb index a0f610d60c..92b8417150 100644 --- a/activesupport/lib/active_support/core_ext/time/calculations.rb +++ b/activesupport/lib/active_support/core_ext/time/calculations.rb @@ -253,7 +253,7 @@ class Time :hour => 23, :min => 59, :sec => 59, - :usec => 999999.999 + :usec => Rational(999999999, 1000) ) end @@ -268,7 +268,7 @@ class Time change( :min => 59, :sec => 59, - :usec => 999999.999 + :usec => Rational(999999999, 1000) ) end @@ -288,7 +288,7 @@ class Time :hour => 23, :min => 59, :sec => 59, - :usec => 999999.999 + :usec => Rational(999999999, 1000) ) end alias :at_end_of_month :end_of_month @@ -321,7 +321,7 @@ class Time :hour => 23, :min => 59, :sec => 59, - :usec => 999999.999 + :usec => Rational(999999999, 1000) ) end alias :at_end_of_year :end_of_year diff --git a/activesupport/lib/active_support/time_with_zone.rb b/activesupport/lib/active_support/time_with_zone.rb index 75fbd98b05..7825283651 100644 --- a/activesupport/lib/active_support/time_with_zone.rb +++ b/activesupport/lib/active_support/time_with_zone.rb @@ -337,7 +337,7 @@ module ActiveSupport end def transfer_time_values_to_utc_constructor(time) - ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:usec) ? time.usec : 0) + ::Time.utc_time(time.year, time.month, time.day, time.hour, time.min, time.sec, time.respond_to?(:nsec) ? Rational(time.nsec, 1000) : 0) end def duration_of_variable_length?(obj) |