Module: Avro::LogicalTypes::IntDate

Defined in:
lib/avro/logical_types.rb

Constant Summary collapse

EPOCH_START =
Date.new(1970, 1, 1)

Class Method Summary collapse

Class Method Details

.decode(int) ⇒ Object



211
212
213
# File 'lib/avro/logical_types.rb', line 211

def self.decode(int)
  EPOCH_START + int
end

.encode(date) ⇒ Object



205
206
207
208
209
# File 'lib/avro/logical_types.rb', line 205

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

  (date - EPOCH_START).to_i
end