Class: JSONSkooma::Validators::Date

Inherits:
Base
  • Object
show all
Defined in:
lib/json_skooma/validators/date.rb

Constant Summary collapse

REGEXP =
/\A#{DateTime::DATE_REGEXP}\z/

Instance Method Summary collapse

Methods inherited from Base

assert?, call, inherited

Instance Method Details

#call(data) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/json_skooma/validators/date.rb', line 8

def call(data)
  match = REGEXP.match(data)
  raise FormatError, "must be a valid RFC 3339 date string" if match.nil?

  ::Date.new(match[:Y].to_i, match[:M].to_i, match[:D].to_i)
rescue ::Date::Error
  raise FormatError, "must be a valid RFC 3339 date string"
end