module Transit::DateTimeUtil

@api private

Public Class Methods

from_millis(millis) click to toggle source
# File lib/transit/date_time_util.rb, line 32
def from_millis(millis)
  t = Time.at(millis / 1000).utc
  DateTime.new(t.year, t.month, t.day, t.hour, t.min, t.sec + (millis % 1000 * 0.001))
end
to_millis(v) click to toggle source
# File lib/transit/date_time_util.rb, line 18
def to_millis(v)
  case v
  when DateTime
    t = v.new_offset(0).to_time
  when Date
    t = Time.gm(v.year, v.month, v.day)
  when Time
    t = v
  else
    raise "Don't know how to get millis from #{t.inspect}"
  end
  (t.to_i * 1000) + (t.usec / 1000.0).round
end

Private Instance Methods

from_millis(millis) click to toggle source
# File lib/transit/date_time_util.rb, line 32
def from_millis(millis)
  t = Time.at(millis / 1000).utc
  DateTime.new(t.year, t.month, t.day, t.hour, t.min, t.sec + (millis % 1000 * 0.001))
end
to_millis(v) click to toggle source
# File lib/transit/date_time_util.rb, line 18
def to_millis(v)
  case v
  when DateTime
    t = v.new_offset(0).to_time
  when Date
    t = Time.gm(v.year, v.month, v.day)
  when Time
    t = v
  else
    raise "Don't know how to get millis from #{t.inspect}"
  end
  (t.to_i * 1000) + (t.usec / 1000.0).round
end