Sha256: ee1ad88c80ac2aaf1e100d34e7cb2d8b921ed5c111853fb3ec93530474a3200f

Contents?: true

Size: 626 Bytes

Versions: 7

Compression:

Stored size: 626 Bytes

Contents

module DataMapper
  class Property

    class ParseDate < Object

      def dump(value)
        case value
        when ::Date
          {"__type" => "Date", "iso" => value.to_datetime.utc.iso8601(3)}
        when ::DateTime
          {"__type" => "Date", "iso" => value.utc.iso8601(3)}
        when ::Hash
          value
        end
      end

      def load(value)
        typecast(value)
      end

      def typecast(value)
        case value
        when ::Hash
          value["iso"].to_datetime
        when ::NilClass
          value
        else
          value.to_datetime
        end
      end

    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
dm-parse-0.3.20 lib/property/parse_date.rb
dm-parse-0.3.19 lib/property/parse_date.rb
dm-parse-0.3.18 lib/property/parse_date.rb
dm-parse-0.3.17 lib/property/parse_date.rb
dm-parse-0.3.16 lib/property/parse_date.rb
dm-parse-0.3.15 lib/property/parse_date.rb
dm-parse-0.3.14 lib/property/parse_date.rb