Project

General

Profile

Actions

Feature #13919

closed

Add a new method to create Time instances from unix time and nsec

Added by tagomoris (Satoshi Tagomori) about 7 years ago. Updated about 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:82864]

Description

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.

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)

t = Time.now
Time.of(t.to_i, t.nsec) == t
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0