Module: Avro::LogicalTypes::TimestampMillis

Defined in:
lib/avro/logical_types.rb

Constant Summary collapse

SUBUNITS_PER_SECOND =
1000

Class Method Summary collapse

Class Method Details

.decode(int) ⇒ Object



226
227
228
229
# File 'lib/avro/logical_types.rb', line 226

def self.decode(int)
  s, ms = int.divmod(SUBUNITS_PER_SECOND)
  Time.at(s, ms, :millisecond).utc
end

.encode(value) ⇒ Object



219
220
221
222
223
224
# File 'lib/avro/logical_types.rb', line 219

def self.encode(value)
  return value.to_i if value.is_a?(Numeric)

  time = value.to_time
  time.to_i * SUBUNITS_PER_SECOND + time.usec / SUBUNITS_PER_SECOND
end