module TimeMsec

The TimeMsec module is a refinement for the Time class that makes it easier to work with millisecond timestamps.

@example

Time.now.to_i    # 1595194259
Time.now.ts_msec # NoMethodError

using TimeMsec

Time.now.to_i    # 1595194259
Time.now.ts_msec # 1595194259000

Time.from_msec(1595194259000) # 2020-07-19 14:30:59 -0700

Public Instance Methods

from_msec(timestamp) click to toggle source
# File lib/ext/time_msec.rb, line 25
def from_msec(timestamp)
  at(timestamp / 1000.0)
end
ts_msec() click to toggle source

TODO: convert to to_msec

# File lib/ext/time_msec.rb, line 19
def ts_msec
  (to_f * 1000.0).to_i
end