demarches-normaliennes/app/models/champs/date_champ.rb

27 lines
464 B
Ruby
Raw Normal View History

2018-02-13 18:18:20 +01:00
class Champs::DateChamp < Champ
before_save :format_before_save
def search_terms
# Text search is pretty useless for dates so were not including these champs
end
def to_s
value.present? ? I18n.l(Date.parse(value)) : ""
end
def for_tag
value.present? ? I18n.l(Date.parse(value)) : ""
end
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