Use default format for date and datetime champ

This commit is contained in:
simon lehericey 2019-05-22 17:54:17 +02:00 committed by Pierre de La Morinerie
parent abcd58c35d
commit ee296f2b44
4 changed files with 8 additions and 4 deletions

View file

@ -6,7 +6,7 @@ class Champs::DateChamp < Champ
end end
def to_s def to_s
value.present? ? Date.parse(value).strftime('%d/%m/%Y') : "" value.present? ? I18n.l(Date.parse(value)) : ""
end end
private private

View file

@ -5,6 +5,10 @@ class Champs::DatetimeChamp < Champ
# Text search is pretty useless for datetimes so were not including these champs # Text search is pretty useless for datetimes so were not including these champs
end end
def to_s
value.present? ? I18n.l(Time.zone.parse(value)) : ""
end
private private
def format_before_save def format_before_save

View file

@ -31,9 +31,9 @@
- when TypeDeChamp.type_champs.fetch(:textarea) - when TypeDeChamp.type_champs.fetch(:textarea)
= render partial: "shared/champs/textarea/show", locals: { champ: c } = render partial: "shared/champs/textarea/show", locals: { champ: c }
- when TypeDeChamp.type_champs.fetch(:date) - when TypeDeChamp.type_champs.fetch(:date)
= try_format_date(c.to_s) = c.to_s
- when TypeDeChamp.type_champs.fetch(:datetime) - when TypeDeChamp.type_champs.fetch(:datetime)
= try_format_datetime(c.to_s) = c.to_s
- else - else
= sanitize(c.to_s) = sanitize(c.to_s)

View file

@ -238,7 +238,7 @@ describe TagsSubstitutionConcern, type: :model do
.update(value: '2017-09-13 09:00') .update(value: '2017-09-13 09:00')
end end
it { is_expected.to eq('15/04/2017 2017-09-13 09:00') } it { is_expected.to eq('15 avril 2017 13 septembre 2017 09:00') }
end end
end end
end end