Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[34901] Use format_time_as_date to get the locale formatted date

Oliver Günther76bdbd9c50dc
diff --git a/modules/meeting/app/views/meeting_mailer/content_for_review.html.erb b/modules/meeting/app/views/meeting_mailer/content_for_review.html.erb
index fd703f4e074..aa8c466f0aa 100644
--- a/modules/meeting/app/views/meeting_mailer/content_for_review.html.erb
+++ b/modules/meeting/app/views/meeting_mailer/content_for_review.html.erb
@@ -31,7 +31,7 @@ See COPYRIGHT and LICENSE files for more details.
<em><%= @meeting.author %></em>
<ul>
-<li><%=t :label_meeting_date_time %>: <%= format_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>-<%= format_time @meeting.end_time, false %> <%= Time.zone %></li>
+<li><%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>-<%= format_time @meeting.end_time, false %> <%= Time.zone %></li>
<li><%=Meeting.human_attribute_name(:location) %>: <%= @meeting.location %></li>
<li><%=Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %></li>
<li><%=Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %></li>
diff --git a/modules/meeting/app/views/meeting_mailer/content_for_review.text.erb b/modules/meeting/app/views/meeting_mailer/content_for_review.text.erb
index 99f4305929a..c1ff83f4dec 100644
--- a/modules/meeting/app/views/meeting_mailer/content_for_review.text.erb
+++ b/modules/meeting/app/views/meeting_mailer/content_for_review.text.erb
@@ -30,7 +30,7 @@ See COPYRIGHT and LICENSE files for more details.
<%= @meeting.project.name %>: <%= @meeting.title %> (<%= meeting_url(@meeting) %>)
<%= @meeting.author %>
-<%=t :label_meeting_date_time %>: <%= format_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>-<%= format_time @meeting.end_time, false %> <%= Time.zone %>
+<%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>-<%= format_time @meeting.end_time, false %> <%= Time.zone %>
<%= Meeting.human_attribute_name(:location) %>: <%= @meeting.location %>
<%= Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %>
<%= Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %>
diff --git a/modules/meeting/app/views/meeting_mailer/icalendar_notification.html.erb b/modules/meeting/app/views/meeting_mailer/icalendar_notification.html.erb
index d687dfbbb59..76750d317d0 100644
--- a/modules/meeting/app/views/meeting_mailer/icalendar_notification.html.erb
+++ b/modules/meeting/app/views/meeting_mailer/icalendar_notification.html.erb
@@ -4,7 +4,7 @@
<p><%= t(:text_notificiation_invited) %></p>
<ul>
-<li><%=t :label_meeting_date_time %>: <%= format_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>-<%= format_time @meeting.end_time, false %> <%= Time.zone %></li>
+<li><%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>-<%= format_time @meeting.end_time, false %> <%= Time.zone %></li>
<li><%=Meeting.human_attribute_name(:location) %>: <%= @meeting.location %></li>
<li><%=Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %></li>
<li><%=Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %></li>
diff --git a/modules/meeting/app/views/meeting_mailer/icalendar_notification.text.erb b/modules/meeting/app/views/meeting_mailer/icalendar_notification.text.erb
index 3384a3bb255..9e703716699 100644
--- a/modules/meeting/app/views/meeting_mailer/icalendar_notification.text.erb
+++ b/modules/meeting/app/views/meeting_mailer/icalendar_notification.text.erb
@@ -3,7 +3,7 @@
<%= t(:text_notificiation_invited) %>
-<%=t :label_meeting_date_time %>: <%= format_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>-<%= format_time @meeting.end_time, false %> <%= Time.zone %>
+<%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, false %>-<%= format_time @meeting.end_time, false %> <%= Time.zone %>
<%=Meeting.human_attribute_name(:location) %>: <%= @meeting.location %>
<%=Meeting.human_attribute_name(:participants_invited) %>: <%= @meeting.participants.invited.sort.join("; ") %>
<%=Meeting.human_attribute_name(:participants_attended) %>: <%= @meeting.participants.attended.sort.join("; ") %>
diff --git a/modules/meeting/spec/mailers/meeting_mailer_spec.rb b/modules/meeting/spec/mailers/meeting_mailer_spec.rb
index 92d54379039..775c13bc8d6 100644
--- a/modules/meeting/spec/mailers/meeting_mailer_spec.rb
+++ b/modules/meeting/spec/mailers/meeting_mailer_spec.rb
@@ -95,6 +95,38 @@ describe MeetingMailer, type: :mailer do
expect(mail.to).to match_array([watcher1.mail])
end
end
+
+ context 'when the meeting time results in another date' do
+ let(:meeting) do
+ FactoryBot.create :meeting,
+ author: author,
+ project: project,
+ start_time: '2021-11-09T23:00:00 +0100'.to_datetime.utc
+ end
+
+ describe 'it renders november 9th for Berlin zone' do
+ let(:mail) { described_class.content_for_review meeting_agenda, 'meeting_agenda', author }
+
+ it 'renders the mail with the correct locale' do
+ expect(mail.html_part.body).to include('11/09/2021 11:00 PM-12:00 AM (GMT+01:00) Europe/Berlin')
+ expect(mail.text_part.body).to include('11/09/2021 11:00 PM-12:00 AM (GMT+01:00) Europe/Berlin')
+
+ expect(mail.to).to match_array([author.mail])
+ end
+ end
+
+ describe 'it renders november 10th for Tokyo zone' do
+ let(:mail) { described_class.content_for_review meeting_agenda, 'meeting_agenda', watcher1 }
+ let!(:preference) { FactoryBot.create(:user_preference, user: watcher1, time_zone: 'Asia/Tokyo') }
+
+ it 'renders the mail with the correct locale' do
+ expect(mail.text_part.body).to include('11/10/2021 07:00 AM-08:00 AM (GMT+09:00) Asia/Tokyo')
+ expect(mail.html_part.body).to include('11/10/2021 07:00 AM-08:00 AM (GMT+09:00) Asia/Tokyo')
+
+ expect(mail.to).to match_array([watcher1.mail])
+ end
+ end
+ end
end
describe 'icalendar' do
@@ -159,7 +191,7 @@ describe MeetingMailer, type: :mailer do
let!(:preference) { FactoryBot.create(:user_preference, user: watcher1, time_zone: 'Asia/Tokyo') }
let(:mail) { described_class.content_for_review meeting_agenda, 'meeting_agenda', watcher1 }
- it 'renders the mail with the correcet locale' do
+ it 'renders the mail with the correct locale' do
expect(mail.text_part.body).to include('01/19/2021 07:00 PM-08:00 PM (GMT+09:00) Asia/Tokyo')
expect(mail.text_part.body).to include("#{author.name} has put the")
expect(mail.html_part.body).to include('01/19/2021 07:00 PM-08:00 PM (GMT+09:00) Asia/Tokyo')
@@ -168,6 +200,38 @@ describe MeetingMailer, type: :mailer do
expect(mail.to).to match_array([watcher1.mail])
end
end
+
+ context 'when the meeting time results in another date' do
+ let(:meeting) do
+ FactoryBot.create :meeting,
+ author: author,
+ project: project,
+ start_time: '2021-11-09T23:00:00 +0100'.to_datetime.utc
+ end
+
+ describe 'it renders november 9th for Berlin zone' do
+ let(:mail) { described_class.icalendar_notification meeting_agenda, 'meeting_agenda', author }
+
+ it 'renders the mail with the correct locale' do
+ expect(mail.text_part.body).to include('11/09/2021 11:00 PM-12:00 AM (GMT+01:00) Europe/Berlin')
+ expect(mail.html_part.body).to include('11/09/2021 11:00 PM-12:00 AM (GMT+01:00) Europe/Berlin')
+
+ expect(mail.to).to match_array([author.mail])
+ end
+ end
+
+ describe 'it renders november 10th for Tokyo zone' do
+ let(:mail) { described_class.icalendar_notification meeting_agenda, 'meeting_agenda', watcher1 }
+ let!(:preference) { FactoryBot.create(:user_preference, user: watcher1, time_zone: 'Asia/Tokyo') }
+
+ it 'renders the mail with the correct locale' do
+ expect(mail.text_part.body).to include('11/10/2021 07:00 AM-08:00 AM (GMT+09:00) Asia/Tokyo')
+ expect(mail.html_part.body).to include('11/10/2021 07:00 AM-08:00 AM (GMT+09:00) Asia/Tokyo')
+
+ expect(mail.to).to match_array([watcher1.mail])
+ end
+ end
+ end
end
def check_meeting_mail_content(body)