Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/mplight.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_mpdata(data, *args) ⇒ Object



283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File 'lib/mplight.rb', line 283

def from_mpdata data, *args
  case data.length
  when  4 then
    s, = data.unpack "L>"
    Time.at s
  when  8 then
    t, = data.unpack "Q>"
    n = t >> 34
    t &= 0x3ffffffff
    Time.at t, n, :nanosecond
  when 12 then
    n, s = data.unpack "L>Q>"
    Time.at s, n, :nanosecond
  else
    raise ArgumentError, "Illegal time data: #{data.inspect}"
  end
end

Instance Method Details

#to_mpdataObject



303
304
305
306
307
308
309
# File 'lib/mplight.rb', line 303

def to_mpdata
  case
  when tv_nsec.zero? && tv_sec < 0x100000000 then [ tv_sec].pack "L>"
  when                  tv_sec < 0x400000000 then [ (tv_nsec << 34)|tv_sec].pack "Q>"
  else                                            [ tv_nsec, tv_sec].pack "L>Q>"
  end
end