Sha256: 5ca3b857eaa44abe1befaf2140907e8332b09b5ee0eec28139a2f5616adf24d7

Contents?: true

Size: 453 Bytes

Versions: 16

Compression:

Stored size: 453 Bytes

Contents

# frozen_string_literal: true

module ValidateParams
  class Types
    class DateTime
      def self.valid?(value)
        Time.at(Integer(value))
        true
      rescue ArgumentError, TypeError
        false
      end

      def self.cast(raw_value, **)
        return raw_value if raw_value.is_a?(::Time)

        Time.at(Integer(raw_value))
      rescue ArgumentError, TypeError
        raw_value
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
validate-params-0.14.0 lib/validate_params/types/date_time.rb
validate-params-0.13.1 lib/validate_params/types/date_time.rb
validate-params-0.13.0 lib/validate_params/types/date_time.rb
validate-params-0.12.5 lib/validate_params/types/date_time.rb
validate-params-0.12.4 lib/validate_params/types/date_time.rb
validate-params-0.12.3 lib/validate_params/types/date_time.rb
validate-params-0.12.2 lib/validate_params/types/date_time.rb
validate-params-0.12.1 lib/validate_params/types/date_time.rb
validate-params-0.12.0 lib/validate_params/types/date_time.rb
validate-params-0.11.0 lib/validate_params/types/date_time.rb
validate-params-0.10.1 lib/validate_params/types/date_time.rb
validate-params-0.10.0 lib/validate_params/types/date_time.rb
validate-params-0.9.0 lib/validate_params/types/date_time.rb
validate-params-0.8.1 lib/validate_params/types/date_time.rb
validate-params-0.8.0 lib/validate_params/types/date_time.rb
validate-params-0.7.1 lib/validate_params/types/date_time.rb