demarches-normaliennes/app/models/champs/date_champ.rb
2022-09-20 15:16:52 +02:00

47 lines
1.4 KiB
Ruby
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# == Schema Information
#
# Table name: champs
#
# id :integer not null, primary key
# data :jsonb
# fetch_external_data_exceptions :string is an Array
# private :boolean default(FALSE), not null
# rebased_at :datetime
# row :integer
# type :string
# value :string
# value_json :jsonb
# created_at :datetime
# updated_at :datetime
# dossier_id :integer not null
# etablissement_id :integer
# external_id :string
# parent_id :bigint
# type_de_champ_id :integer not null
#
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(Time.zone.parse(value), format: '%d %B %Y') : ""
end
def for_tag
value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : ""
end
private
def format_before_save
self.value =
begin
Time.zone.parse(value).to_date.iso8601
rescue
nil
end
end
end