Sha256: 227527cbddb0de6f385e7123195e5e6a9dd8d5a784bc06aba6095d80e360ecf6

Contents?: true

Size: 495 Bytes

Versions: 4

Compression:

Stored size: 495 Bytes

Contents

module Hari
  class Entity
    module Serialization
      module Time

        def self.serialize(value, options = {})
          desserialize(value, options).try :strftime, '%Y%m%d%H%M%S'
        end

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

          value.kind_of?(::Time) ? value : ::Time.parse(value)
        rescue
          raise SerializationError, "#{options[:name]}:#{value} is an invalid 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/time.rb
hari-0.0.4 lib/hari/entity/serialization/time.rb
hari-0.0.3 lib/hari/entity/serialization/time.rb
hari-0.0.1 lib/hari/entity/serialization/time.rb