Issue #13919 has been updated by akr (Akira Tanaka).


I think new method is possible if we find a good method name.

Another idea is adding an optional argument, unit, for Time.at.
Time.at(s, ns, :nanosecond) for example.

----------------------------------------
Feature #13919: Add a new method to create Time instances from unix time and nsec
https://bugs.ruby-lang.org/issues/13919#change-66796

* Author: tagomoris (Satoshi TAGOMORI)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
Time object contains `nsec`, but Time class doesn't have method to create an instance with nsec.
Time.at() accepts 2nd argument, but it's micro-sec, and we need to divide nsec by 1000.0.

```ruby
t1 = Time.now
t1.nsec #=> nsec value

t2 = Time.at(t1.to_i, t1.usec) # not nsec!
t3 = Time.at(t1.to_i, t1.nsec / 1000.0) # additional division
```

I think it's better to have another method to create an instance from time(unix time) and nsec, for example, `Time.of(unix_time, nsec)`

```ruby
t = Time.now
Time.of(t.to_i, t.nsec) == t
```




-- 
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>