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

45 lines
1,016 B
Ruby
Raw Normal View History

2020-08-06 16:35:45 +02:00
# == Schema Information
#
# Table name: champs
#
# id :integer not null, primary key
2021-01-13 18:57:10 +01:00
# data :jsonb
2020-08-06 16:35:45 +02:00
# private :boolean default(FALSE), not null
# row :integer
# type :string
# value :string
# created_at :datetime
# updated_at :datetime
# dossier_id :integer
# etablissement_id :integer
2021-01-14 23:53:02 +01:00
# external_id :string
2020-08-06 16:35:45 +02:00
# parent_id :bigint
# type_de_champ_id :integer
#
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(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
2018-02-13 18:18:20 +01:00
end