Sha256: 6ae0920faeb843d18725679bfcf2c493564fb3a503873bab18998c981898ac8c

Contents?: true

Size: 448 Bytes

Versions: 12

Compression:

Stored size: 448 Bytes

Contents

# frozen_string_literal: true

module Attribeauty
  module Types
    # custom Time type
    class Time
      def cast(value)
        return if value.nil?

        case value
        when Time
          value
        when Date, DateTime
          value.to_time
        when Integer
          ::Time.at(value / 1000.0)
        when Numeric
          ::Time.at(value)
        else
          ::Time.parse(value)
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
attribeauty-0.4.11 lib/attribeauty/types/time.rb
attribeauty-0.4.8 lib/attribeauty/types/time.rb
attribeauty-0.4.7 lib/attribeauty/types/time.rb
attribeauty-0.4.6 lib/attribeauty/types/time.rb
attribeauty-0.4.5 lib/attribeauty/types/time.rb
attribeauty-0.4.4 lib/attribeauty/types/time.rb
attribeauty-0.4.3 lib/attribeauty/types/time.rb
attribeauty-0.4.2 lib/attribeauty/types/time.rb
attribeauty-0.4.1 lib/attribeauty/types/time.rb
attribeauty-0.4.0 lib/attribeauty/types/time.rb
attribeauty-0.3.4 lib/attribeauty/types/time.rb
attribeauty-0.3.3 lib/attribeauty/types/time.rb