Last active
December 17, 2015 18:09
-
-
Save avit/5651344 to your computer and use it in GitHub Desktop.
Problem with different level of precision when adding ActiveSupport::Duration than Fixnum seconds. It looks like Rails 4.0 has a fix for this. The bug (illustrated here with plain ruby) depends on the system environment for the precision error to show up.
This file contains hidden or 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
require 'active_support/time' | |
require 'active_support/version' | |
t0 = Time.now # => 2013-05-26 01:14:51 +0000 | |
t1 = t0 + 86400 | |
t2 = t0 + 1.day | |
puts "Ruby %s / ActiveSupport %s" % [RUBY_VERSION, ActiveSupport::VERSION::STRING] | |
puts "Time + Fixnum nsec: %s" % t1.nsec # => 11111111 | |
puts "Time + AS::Duration nsec: %s" % t2.nsec # => 11111000 |
This file contains hidden or 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
t0 = Time.now | |
t1 = Time.local(t0.year, t0.month, t0.day, t0.hour, t0.min, t0.sec, t0.usec) | |
puts "Ruby %s" % RUBY_VERSION | |
puts "t0 == t1 is %s" % (t0 == t1) | |
puts "t0.nsec: %s" % t0.nsec | |
puts "t1.nsec: %s" % t1.nsec |
This file contains hidden or 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
[1] pry(#<RSpec::Core::ExampleGroup::Nested_4>)> (t0 + 86400).to_f | |
=> 1369615883.5234501 | |
[2] pry(#<RSpec::Core::ExampleGroup::Nested_4>)> (t0 + 1.day).to_f | |
=> 1369615883.5234501 |
This file contains hidden or 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
[30] pry(#<RSpec::Core::ExampleGroup::Nested_4>)> (t0 + 1.day).to_f | |
=> 1369615386.78719 | |
[31] pry(#<RSpec::Core::ExampleGroup::Nested_4>)> (t0 + 86400).to_f | |
=> 1369615386.7871902 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment