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

nil memoized tz variable on reload

ulferts1d7fd3c2ec23
diff --git a/app/models/user.rb b/app/models/user.rb
index 96f11b04dd3..c88ad590823 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -409,6 +409,12 @@ class User < Principal
@time_zone ||= (pref.time_zone.blank? ? nil : ActiveSupport::TimeZone[pref.time_zone])
end
+ def reload(*)
+ @time_zone = nil
+
+ super
+ end
+
def wants_comments_in_reverse_order?
pref.comments_in_reverse_order?
end
diff --git a/modules/meeting/app/mailers/meeting_mailer.rb b/modules/meeting/app/mailers/meeting_mailer.rb
index 817962f41c3..fa026b3eb58 100644
--- a/modules/meeting/app/mailers/meeting_mailer.rb
+++ b/modules/meeting/app/mailers/meeting_mailer.rb
@@ -63,8 +63,6 @@ class MeetingMailer < UserMailer
set_headers @meeting
with_attached_ics(meeting, user) do
- timezone = Time.zone || Time.zone_default
- @formatted_timezone = format_timezone_offset timezone, @meeting.start_time
subject = "[#{@meeting.project.name}] #{@meeting.title}"
mail(to: user, subject:)
end
@@ -95,9 +93,4 @@ class MeetingMailer < UserMailer
headers["Content-Type"] = 'text/calendar; charset=utf-8; method="PUBLISH"; name="meeting.ics"'
headers["Content-Transfer-Encoding"] = "8bit"
end
-
- def format_timezone_offset(timezone, time)
- offset = ::ActiveSupport::TimeZone.seconds_to_utc_offset time.utc_offest_for_timezone(timezone), true
- "(GMT#{offset}) #{timezone.name}"
- end
end
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 9e194f38d65..4c2129253fb 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_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> <%= @formatted_timezone %></li>
+<li><%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)</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 6ccc85941ff..077cc974d31 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_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> <%= @formatted_timezone %>
+<%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)
<%=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/invited.html.erb b/modules/meeting/app/views/meeting_mailer/invited.html.erb
index 2bc6b23b144..499075a3b73 100644
--- a/modules/meeting/app/views/meeting_mailer/invited.html.erb
+++ b/modules/meeting/app/views/meeting_mailer/invited.html.erb
@@ -47,7 +47,7 @@ See COPYRIGHT and LICENSE files for more details.
<td style="<%= placeholder_text_styles %>">
<%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>
-
- <%= format_time @meeting.end_time, include_date: false %> <%= Time.zone %>
+ <%= format_time @meeting.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)
</td>
</tr>
<% if @meeting.location.present? %>
diff --git a/modules/meeting/app/views/meeting_mailer/invited.text.erb b/modules/meeting/app/views/meeting_mailer/invited.text.erb
index 3471877f970..36f7ce7116a 100644
--- a/modules/meeting/app/views/meeting_mailer/invited.text.erb
+++ b/modules/meeting/app/views/meeting_mailer/invited.text.erb
@@ -32,7 +32,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_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> <%= Time.zone %>
+<%=t :label_meeting_date_time %>: <%= format_time_as_date @meeting.start_time %> <%= format_time @meeting.start_time, include_date: false %>-<%= format_time @meeting.end_time, include_date: false %> (<%= formatted_time_zone_offset %>)
<%= 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/rescheduled.html.erb b/modules/meeting/app/views/meeting_mailer/rescheduled.html.erb
index 456e625769c..b0cd462ebbb 100644
--- a/modules/meeting/app/views/meeting_mailer/rescheduled.html.erb
+++ b/modules/meeting/app/views/meeting_mailer/rescheduled.html.erb
@@ -48,7 +48,7 @@ See COPYRIGHT and LICENSE files for more details.
<s>
<%= format_time_as_date @changes[:old_start] %> <%= format_time @changes[:old_start], include_date: false %>
-
- <%= format_time (@changes[:old_start] + @changes[:old_duration].hours), include_date: false %> <%= formatted_time_zone_offset %>
+ <%= format_time (@changes[:old_start] + @changes[:old_duration].hours), include_date: false %> (<%= formatted_time_zone_offset %>)
</s>
</td>
</tr>
@@ -59,7 +59,7 @@ See COPYRIGHT and LICENSE files for more details.
<td style="<%= placeholder_text_styles('font-weight': 'bold') %>">
<%= format_time_as_date @changes[:new_start] %> <%= format_time @changes[:new_start], include_date: false %>
-
- <%= format_time (@changes[:new_start] + @changes[:new_duration].hours), include_date: false %> <%= formatted_time_zone_offset %>
+ <%= format_time (@changes[:new_start] + @changes[:new_duration].hours), include_date: false %> (<%= formatted_time_zone_offset %>)
</td>
</tr>
<% if @meeting.location.present? %>
diff --git a/modules/meeting/app/views/meeting_mailer/rescheduled.text.erb b/modules/meeting/app/views/meeting_mailer/rescheduled.text.erb
index 911558e4a84..78810123703 100644
--- a/modules/meeting/app/views/meeting_mailer/rescheduled.text.erb
+++ b/modules/meeting/app/views/meeting_mailer/rescheduled.text.erb
@@ -35,7 +35,7 @@ See COPYRIGHT and LICENSE files for more details.
title: @meeting.title) %>
<%= t('meeting.email.rescheduled.old_date_time') %>:
-<%= format_time_as_date @changes[:old_start] %> <%= format_time @changes[:old_start], include_date: false %> - <%= format_time (@changes[:old_start] + @changes[:old_duration]), include_date: false %> <%= Time.zone %>
+<%= format_time_as_date @changes[:old_start] %> <%= format_time @changes[:old_start], include_date: false %> - <%= format_time (@changes[:old_start] + @changes[:old_duration]), include_date: false %> (<%= formatted_time_zone_offset %>}
<%= t('meeting.email.rescheduled.new_date_time') %>:
-<%= format_time_as_date @changes[:new_start] %> <%= format_time @changes[:new_start], include_date: false %> - <%= format_time (@changes[:new_start] + @changes[:new_duration]), include_date: false %> <%= Time.zone %>
+<%= format_time_as_date @changes[:new_start] %> <%= format_time @changes[:new_start], include_date: false %> - <%= format_time (@changes[:new_start] + @changes[:new_duration]), include_date: false %> (<%= formatted_time_zone_offset %>}
diff --git a/modules/meeting/spec/mailers/meeting_mailer_spec.rb b/modules/meeting/spec/mailers/meeting_mailer_spec.rb
index 65c74116800..b5fc84a3747 100644
--- a/modules/meeting/spec/mailers/meeting_mailer_spec.rb
+++ b/modules/meeting/spec/mailers/meeting_mailer_spec.rb
@@ -47,6 +47,8 @@ RSpec.describe MeetingMailer do
let(:meeting_agenda) do
create(:meeting_agenda, meeting:)
end
+ let(:tokyo_offset) { "UTC#{ActiveSupport::TimeZone['Asia/Tokyo'].now.formatted_offset}" }
+ let(:berlin_offset) { "UTC#{ActiveSupport::TimeZone['Europe/Berlin'].now.formatted_offset}" }
before do
User.current = author
@@ -88,11 +90,9 @@ RSpec.describe MeetingMailer do
context "with a recipient with another time zone" do
let!(:preference) { watcher1.pref.update(time_zone: "Asia/Tokyo") }
- it "renders the mail with the correcet locale" do
- expect(mail.text_part.body).to include("Tokyo")
- expect(mail.text_part.body).to include("GMT+09:00")
- expect(mail.html_part.body).to include("Tokyo")
- expect(mail.html_part.body).to include("GMT+09:00")
+ it "renders the mail with the correct locale" do
+ expect(mail.text_part.body).to include(tokyo_offset)
+ expect(mail.html_part.body).to include(tokyo_offset)
expect(mail.to).to contain_exactly(watcher1.mail)
end
@@ -111,8 +111,8 @@ RSpec.describe MeetingMailer do
it "renders the mail with the correct locale" do
expect(mail.html_part.body).to include("11/09/2021 11:00 PM")
- expect(mail.html_part.body).to include("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.html_part.body).to include("12:00 AM (#{berlin_offset})")
+ expect(mail.text_part.body).to include("11/09/2021 11:00 PM-12:00 AM (#{berlin_offset})")
expect(mail.to).to contain_exactly(author.mail)
end
@@ -124,9 +124,9 @@ RSpec.describe MeetingMailer do
it "renders the mail with the correct locale" do
expect(mail.html_part.body).to include("11/10/2021 07:00 AM")
- expect(mail.html_part.body).to include("08:00 AM (GMT+09:00) Asia/Tokyo")
+ expect(mail.html_part.body).to include("08:00 AM (#{tokyo_offset})")
- expect(mail.text_part.body).to include("11/10/2021 07:00 AM-08:00 AM (GMT+09:00) Asia/Tokyo")
+ expect(mail.text_part.body).to include("11/10/2021 07:00 AM-08:00 AM (#{tokyo_offset})")
expect(mail.to).to contain_exactly(watcher1.mail)
end
@@ -160,7 +160,7 @@ RSpec.describe MeetingMailer do
expect(body).to include(meeting.project.name)
expect(body).to include(meeting.title)
expect(body).to include(meeting.location)
- expect(body).to include("01/19/2021 11:00 AM-12:00 PM (GMT+01:00) Europe/Berlin")
+ expect(body).to include("01/19/2021 11:00 AM-12:00 PM (#{berlin_offset})")
expect(body).to include(meeting.participants[0].name)
expect(body).to include(meeting.participants[1].name)
end
@@ -174,7 +174,7 @@ RSpec.describe MeetingMailer do
expect(body).to include(meeting.title)
expect(body).to include(meeting.location)
expect(body).to include("01/19/2021 11:00 AM")
- expect(body).to include("12:00 PM (GMT+01:00) Europe/Berlin")
+ expect(body).to include("12:00 PM (#{berlin_offset})")
expect(body).to include(meeting.participants[0].name)
expect(body).to include(meeting.participants[1].name)
end
@@ -207,9 +207,9 @@ RSpec.describe MeetingMailer do
let(:mail) { described_class.icalendar_notification(meeting, watcher1, author) }
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("01/19/2021 07:00 PM-08:00 PM (#{tokyo_offset})")
expect(mail.html_part.body).to include("01/19/2021 07:00 PM")
- expect(mail.html_part.body).to include("08:00 PM (GMT+09:00) Asia/Tokyo")
+ expect(mail.html_part.body).to include("08:00 PM (#{tokyo_offset})")
expect(mail.to).to contain_exactly(watcher1.mail)
end
@@ -227,9 +227,9 @@ RSpec.describe MeetingMailer do
let(:mail) { described_class.icalendar_notification(meeting, author, 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.text_part.body).to include("11/09/2021 11:00 PM-12:00 AM (#{berlin_offset})")
expect(mail.html_part.body).to include("11/09/2021 11:00 PM")
- expect(mail.html_part.body).to include("12:00 AM (GMT+01:00) Europe/Berlin")
+ expect(mail.html_part.body).to include("12:00 AM (#{berlin_offset})")
expect(mail.to).to contain_exactly(author.mail)
end
@@ -240,8 +240,8 @@ RSpec.describe MeetingMailer do
let!(:preference) { watcher1.pref.update(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.text_part.body).to include("11/10/2021 07:00 AM-08:00 AM (#{tokyo_offset})")
+ expect(mail.html_part.body).to include("11/10/2021 07:00 AM-08:00 AM (#{tokyo_offset})")
expect(mail.to).to contain_exactly(watcher1.mail)
end
@@ -255,6 +255,7 @@ RSpec.describe MeetingMailer do
expect(body).to include(i18n.format_date(meeting.start_date))
expect(body).to include(i18n.format_time(meeting.start_time, include_date: false))
expect(body).to include(i18n.format_time(meeting.end_time, include_date: false))
+ expect(body).to include(i18n.formatted_time_zone_offset)
expect(body).to include(meeting.participants[0].name)
expect(body).to include(meeting.participants[1].name)
end
diff --git a/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb b/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
index 8aa1e05291e..0c23e3199c3 100644
--- a/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
+++ b/spec/lib/api/v3/user_preferences/user_preference_representer_rendering_spec.rb
@@ -62,8 +62,8 @@ RSpec.describe API::V3::UserPreferences::UserPreferenceRepresenter,
context "without a timezone set" do
let(:preference) { build(:user_preference, time_zone: "") }
- it "shows the timeZone as nil" do
- expect(subject).to be_json_eql(nil.to_json).at_path("timeZone")
+ it "shows the timeZone as utc" do
+ expect(subject).to be_json_eql("Etc/UTC".to_json).at_path("timeZone")
end
end
diff --git a/spec/models/deleted_user_spec.rb b/spec/models/deleted_user_spec.rb
index 03193804152..5b477505d99 100644
--- a/spec/models/deleted_user_spec.rb
+++ b/spec/models/deleted_user_spec.rb
@@ -48,7 +48,7 @@ RSpec.describe DeletedUser do
end
describe "#time_zone" do
- it { expect(user.time_zone).to be_nil }
+ it { expect(user.time_zone).to eql ActiveSupport::TimeZone["Etc/UTC"] }
end
describe "#rss_key" do
diff --git a/spec/models/users/default_timezone_spec.rb b/spec/models/users/default_timezone_spec.rb
index e0a83088ce7..f0f2b6e5cf6 100644
--- a/spec/models/users/default_timezone_spec.rb
+++ b/spec/models/users/default_timezone_spec.rb
@@ -32,8 +32,8 @@ RSpec.describe User, "default time zone" do
let(:user) { create(:user) }
context "with no system default set" do
- it "is not set" do
- expect(user.pref.time_zone).to be_nil
+ it "is still set to Etc/UTC as that will be calculated with internally" do
+ expect(user.pref.time_zone).to eq "Etc/UTC"
end
end