Issue #13919 has been updated by shevegen (Robert A. Heiler).


I have no objection to a new method at all.

I think the name "Time.of()" is strange though.

With Time.at(), we can say "ok, at this or that moment, we want the time".

With Time.of(), I am confused what that should mean. I am not a native
english speaker though, so who knows.

Would Time.nsec be any worse? That is, it would want the time input in
nanoseconds (nsec is nano seconds right?)

I agree that Time.at() is not very convenient with the second parameter
mandating microsecond IF one wants to use nanoseconds instead. I think
the reason why that was chosen, though, was because nsec may be less
frequent than msec. Like hour-minutes-seconds notation, and then the
milliseconds after a ',' or so.

Just putting some more ideas for names out there:

  Time.at_nsec
  Time.at(t.to_i, nsec: t)
  Time.at(t.to_i, :nsec)

Hmm. Or perhaps be able to modify the default for Time so that you can
switch it to nsec, like:

  Time.default_to = :microseconds
  Time.default_to = :nanoseconds

Or anything like that. Just trying to find good alternatives, giving 
things a good name that can easily stick mentally is not always easy.

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

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