Sha256: 02502dbf89aa2baa69f3413ad773bd465f4cd8409ec77544362ce6498935085f

Contents?: true

Size: 646 Bytes

Versions: 17

Compression:

Stored size: 646 Bytes

Contents

module Acfs::Resource::Attributes
  # @api public
  #
  # DateTime attribute type. Use it in your model as
  # an attribute type:
  #
  # @example
  #   class User < Acfs::Resource
  #     attribute :name, :date_time
  #   end
  #
  class DateTime < Base

    # @api public
    #
    # Cast given object to DateTime.
    #
    # @param [Object] value Object to cast.
    # @return [DateTime] Casted object as DateTime.
    #
    def cast_value(value)
      if value.blank?
        nil
      elsif value.acts_like?(:time) || value.acts_like?(:date)
        value.to_datetime
      else
        ::DateTime.iso8601 value
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
acfs-1.3.2 lib/acfs/resource/attributes/date_time.rb
acfs-1.3.1 lib/acfs/resource/attributes/date_time.rb
acfs-1.3.0 lib/acfs/resource/attributes/date_time.rb
acfs-1.2.1 lib/acfs/resource/attributes/date_time.rb
acfs-0.50.0 lib/acfs/resource/attributes/date_time.rb
acfs-1.2.0 lib/acfs/resource/attributes/date_time.rb
acfs-0.49.1 lib/acfs/resource/attributes/date_time.rb
acfs-1.1.1 lib/acfs/resource/attributes/date_time.rb
acfs-0.49.0 lib/acfs/resource/attributes/date_time.rb
acfs-1.1.0 lib/acfs/resource/attributes/date_time.rb
acfs-0.48.2 lib/acfs/resource/attributes/date_time.rb
acfs-1.0.1 lib/acfs/resource/attributes/date_time.rb
acfs-0.48.1 lib/acfs/resource/attributes/date_time.rb
acfs-1.0.0 lib/acfs/resource/attributes/date_time.rb
acfs-0.48.0 lib/acfs/resource/attributes/date_time.rb
acfs-0.47.0 lib/acfs/resource/attributes/date_time.rb
acfs-0.46.0 lib/acfs/resource/attributes/date_time.rb