From abcd58c35d06c07674f86759045f665cb8e36a87 Mon Sep 17 00:00:00 2001 From: pedong Date: Wed, 10 Apr 2019 15:49:13 +0200 Subject: [PATCH 1/3] [fix #3710] date with letter Co-Authored-By: simon lehericey --- app/helpers/application_helper.rb | 8 ++++ .../shared/dossiers/_champ_row.html.haml | 4 ++ .../dossiers/_identite_entreprise.html.haml | 8 ++-- .../_infos_association.html.haml | 6 +-- .../etablissement/_infos_entreprise.html.haml | 2 +- config/locales/fr.yml | 5 ++- spec/helpers/application_helper_spec.rb | 38 +++++++++++++++++++ 7 files changed, 62 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index f2e84bd75..b99514ae8 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -112,4 +112,12 @@ module ApplicationHelper root_path end end + + def try_format_date(date) + date.present? ? I18n.l(date) : '' + end + + def try_format_datetime(datetime) + datetime.present? ? I18n.l(datetime) : '' + end end diff --git a/app/views/shared/dossiers/_champ_row.html.haml b/app/views/shared/dossiers/_champ_row.html.haml index 361c6e786..62f6feb87 100644 --- a/app/views/shared/dossiers/_champ_row.html.haml +++ b/app/views/shared/dossiers/_champ_row.html.haml @@ -30,6 +30,10 @@ = render partial: "shared/champs/siret/show", locals: { champ: c, profile: profile } - when TypeDeChamp.type_champs.fetch(:textarea) = render partial: "shared/champs/textarea/show", locals: { champ: c } + - when TypeDeChamp.type_champs.fetch(:date) + = try_format_date(c.to_s) + - when TypeDeChamp.type_champs.fetch(:datetime) + = try_format_datetime(c.to_s) - else = sanitize(c.to_s) diff --git a/app/views/shared/dossiers/_identite_entreprise.html.haml b/app/views/shared/dossiers/_identite_entreprise.html.haml index 87be8390f..33f0ce548 100644 --- a/app/views/shared/dossiers/_identite_entreprise.html.haml +++ b/app/views/shared/dossiers/_identite_entreprise.html.haml @@ -22,7 +22,7 @@ %td= etablissement.naf %tr %th.libelle Date de création : - %td= etablissement.entreprise.date_creation&.strftime("%d/%m/%Y") + %td= try_format_date(etablissement.entreprise.date_creation) %tr %th.libelle Effectif de l'organisation : %td= effectif(etablissement) @@ -64,10 +64,10 @@ %td= etablissement.association_objet %tr %th.libelle Date de création : - %td= etablissement.association_date_creation&.strftime("%d/%m/%Y") + %td= try_format_date(etablissement.association_date_creation) %tr %th.libelle Date de publication : - %td= etablissement.association_date_publication&.strftime("%d/%m/%Y") + %td= try_format_date(etablissement.association_date_publication) %tr %th.libelle Date de déclaration : - %td= etablissement.association_date_declaration&.strftime("%d/%m/%Y") + %td= try_format_date(etablissement.association_date_declaration) diff --git a/app/views/users/dossiers/etablissement/_infos_association.html.haml b/app/views/users/dossiers/etablissement/_infos_association.html.haml index 4fe9b8f91..d8afcbdb6 100644 --- a/app/views/users/dossiers/etablissement/_infos_association.html.haml +++ b/app/views/users/dossiers/etablissement/_infos_association.html.haml @@ -13,12 +13,12 @@ %li Date de création : - = etablissement.association_date_creation&.strftime('%d/%m/%Y') + = try_format_date(etablissement.association_date_creation) %li Date de déclaration : - = etablissement.association_date_declaration&.strftime('%d/%m/%Y') + = try_format_date(etablissement.association_date_declaration) %li Date de publication : - = etablissement.association_date_publication&.strftime('%d/%m/%Y') + = try_format_date(etablissement.association_date_publication) diff --git a/app/views/users/dossiers/etablissement/_infos_entreprise.html.haml b/app/views/users/dossiers/etablissement/_infos_entreprise.html.haml index 54f03b486..9667a54bd 100644 --- a/app/views/users/dossiers/etablissement/_infos_entreprise.html.haml +++ b/app/views/users/dossiers/etablissement/_infos_entreprise.html.haml @@ -22,7 +22,7 @@ %li Date de création : - = etablissement.entreprise.date_creation&.strftime('%d/%m/%Y') + = try_format_date(etablissement.entreprise.date_creation) %li Effectif organisation : diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 435a8fb0e..a06351dbb 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -249,7 +249,7 @@ fr: - vendredi - samedi formats: - default: "%d/%m/%Y" + default: "%d %B %Y" short: "%e %b" long: "%e %B %Y" datetime: @@ -290,6 +290,9 @@ fr: x_seconds: one: 1 seconde other: "%{count} secondes" + time: + formats: + default: "%d %B %Y %R" pluralize: case: zero: dossier diff --git a/spec/helpers/application_helper_spec.rb b/spec/helpers/application_helper_spec.rb index 30a7becef..ff70654fd 100644 --- a/spec/helpers/application_helper_spec.rb +++ b/spec/helpers/application_helper_spec.rb @@ -17,4 +17,42 @@ describe ApplicationHelper do it { is_expected.to be_nil } end end + + describe "#try_format_date" do + subject { try_format_date(date) } + + describe 'try formatting a date' do + let(:date) { Date.new(2019, 01, 24) } + it { is_expected.to eq("24 janvier 2019") } + end + + describe 'try formatting a blank string' do + let(:date) { "" } + it { is_expected.to eq("") } + end + + describe 'try formatting a nil string' do + let(:date) { nil } + it { is_expected.to eq("") } + end + end + + describe "#try_format_datetime" do + subject { try_format_datetime(datetime) } + + describe 'try formatting 31/01/2019 11:25' do + let(:datetime) { Time.zone.local(2019, 01, 31, 11, 25, 00) } + it { is_expected.to eq("31 janvier 2019 11:25") } + end + + describe 'try formatting a blank string' do + let(:datetime) { "" } + it { is_expected.to eq("") } + end + + describe 'try formatting a nil string' do + let(:datetime) { nil } + it { is_expected.to eq("") } + end + end end From ee296f2b449df510108451930dbbed7a84e4ab7b Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 22 May 2019 17:54:17 +0200 Subject: [PATCH 2/3] Use default format for date and datetime champ --- app/models/champs/date_champ.rb | 2 +- app/models/champs/datetime_champ.rb | 4 ++++ app/views/shared/dossiers/_champ_row.html.haml | 4 ++-- spec/models/concern/tags_substitution_concern_spec.rb | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/models/champs/date_champ.rb b/app/models/champs/date_champ.rb index ceddaec82..0fd0a2499 100644 --- a/app/models/champs/date_champ.rb +++ b/app/models/champs/date_champ.rb @@ -6,7 +6,7 @@ class Champs::DateChamp < Champ end def to_s - value.present? ? Date.parse(value).strftime('%d/%m/%Y') : "" + value.present? ? I18n.l(Date.parse(value)) : "" end private diff --git a/app/models/champs/datetime_champ.rb b/app/models/champs/datetime_champ.rb index 3995b39e2..c98377d15 100644 --- a/app/models/champs/datetime_champ.rb +++ b/app/models/champs/datetime_champ.rb @@ -5,6 +5,10 @@ class Champs::DatetimeChamp < Champ # Text search is pretty useless for datetimes so we’re not including these champs end + def to_s + value.present? ? I18n.l(Time.zone.parse(value)) : "" + end + private def format_before_save diff --git a/app/views/shared/dossiers/_champ_row.html.haml b/app/views/shared/dossiers/_champ_row.html.haml index 62f6feb87..e59716d6b 100644 --- a/app/views/shared/dossiers/_champ_row.html.haml +++ b/app/views/shared/dossiers/_champ_row.html.haml @@ -31,9 +31,9 @@ - when TypeDeChamp.type_champs.fetch(:textarea) = render partial: "shared/champs/textarea/show", locals: { champ: c } - when TypeDeChamp.type_champs.fetch(:date) - = try_format_date(c.to_s) + = c.to_s - when TypeDeChamp.type_champs.fetch(:datetime) - = try_format_datetime(c.to_s) + = c.to_s - else = sanitize(c.to_s) diff --git a/spec/models/concern/tags_substitution_concern_spec.rb b/spec/models/concern/tags_substitution_concern_spec.rb index 4b5a1ef21..c6be332c5 100644 --- a/spec/models/concern/tags_substitution_concern_spec.rb +++ b/spec/models/concern/tags_substitution_concern_spec.rb @@ -238,7 +238,7 @@ describe TagsSubstitutionConcern, type: :model do .update(value: '2017-09-13 09:00') 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 From 7ef1a558f412b1af5476ec631da497ecdac3b76f Mon Sep 17 00:00:00 2001 From: pedong Date: Wed, 5 Jun 2019 17:07:38 +0200 Subject: [PATCH 3/3] change date format for all, use try_format_date of helper --- app/views/admin/procedures/_list.html.haml | 4 ++-- .../administrateur_mailer/activate_before_expiration.haml | 2 +- .../procedure_administrateurs/_administrateur.html.haml | 2 +- app/views/shared/dossiers/_champ_row.html.haml | 2 +- app/views/shared/dossiers/_identite_individual.html.haml | 2 +- app/views/shared/dossiers/_pieces_jointes.html.haml | 4 ++-- app/views/shared/dossiers/_submit_is_over.html.haml | 2 +- .../shared/dossiers/editable_champs/_champ_label.html.haml | 2 +- app/views/users/dossiers/index.html.haml | 2 +- spec/views/shared/dossiers/_demande.html.haml_spec.rb | 2 +- 10 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/views/admin/procedures/_list.html.haml b/app/views/admin/procedures/_list.html.haml index 39f9a4a4a..833a6a6fc 100644 --- a/app/views/admin/procedures/_list.html.haml +++ b/app/views/admin/procedures/_list.html.haml @@ -20,9 +20,9 @@ - if procedure.publiee? %td.procedure-lien= link_to(procedure_lien(procedure), procedure_lien(procedure)) - if procedure.publiee_ou_archivee? - %td= link_to(procedure.published_at.present? ? procedure.published_at.strftime('%d/%m/%Y %H:%M') : "", admin_procedure_href) + %td= link_to(procedure.published_at.present? ? try_format_datetime(procedure.published_at) : "", admin_procedure_href) - else - %td= link_to(procedure.created_at.strftime('%d/%m/%Y %H:%M'), admin_procedure_href) + %td= link_to(try_format_datetime(procedure.created_at), admin_procedure_href) %td = link_to('Cloner', admin_procedure_clone_path(procedure.id), data: { method: :put }, class: 'btn-sm btn-primary clone-btn') - if !procedure.publiee_ou_archivee? diff --git a/app/views/administrateur_mailer/activate_before_expiration.haml b/app/views/administrateur_mailer/activate_before_expiration.haml index 6f60a52cc..a5e0bea12 100644 --- a/app/views/administrateur_mailer/activate_before_expiration.haml +++ b/app/views/administrateur_mailer/activate_before_expiration.haml @@ -5,7 +5,7 @@ %p Vous avez fait la demande d’un compte administrateur sur demarches-simplifiees.fr. - Votre compte a été créé mais reste inactif, il arrivera à expiration le #{@expiration_date.strftime("%d/%m/%Y")} + Votre compte a été créé mais reste inactif, il arrivera à expiration le #{try_format_date(@expiration_date)} %p Afin d’activer votre compte, veuillez cliquer sur le lien ci-dessous : diff --git a/app/views/new_administrateur/procedure_administrateurs/_administrateur.html.haml b/app/views/new_administrateur/procedure_administrateurs/_administrateur.html.haml index 65354f432..9277ae0ad 100644 --- a/app/views/new_administrateur/procedure_administrateurs/_administrateur.html.haml +++ b/app/views/new_administrateur/procedure_administrateurs/_administrateur.html.haml @@ -1,6 +1,6 @@ %tr{ id: "procedure-#{@procedure.id}-administrateur-#{administrateur.id}" } %td= administrateur.email - %td= administrateur.created_at.strftime('%d/%m/%Y %H:%M') + %td= try_format_datetime(administrateur.created_at) %td= administrateur.registration_state %td - if administrateur == current_administrateur diff --git a/app/views/shared/dossiers/_champ_row.html.haml b/app/views/shared/dossiers/_champ_row.html.haml index e59716d6b..66d5b4807 100644 --- a/app/views/shared/dossiers/_champ_row.html.haml +++ b/app/views/shared/dossiers/_champ_row.html.haml @@ -41,4 +41,4 @@ %td.updated-at %span{ class: highlight_if_unseen_class(demande_seen_at, c.updated_at) } modifié le - = c.updated_at.strftime("%d/%m/%Y à %H:%M") + = try_format_datetime(c.updated_at) diff --git a/app/views/shared/dossiers/_identite_individual.html.haml b/app/views/shared/dossiers/_identite_individual.html.haml index c1d08eb5d..7f83da051 100644 --- a/app/views/shared/dossiers/_identite_individual.html.haml +++ b/app/views/shared/dossiers/_identite_individual.html.haml @@ -12,4 +12,4 @@ - if individual.birthdate.present? %tr %th.libelle Date de naissance : - %td= individual.birthdate&.strftime("%d/%m/%Y") + %td= try_format_date(individual.birthdate) diff --git a/app/views/shared/dossiers/_pieces_jointes.html.haml b/app/views/shared/dossiers/_pieces_jointes.html.haml index f547c6f72..c11777fb4 100644 --- a/app/views/shared/dossiers/_pieces_jointes.html.haml +++ b/app/views/shared/dossiers/_pieces_jointes.html.haml @@ -23,11 +23,11 @@ = link_to pj.content_url, { target: :blank, rel: :noopener } do %span.filename= display_pj_filename(pj) %span - ajoutée le #{pj.created_at.strftime('%d/%m/%Y à %H:%M')} + ajoutée le #{try_format_datetime(pj.created_at)} - else %td Pièce non fournie %td.updated-at - if pj %span{ class: highlight_if_unseen_class(demande_seen_at, pj.updated_at) } modifié le - = pj.updated_at.strftime("%d/%m/%Y à %H:%M") + = try_format_datetime(pj.updated_at) diff --git a/app/views/shared/dossiers/_submit_is_over.html.haml b/app/views/shared/dossiers/_submit_is_over.html.haml index 9d81a8a96..212f6e00f 100644 --- a/app/views/shared/dossiers/_submit_is_over.html.haml +++ b/app/views/shared/dossiers/_submit_is_over.html.haml @@ -3,6 +3,6 @@ .card-title Le dépôt de dossier est fermé - if dossier.procedure.archived_at.present? - Il n'est plus possible de déposer de dossier pour cette démarche en ligne depuis le #{dossier.procedure.archived_at.strftime("%d/%m/%Y")}. + Il n'est plus possible de déposer de dossier pour cette démarche en ligne depuis le #{try_format_date(dossier.procedure.archived_at)}. - else Il n'est plus possible de déposer de dossier pour cette démarche en ligne. diff --git a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml index 43c6d2b11..1800c94bb 100644 --- a/app/views/shared/dossiers/editable_champs/_champ_label.html.haml +++ b/app/views/shared/dossiers/editable_champs/_champ_label.html.haml @@ -5,7 +5,7 @@ - if champ.updated_at.present? && seen_at.present? %span.updated-at{ class: highlight_if_unseen_class(seen_at, champ.updated_at) } - = "modifié le #{champ.updated_at.strftime('%d/%m/%Y à %H:%M')}" + = "modifié le #{try_format_datetime(champ.updated_at)}" - if champ.description.present? %span.notice= string_to_html(champ.description) diff --git a/app/views/users/dossiers/index.html.haml b/app/views/users/dossiers/index.html.haml index 8d49cd044..9475432c3 100644 --- a/app/views/users/dossiers/index.html.haml +++ b/app/views/users/dossiers/index.html.haml @@ -47,7 +47,7 @@ = render partial: 'shared/dossiers/status_badge', locals: { dossier: dossier } %td.updated-at-col = link_to(url_for_dossier(dossier), class: 'cell-link') do - = dossier.updated_at.strftime("%d/%m/%Y") + = try_format_date(dossier.updated_at) %td.action-col.action-col = render partial: 'dossier_actions', locals: { dossier: dossier } = paginate(@dossiers) diff --git a/spec/views/shared/dossiers/_demande.html.haml_spec.rb b/spec/views/shared/dossiers/_demande.html.haml_spec.rb index 4c1a7d796..c1d28dd72 100644 --- a/spec/views/shared/dossiers/_demande.html.haml_spec.rb +++ b/spec/views/shared/dossiers/_demande.html.haml_spec.rb @@ -38,7 +38,7 @@ describe 'shared/dossiers/demande.html.haml', type: :view do expect(rendered).to include(individual.gender) expect(rendered).to include(individual.nom) expect(rendered).to include(individual.prenom) - expect(rendered).to include(individual.birthdate.strftime("%d/%m/%Y")) + expect(rendered).to include(I18n.l(individual.birthdate)) end end