Method: Lazier::DateTime::ClassMethods#valid?

Defined in:
lib/lazier/datetime.rb

#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


73
74
75
76
77
78
# File 'lib/lazier/datetime.rb', line 73

def valid?(value, format = "%F %T")
  ::DateTime.strptime(value, custom_format(format))
  true
rescue
  false
end