Merge pull request #8864 from colinux/fix-date-not-parseable
fix(date): ne crash pas lorsqu'un champ date n'as pas une date standard
This commit is contained in:
commit
b8f639721e
2 changed files with 15 additions and 3 deletions
|
@ -30,11 +30,11 @@ class Champs::DateChamp < Champ
|
|||
|
||||
def to_s
|
||||
value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : ""
|
||||
rescue ArgumentError
|
||||
value.presence || "" # old dossiers can have not parseable dates
|
||||
end
|
||||
|
||||
def for_tag
|
||||
value.present? ? I18n.l(Time.zone.parse(value), format: '%d %B %Y') : ""
|
||||
end
|
||||
alias for_tag to_s
|
||||
|
||||
private
|
||||
|
||||
|
|
|
@ -45,6 +45,18 @@ describe Champs::DateChamp do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#to_s" do
|
||||
it "format the date" do
|
||||
champ_with_value("2020-06-20")
|
||||
expect(date_champ.to_s).to eq("20 juin 2020")
|
||||
end
|
||||
|
||||
it "does not fail when value is not iso" do
|
||||
champ_with_value("2023-30-01")
|
||||
expect(date_champ.to_s).to eq("2023-30-01")
|
||||
end
|
||||
end
|
||||
|
||||
def champ_with_value(number)
|
||||
date_champ.tap { |c| c.value = number }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue