2018-02-13 18:18:20 +01:00
|
|
|
|
class Champs::DateChamp < Champ
|
2018-06-14 17:41:31 +02:00
|
|
|
|
before_save :format_before_save
|
|
|
|
|
|
2018-07-25 19:34:06 +02:00
|
|
|
|
def search_terms
|
|
|
|
|
# Text search is pretty useless for dates so we’re not including these champs
|
|
|
|
|
end
|
|
|
|
|
|
2018-12-28 15:37:20 +01:00
|
|
|
|
def to_s
|
|
|
|
|
value.present? ? Date.parse(value).strftime('%d/%m/%Y') : ""
|
|
|
|
|
end
|
|
|
|
|
|
2018-06-14 17:41:31 +02:00
|
|
|
|
private
|
|
|
|
|
|
|
|
|
|
def format_before_save
|
|
|
|
|
self.value =
|
|
|
|
|
begin
|
|
|
|
|
Date.parse(value).iso8601
|
|
|
|
|
rescue
|
|
|
|
|
nil
|
|
|
|
|
end
|
|
|
|
|
end
|
2018-02-13 18:18:20 +01:00
|
|
|
|
end
|