[ruby-core:96615] [Ruby master Bug#16470] Issue with nanoseconds in Time#inspect
[email protected] Wed, 01 Jan 2020 15:11:41 +0000 (UTC)
| Newsgroups | gmane.comp.lang.ruby.core |
|---|---|
| Message-ID | <redmine.journal-83585.20200101151140.e057ad6af9c9a2c9@ruby-lang.org> |
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:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>