debian-mirror-gitlab/app/validators/iso8601_date_validator.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

10 lines
316 B
Ruby
Raw Normal View History

2023-03-04 22:38:38 +05:30
# frozen_string_literal: true
class Iso8601DateValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
Date.iso8601(record.read_attribute_before_type_cast(attribute).to_s)
rescue ArgumentError, TypeError
record.errors.add(attribute, _('must be in ISO 8601 format'))
end
end