Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Time advance nsec bug #4316

Merged
merged 1 commit into from

3 participants

Paweł Pierzchała Piotr Sarnacki Aaron Patterson
Paweł Pierzchała

#advance method of Time is not coping nsec fraction of time. It results in strange behaviour like:

Date.today.end_of_day != Date.today.end_of_day + 0.days

This pull requests fixes that.

Piotr Sarnacki
Collaborator

Could you please squash those commits into one?

Pawel Pierzchala Nano seconds fraction of time is copied properly in Time#advance
When day, month or year was passed, advance created a new time
ignoring previous nsec fraction. Now nsec is passed through
usec as a Rational number.
c766f3e
Paweł Pierzchała wrozka closed this
Paweł Pierzchała wrozka reopened this
Paweł Pierzchała

This is one commit now. Sorry for closing and reopening, I thought Github didn't pick up my changes.

Aaron Patterson tenderlove merged commit 1dbbe7b into from
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 5, 2012
  1. Nano seconds fraction of time is copied properly in Time#advance

    Pawel Pierzchala authored
    When day, month or year was passed, advance created a new time
    ignoring previous nsec fraction. Now nsec is passed through
    usec as a Rational number.
This page is out of date. Refresh to see the latest.
2  activesupport/lib/active_support/core_ext/time/calculations.rb
View
@@ -78,7 +78,7 @@ def change(options)
options[:hour] || hour,
options[:min] || (options[:hour] ? 0 : min),
options[:sec] || ((options[:hour] || options[:min]) ? 0 : sec),
- options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : usec)
+ options[:usec] || ((options[:hour] || options[:min] || options[:sec]) ? 0 : Rational(nsec, 1000))
)
end
5 activesupport/test/core_ext/time_ext_test.rb
View
@@ -491,6 +491,11 @@ def test_utc_advance
assert_equal Time.utc(2013,10,17,20,22,19), Time.utc(2005,2,28,15,15,10).advance(:years => 7, :months => 19, :weeks => 2, :days => 5, :hours => 5, :minutes => 7, :seconds => 9)
end
+ def test_advance_with_nsec
+ t = Time.at(0, Rational(108635108, 1000))
+ assert_equal t, t.advance(:months => 0)
+ end
+
def test_prev_week
with_env_tz 'US/Eastern' do
assert_equal Time.local(2005,2,21), Time.local(2005,3,1,15,15,10).prev_week
Something went wrong with that request. Please try again.