messagerie: better format message dates
This commit is contained in:
parent
fe13871380
commit
211674435e
5 changed files with 57 additions and 1 deletions
|
@ -4,4 +4,10 @@ module CommentaireHelper
|
||||||
"from-me"
|
"from-me"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def commentaire_date(commentaire)
|
||||||
|
is_current_year = (commentaire.created_at.year == Date.current.year)
|
||||||
|
template = is_current_year ? :message_date : :message_date_with_year
|
||||||
|
I18n.l(commentaire.created_at.localtime, format: template)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
- if ![user_email, commentaire.dossier.user.email, OLD_CONTACT_EMAIL, CONTACT_EMAIL].include?(commentaire.email)
|
- if ![user_email, commentaire.dossier.user.email, OLD_CONTACT_EMAIL, CONTACT_EMAIL].include?(commentaire.email)
|
||||||
%span.guest Invité
|
%span.guest Invité
|
||||||
%span.date{ class: highlight_if_unseen_class(messagerie_seen_at, commentaire.created_at) }
|
%span.date{ class: highlight_if_unseen_class(messagerie_seen_at, commentaire.created_at) }
|
||||||
= I18n.l(commentaire.created_at.localtime, format: '%d/%m/%Y à %H:%M ')
|
= commentaire_date(commentaire)
|
||||||
.rich-text= sanitize(commentaire.body)
|
.rich-text= sanitize(commentaire.body)
|
||||||
|
|
||||||
- if commentaire.piece_justificative
|
- if commentaire.piece_justificative
|
||||||
|
|
10
config/locales/time_format.en.rb
Normal file
10
config/locales/time_format.en.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
:en => {
|
||||||
|
:time => {
|
||||||
|
:formats => {
|
||||||
|
:message_date => lambda { |time, _| "%B #{time.day.ordinalize} at %H:%M" },
|
||||||
|
:message_date_with_year => lambda { |time, _| "%B #{time.day.ordinalize} %Y at %H:%M" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
10
config/locales/time_format.fr.rb
Normal file
10
config/locales/time_format.fr.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
{
|
||||||
|
:fr => {
|
||||||
|
:time => {
|
||||||
|
:formats => {
|
||||||
|
:message_date => lambda { |time, _| "le #{time.day == 1 ? '1er' : time.day} %B à %H h %M" },
|
||||||
|
:message_date_with_year => lambda { |time, _| "le #{time.day == 1 ? '1er' : time.day} %B %Y à %H h %M" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,4 +18,34 @@ RSpec.describe CommentaireHelper, type: :helper do
|
||||||
it { is_expected.to eq nil }
|
it { is_expected.to eq nil }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '.commentaire_date' do
|
||||||
|
let(:present_date) { Time.local(2018, 9, 2, 10, 5, 0) }
|
||||||
|
let(:creation_date) { present_date }
|
||||||
|
let(:commentaire) do
|
||||||
|
Timecop.freeze(creation_date) { create(:commentaire, email: "michel@pref.fr") }
|
||||||
|
end
|
||||||
|
|
||||||
|
subject do
|
||||||
|
Timecop.freeze(present_date) { commentaire_date(commentaire) }
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'doesn’t include the creation year' do
|
||||||
|
expect(subject).to eq 'le 2 septembre à 10 h 05'
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when displaying a commentaire created on a previous year' do
|
||||||
|
let(:creation_date) { present_date.prev_year }
|
||||||
|
it 'includes the creation year' do
|
||||||
|
expect(subject).to eq 'le 2 septembre 2017 à 10 h 05'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when formatting the first day of the month' do
|
||||||
|
let(:present_date) { Time.local(2018, 9, 1, 10, 5, 0) }
|
||||||
|
it 'includes the ordinal' do
|
||||||
|
expect(subject).to eq 'le 1er septembre à 10 h 05'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue