lib/eco/api/common/people/default_parsers/date_parser.rb in eco-helpers-3.0.14 vs lib/eco/api/common/people/default_parsers/date_parser.rb in eco-helpers-3.0.15
- old
+ new
@@ -32,40 +32,45 @@
def serialize_date(value)
return value.map {|val| serialize_date(val)}.compact if value.is_a?(Enumerable)
return nil if blank?(value)
return value if value.is_a?(String)
return nil unless [Date, Time].any? {|type| value.is_a?(type)}
+
value&.strftime('%Y-%m-%d')
rescue TypeError, Date::Error
nil
end
def date?(value)
return true if value.nil?
return true if value.to_s.strip.empty?
+
Date.parse(value)
true
rescue TypeError, Date::Error
false
end
def valid_range?(date)
return true if date.nil?
return false unless min_date <= date
+
max_date >= date
end
def wrong!(value, attr:, desc: "Can't make a date out of")
return if wrong(attr).key?(value)
+
wrong(attr)[value] = value
log(:warn) { "#{desc} '#{value}' for '#{attr}'" }
nil
end
def wrong(attr = nil)
@wrong ||= {}
return @wrong if attr.nil?
+
@wrong[attr] ||= {}
end
def min_date
@min_date ||= Date.parse(MIN_DATE)
@@ -76,8 +81,9 @@
end
def blank?(value)
return true if value.nil?
return true if value.to_s.strip.empty?
+
false
end
end