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
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
factor DST into the calculation of the formatted time zone offset
ulfertsb27f164486e2
diff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rbindex 5c107025668..534884af36e 100644--- a/lib_static/redmine/i18n.rb+++ b/lib_static/redmine/i18n.rb@@ -144,8 +144,14 @@ module Redmine(Setting.time_format.blank? ? ::I18n.l(local, format: :time) : local.strftime(Setting.time_format))end- def format_time_zone- User.current.time_zone.to_s[/\((.*?)\)/m, 1]+ # Returns the offset to UTC (with utc prepended) currently active+ # in the current users time zone. DST is factored in so the offset can+ # shift over the course of the year+ def formatted_time_zone_offset+ # Doing User.current.time_zone and format that will not take heed of DST as it has no notion+ # of a current time.+ # https://github.com/rails/rails/issues/7297+ "UTC#{User.current.time_zone.now.formatted_offset}"enddef day_name(day)diff --git a/modules/meeting/app/components/meetings/side_panel/details_component.html.erb b/modules/meeting/app/components/meetings/side_panel/details_component.html.erbindex b7425f44e1a..2431e0f8f0c 100644--- a/modules/meeting/app/components/meetings/side_panel/details_component.html.erb+++ b/modules/meeting/app/components/meetings/side_panel/details_component.html.erb@@ -36,7 +36,7 @@time.with_column(ml: 2) dorender(Primer::Beta::Text.new(color: :subtle, font_size: :small)) do- format_time_zone+ formatted_time_zone_offsetendendenddiff --git a/modules/meeting/app/controllers/meetings_controller.rb b/modules/meeting/app/controllers/meetings_controller.rbindex f7cadcbf7eb..44fcb157e7e 100644--- a/modules/meeting/app/controllers/meetings_controller.rb+++ b/modules/meeting/app/controllers/meetings_controller.rb@@ -290,14 +290,7 @@ class MeetingsController < ApplicationControllerenddef set_time_zone(&)- zone = User.current.time_zone- if zone.nil?- localzone = Time.current.utc_offset- localzone -= 3600 if Time.current.dst?- zone = ::ActiveSupport::TimeZone[localzone]- end-- Time.use_zone(zone, &)+ Time.use_zone(User.current.time_zone, &)enddef build_meetingdiff --git a/modules/meeting/app/forms/meeting/start_time.rb b/modules/meeting/app/forms/meeting/start_time.rbindex 15fbf9e9649..36b43092839 100644--- a/modules/meeting/app/forms/meeting/start_time.rb+++ b/modules/meeting/app/forms/meeting/start_time.rb@@ -38,7 +38,7 @@ class Meeting::StartTime < ApplicationFormlabel: Meeting.human_attribute_name(:start_time),leading_visual: { icon: :clock },required: true,- caption: format_time_zone+ caption: formatted_time_zone_offset)enddiff --git a/spec/lib/redmine/i18n_spec.rb b/spec/lib/redmine/i18n_spec.rbindex e2dabf1727b..3c4ceaf4256 100644--- a/spec/lib/redmine/i18n_spec.rb+++ b/spec/lib/redmine/i18n_spec.rb@@ -382,16 +382,17 @@ module OpenProjectendend- describe "#format_time_zone" do+ describe "#formatted_time_zone_offset" docurrent_user { build_stubbed(:user, preferences: { time_zone: user_time_zone }) }let(:user_time_zone) { "" }+ let(:berlin_gmt) { ActiveSupport::TimeZone["Europe/Berlin"].now.utc_offset == 7200 ? "UTC+02:00" : "UTC+01:00" }+context "with the current user having set a time zone" do- let(:user_time_zone) { "Kathmandu" }+ let(:user_time_zone) { "Europe/Berlin" }it "renders the time zone of the user" do- # No DST in this time zone so the expectation should be constant.- expect(format_time_zone).to eql "GMT+05:45"+ expect(formatted_time_zone_offset).to eql berlin_gmtendend@@ -399,27 +400,25 @@ module OpenProjectlet(:user_time_zone) { "" }it "renders the UTC time zone" do- expect(format_time_zone).to eql "GMT+00:00"+ expect(formatted_time_zone_offset).to eql "UTC+00:00"endendcontext "without the current user having a time zone but with a default one configured",- with_settings: { user_default_timezone: "Kathmandu" } do+ with_settings: { user_default_timezone: "Europe/Berlin" } dolet(:user_time_zone) { "" }it "renders the default time zone" do- # No DST in this time zone so the expectation should be constant.- expect(format_time_zone).to eql "GMT+05:45"+ expect(formatted_time_zone_offset).to eql berlin_gmtendendcontext "without the current user having a time zone and also a default one configured",- with_settings: { user_default_timezone: "Atlanta" } do- let(:user_time_zone) { "Kathmandu" }+ with_settings: { user_default_timezone: "America/Atlanta" } do+ let(:user_time_zone) { "Europe/Berlin" }it "renders the default time zone" do- # No DST in this time zone so the expectation should be constant.- expect(format_time_zone).to eql "GMT+05:45"+ expect(formatted_time_zone_offset).to eql berlin_gmtendendend