Sha256: 577c9de3ff0235d35c7155a69b87331ed133099e2f76d31007ea61451a08baa9

Contents?: true

Size: 1 KB

Versions: 9

Compression:

Stored size: 1 KB

Contents

# Copyright 2020 Google LLC
#
# Use of this source code is governed by an MIT-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/MIT.

# frozen_string_literal: true

module ActiveRecord
  module Type
    module Spanner
      class Time < ActiveRecord::Type::Time
        def serialize value, *options
          return "PENDING_COMMIT_TIMESTAMP()" if value == :commit_timestamp && options.length && options[0] == :dml
          return "spanner.commit_timestamp()" if value == :commit_timestamp && options.length && options[0] == :mutation
          val = super value
          val.acts_like?(:time) ? val.utc.rfc3339(9) : val
        end

        def user_input_in_time_zone value
          return value.in_time_zone if value.is_a? ::Time
          super value
        end

        private

        def cast_value value
          if value.is_a? ::String
            value = value.empty? ? nil : ::Time.parse(value)
          end

          value
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
activerecord-spanner-adapter-1.2.2 lib/active_record/type/spanner/time.rb
activerecord-spanner-adapter-1.2.1 lib/active_record/type/spanner/time.rb
activerecord-spanner-adapter-1.2.0 lib/active_record/type/spanner/time.rb
activerecord-spanner-adapter-1.1.0 lib/active_record/type/spanner/time.rb
activerecord-spanner-adapter-1.0.1 lib/active_record/type/spanner/time.rb
activerecord-spanner-adapter-1.0.0 lib/active_record/type/spanner/time.rb
activerecord-spanner-adapter-0.7.0 lib/active_record/type/spanner/time.rb
activerecord-spanner-adapter-0.6.0 lib/active_record/type/spanner/time.rb
activerecord-spanner-adapter-0.5.0 lib/active_record/type/spanner/time.rb