Sha256: 89fdd043992787638b76ff8a4ab632e653fbec1bb92aae89ca4166aed3b429ae

Contents?: true

Size: 495 Bytes

Versions: 4

Compression:

Stored size: 495 Bytes

Contents

module Hari
  class Entity
    module Serialization
      module DateTime

        def self.serialize(value, options = {})
          desserialize(value, options).try :iso8601
        end

        def self.desserialize(value, options = {})
          return unless value.present?

          value.kind_of?(::DateTime) ? value : ::DateTime.parse(value)
        rescue
          raise SerializationError, "#{options[:name]}:#{value} is an invalid date time"
        end

      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
hari-0.0.5 lib/hari/entity/serialization/datetime.rb
hari-0.0.4 lib/hari/entity/serialization/datetime.rb
hari-0.0.3 lib/hari/entity/serialization/datetime.rb
hari-0.0.1 lib/hari/entity/serialization/datetime.rb