Method: Lazier::DateTime::ClassMethods#is_valid?

Defined in:
lib/lazier/datetime.rb

#is_valid?(value, format = "%F %T") ⇒ Boolean

Checks if the date is valid against to a specific format.

Parameters:

  • value (String)

    The value to check.

  • format (String) (defaults to: "%F %T")

    The format to check the value against.

Returns:

  • (Boolean)

    true if the value is valid against the format, false otherwise.

See Also:

  • DateTime#custom_format


149
150
151
# File 'lib/lazier/datetime.rb', line 149

def is_valid?(value, format = "%F %T")
  !(::DateTime.strptime(value, self.custom_format(format)) rescue nil).nil?
end