Sha256: d1453b07f36e285d0f1bf4910429b395a44174b2db0a01ac179798d183013ac6

Contents?: true

Size: 735 Bytes

Versions: 4

Compression:

Stored size: 735 Bytes

Contents

# frozen_string_literal: true

require 'avromatic/model/types/abstract_timestamp_type'

module Avromatic
  module Model
    module Types

      # This subclass is used to truncate timestamp values to milliseconds.
      class TimestampMillisType < Avromatic::Model::Types::AbstractTimestampType

        def name
          'timestamp-millis'
        end

        private

        def truncated?(value)
          value.nsec % 1_000_000 == 0
        end

        def coerce_time(input)
          # value is coerced to a local Time
          # The Avro representation of a timestamp is Epoch seconds, independent
          # of time zone.
          ::Time.at(input.to_i, input.usec / 1000 * 1000)
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
avromatic-2.2.1 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.2.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.1.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.0.1 lib/avromatic/model/types/timestamp_millis_type.rb