Method: Hanami::Utils::Kernel.DateTime
- Defined in:
- lib/hanami/utils/kernel.rb
permalink .DateTime(arg) ⇒ DateTime
Coerces the argument to be a DateTime.
784 785 786 787 788 789 790 791 792 793 |
# File 'lib/hanami/utils/kernel.rb', line 784 def self.DateTime(arg) case arg when ->(a) { a.respond_to?(:to_datetime) } then arg.to_datetime when Numeric then DateTime(Time.at(arg)) else DateTime.parse(arg.to_s) end rescue ArgumentError, NoMethodError raise TypeError.new "can't convert #{inspect_type_error(arg)}into DateTime" end |