Sha256: 241d03200aa375ee4d75ff1e3bc7af90a1b332faf452ee558bc3a368048a79a7

Contents?: true

Size: 418 Bytes

Versions: 5

Compression:

Stored size: 418 Bytes

Contents

# frozen_string_literal: true

module Attribeauty
  module Types
    # custom Time type
    class Time
      def cast(value)
        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

5 entries across 5 versions & 1 rubygems

Version Path
attribeauty-0.3.2 lib/attribeauty/types/time.rb
attribeauty-0.3.1 lib/attribeauty/types/time.rb
attribeauty-0.3.0 lib/attribeauty/types/time.rb
attribeauty-0.2.0 lib/attribeauty/types/time.rb
attribeauty-0.1.0 lib/attribeauty/types/time.rb