Class: Bytepack::Timestamp
- Defined in:
- lib/bytepack/basic/fixed_size/timestamp.rb
Constant Summary
Constants inherited from Long
Long::DIRECTIVE, Long::LENGTH, Long::NULL_INDICATOR
Class Method Summary collapse
Methods inherited from Basic
bytesToInt, intToBytes, preprocess
Methods inherited from Struct
classifyDataType, config, packingDataType, single_type_array?, testpacking
Class Method Details
.pack(val) ⇒ Object
5 6 7 8 9 10 11 12 |
# 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) ⇒ Object
14 15 16 17 18 |
# 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 |