Sha256: 8d04f4ed93cdd1e4511d4d26a0362d165f57d0cd94641f44563ee089319460ef
Contents?: true
Size: 574 Bytes
Versions: 3
Compression:
Stored size: 574 Bytes
Contents
# frozen_string_literal: true require 'date' using SmartCore::Ext::BasicObjectAsObject # @api public # @since 0.1.0 # @version 0.3.0 SmartCore::Types::Value.define_type(:DateTime) do |type| type.define_checker do |value| value.is_a?(::DateTime) || value == ::DateTime::Infinity end type.define_caster do |value| next value if value.is_a?(::DateTime) || value == ::DateTime::Infinity begin ::DateTime.parse(value) rescue ::Date::Error, ::TypeError raise(SmartCore::Types::TypeCastingError, 'Non-castable to DateTime') end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
smart_types-0.6.0 | lib/smart_core/types/value/date_time.rb |
smart_types-0.4.0 | lib/smart_core/types/value/date_time.rb |
smart_types-0.3.0 | lib/smart_core/types/value/date_time.rb |