Sha256: 1b387f63b3ba842d0afd636ba369fdfedb01e46348b21ecfbb900eebdc9d3e7a

Contents?: true

Size: 806 Bytes

Versions: 18

Compression:

Stored size: 806 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

        def referenced_model_classes
          EMPTY_ARRAY
        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

18 entries across 18 versions & 1 rubygems

Version Path
avromatic-5.2.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-5.1.1 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-5.1.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-5.0.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-4.3.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-4.2.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-4.1.1 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-4.1.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-4.0.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-3.0.2 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-3.0.1 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-3.0.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.4.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.3.0 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.2.6 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.2.5 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.2.4 lib/avromatic/model/types/timestamp_millis_type.rb
avromatic-2.2.3 lib/avromatic/model/types/timestamp_millis_type.rb