class Bytepack::Timestamp

Public Class Methods

pack(val) click to toggle source
Calls superclass method Bytepack::FixedSize::pack
# File lib/bytepack/basic/fixed_size/timestamp.rb, line 5
def pack(val)
  # All dates are represented as Long values. This signed number represents the number of microseconds before or after Jan. 1 1970 00:00:00 GMT, the Unix epoch. Note that the units are microseconds, not milliseconds.
  val = case val
  when ::Integer then val
  when ::Time then val.to_i*1000000 + val.usec # Microseconds
  end
  super(val)
end
unpack(bytes, offset = 0) click to toggle source
Calls superclass method Bytepack::FixedSize::unpack
# File lib/bytepack/basic/fixed_size/timestamp.rb, line 14
def unpack(bytes, offset = 0)
  unpacked = super(bytes, offset)
  unpacked[0] = Time.at(unpacked[0]/1000000.to_f) if unpacked[0] # Microseconds
  unpacked
end