[ruby-core:96615] [Ruby master Bug#16470] Issue with nanoseconds in Time#inspect
From:
zn@...
Date:
2020-01-01 15:11:41 UTC
List:
ruby-core #96615
Issue #16470 has been updated by znz (Kazuhiro NISHIYAMA).
Assignee set to matz (Yukihiro Matsumoto)
----------------------------------------
Bug #16470: Issue with nanoseconds in Time#inspect
https://bugs.ruby-lang.org/issues/16470#change-83585
* Author: andrykonchin (Andrew Konchin)
* Status: Open
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version:
* ruby -v: 2.7
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
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: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>