Sha256: d1f59dc78d47428db6877eb8d5426ad34f4695777241296b6b298993cfeecb29

Contents?: true

Size: 580 Bytes

Versions: 3

Compression:

Stored size: 580 Bytes

Contents

require 'time'

module Kanade
  module Converter
    class Time < Base
      Engine.register_converter!(self)

      def serialize(term, _)
        return nil if term.nil?
        term.iso8601(0)
      end
      def deserialize(term, _)
        return nil if term.nil?
        return term if term.is_a?(::Time)
        return term if term.is_a?(Date)
        # WARNING: Parse does not really parse TZ!
        # Consider using ActiveSupport?

        ::Time.parse(term)
      end

      configurable :time_format, :iso8601
      configurable :time_msec_round, 0
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
kanade-0.1.1 lib/kanade/converter/time.rb
kanade-0.1.0 lib/kanade/converter/time.rb
kanade-0.1.0.beta2 lib/kanade/converter/time.rb