Sha256: b8f6993b8fabdc95a18e69a193c2355c311372858e0f6880932862293487f548
Contents?: true
Size: 498 Bytes
Versions: 2
Compression:
Stored size: 498 Bytes
Contents
# frozen_string_literal: true require 'time' # @api public # @since 0.1.0 SmartCore::Types::Value.define_type(:Time) do |type| type.define_checker do |value| value.is_a?(::Time) end type.define_caster do |value| next value if value.is_a?(::Time) begin SmartCore::Types::Value::Integer.valid?(value) ? ::Time.at(value) : ::Time.parse(value) rescue ::TypeError, ::ArgumentError raise(SmartCore::Types::TypeCastingError, 'Non-castable to Time') end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
smart_types-0.2.0 | lib/smart_core/types/value/time.rb |
smart_types-0.1.0 | lib/smart_core/types/value/time.rb |