Sha256: bdccbd3790f1d9402dc5ffae1b40cfac887842758ffe98afdad4411be159f10c

Contents?: true

Size: 788 Bytes

Versions: 17

Compression:

Stored size: 788 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 microseconds.
      class TimestampMicrosType < Avromatic::Model::Types::AbstractTimestampType

        def name
          'timestamp-micros'
        end

        def referenced_model_classes
          EMPTY_ARRAY
        end

        private

        def truncated?(value)
          value.nsec % 1_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)
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

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