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
|
2019-05-22 17:54:17 +02:00
|
|
|
|
value.present? ? I18n.l(Date.parse(value)) : ""
|
2018-12-28 15:37:20 +01:00
|
|
|
|
end
|
|
|
|
|
|
2019-09-11 16:04:42 +02:00
|
|
|
|
def for_tag
|
|
|
|
|
value.present? ? I18n.l(Date.parse(value)) : ""
|
|
|
|
|
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
|