From: merch-redmine@... Date: 2020-05-29T20:20:52+00:00 Subject: [ruby-core:98579] [Ruby master Feature#16470] Issue with nanoseconds in Time#inspect Issue #16470 has been updated by jeremyevans0 (Jeremy Evans). Backport deleted (2.5: UNKNOWN, 2.6: UNKNOWN) ruby -v deleted (2.7) Tracker changed from Bug to Feature Even though this appears to be a bug, it's actually intentional behavior, introduced in commit:5208c431bef3240eb251f5da23723b324431a98e, and there are tests and specs for it. So changing this behavior would be a feature request. I think the behavior of displaying the rational is less useful, and the vast majority of Ruby programmers would want: ```ruby Time.utc(2007, 11, 1, 15, 25, 0, 123456.789).inspect # => "2007-11-01 15:25:00.123456789 UTC" ``` I've added a pull request to implement this: https://github.com/ruby/ruby/pull/3160 One disadvantage of the pull request's approach is that two Time objects that are not equal will have inspect output that is equal. An alternative approach that wouldn't have that issue would be to rationalize all float usecs given as input, as @Eregon mentioned, but that could possibly have implications beyond inspect. With that approach, you would still end up with weird inspect output if providing a rational such as `8483885939586761/68719476736000000r` as usec input. ---------------------------------------- Feature #16470: Issue with nanoseconds in Time#inspect https://bugs.ruby-lang.org/issues/16470#change-85890 * Author: andrykonchin (Andrew Konchin) * Status: Open * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- Recently in Ruby 2.7 nanoseconds were added to a string representation produced by the `Time#inspect` method. I encountered an issue when was working on new specs for the RubySpec project - nanoseconds are displaying like a Rational. Let's illustrate it with example: ```ruby t = Time.utc(2007, 11, 1, 15, 25, 0, 123456.789) t.inspect # => "2007-11-01 15:25:00 8483885939586761/68719476736000000 UTC" ``` But nanoseconds are stored correctly: ```ruby t.nsec # => 123456789 t.strftime("%N") # => "123456789" ``` So `123456789` is formatted as `8483885939586761/68719476736000000` which equals `0.12345678900000001`. I assume it isn't expected behavior and will be fixed. -- https://bugs.ruby-lang.org/ Unsubscribe: