mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
30 lines
661 B
Ruby
30 lines
661 B
Ruby
class DateTimeIso8601Validator < ActiveModel::EachValidator
|
|
def validate_each(record, attribute, value)
|
|
return if self.class.validate(value)
|
|
record.errors[attribute] << (options[:message] || I18n.t('unknown_expiry_absolute_pattern'))
|
|
end
|
|
|
|
class << self
|
|
def validate(value)
|
|
return true if value.empty?
|
|
|
|
begin
|
|
DateTime.zone.parse(value)
|
|
rescue => _e
|
|
return false
|
|
end
|
|
|
|
true
|
|
end
|
|
|
|
def validate_epp(obj, value)
|
|
return if validate(value)
|
|
|
|
{
|
|
code: '2005',
|
|
msg: I18n.t(:unknown_expiry_absolute_pattern),
|
|
value: { obj: obj, val: value }
|
|
}
|
|
end
|
|
end
|
|
end
|