jetrockets/attrio

View on GitHub
lib/attrio/types/time.rb

Summary

Maintainability
A
45 mins
Test Coverage
# encoding: utf-8

module Attrio
  module Types
    class Time < Base
      def self.typecast(value, options = {})
        begin
          options[:format].present? ? ::Time.strptime(value.to_s, options[:format]) : ::Time.parse(value.to_s)
        rescue ArgumentError => e
          nil
        end      
      end

      def self.typecasted?(value, options = {})
        value.is_a? ::Time
      end
    end
  end
end