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

move the friendly_timezone_name helper into Redmine::I18n

Klaus Zanders96fa068299c0
diff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rb
index 52dfcf29864..c5099fd75d1 100644
--- a/lib_static/redmine/i18n.rb
+++ b/lib_static/redmine/i18n.rb
@@ -172,6 +172,21 @@ module Redmine
"UTC#{user.time_zone.now.formatted_offset}"
end
+ ##
+ # Formats an ActiveSupport::TimeZone object into a user-friendly string.
+ # @param time_zone [ActiveSupport::TimeZone] The time zone to format.
+ # @return [String] The formatted time zone string.
+ def friendly_timezone_name(time_zone)
+ tz_info = time_zone.tzinfo
+
+ if tz_info.canonical_zone.name == "Etc/UTC"
+ "UTC"
+ else
+ friendly_names = ActiveSupport::TimeZone::MAPPING.select { |_, v| v == tz_info.canonical_zone.name }.keys.sort
+ "(UTC#{ActiveSupport::TimeZone.seconds_to_utc_offset(tz_info.base_utc_offset)}) #{friendly_names.join(', ')}"
+ end
+ end
+
def day_name(day)
::I18n.t("date.day_names")[day % 7]
end
diff --git a/modules/costs/app/controllers/time_entries_controller.rb b/modules/costs/app/controllers/time_entries_controller.rb
index 3cc1e5d412c..81a503b461b 100644
--- a/modules/costs/app/controllers/time_entries_controller.rb
+++ b/modules/costs/app/controllers/time_entries_controller.rb
@@ -31,6 +31,7 @@
class TimeEntriesController < ApplicationController
include OpTurbo::ComponentStream
include OpTurbo::DialogStreamHelper
+ include Redmine::I18n
before_action :require_login
@@ -57,7 +58,7 @@ class TimeEntriesController < ApplicationController
def user_tz_caption
user = User.visible.find_by(id: params[:user_id])
caption = if user && user.time_zone != User.current.time_zone
- I18n.t("notice_different_time_zones", tz: helpers.friendly_timezone_name(user.time_zone))
+ I18n.t("notice_different_time_zones", tz: friendly_timezone_name(user.time_zone))
else
""
end
diff --git a/modules/costs/app/helpers/time_entries_helper.rb b/modules/costs/app/helpers/time_entries_helper.rb
deleted file mode 100644
index 17f1db98424..00000000000
--- a/modules/costs/app/helpers/time_entries_helper.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-# frozen_string_literal: true
-
-#-- copyright
-# OpenProject is an open source project management software.
-# Copyright (C) the OpenProject GmbH
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License version 3.
-#
-# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
-# Copyright (C) 2006-2013 Jean-Philippe Lang
-# Copyright (C) 2010-2013 the ChiliProject Team
-#
-# This program is free software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# See COPYRIGHT and LICENSE files for more details.
-#++
-
-module TimeEntriesHelper
- def friendly_timezone_name(time_zone)
- tz_info = time_zone.tzinfo
- friendly_name = ActiveSupport::TimeZone::MAPPING.key(tz_info.canonical_zone.name)
-
- "(UTC#{ActiveSupport::TimeZone.seconds_to_utc_offset(tz_info.base_utc_offset)}) #{friendly_name}"
- end
-end
diff --git a/modules/costs/spec/controllers/time_entries_controller_spec.rb b/modules/costs/spec/controllers/time_entries_controller_spec.rb
index 38f0727c2c1..a504b7c3636 100644
--- a/modules/costs/spec/controllers/time_entries_controller_spec.rb
+++ b/modules/costs/spec/controllers/time_entries_controller_spec.rb
@@ -31,6 +31,7 @@
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper.rb")
RSpec.describe TimeEntriesController do
+ include Redmine::I18n
let(:user) { create(:user) }
let(:other_user) { create(:user) }
@@ -271,7 +272,7 @@ RSpec.describe TimeEntriesController do
get :user_tz_caption, params: { user_id: other_user.id }, format: :turbo_stream
expect(response.body).to include(
"caption=\"#{I18n.t('notice_different_time_zones',
- tz: described_class.helpers.friendly_timezone_name(other_user.time_zone))}\""
+ tz: friendly_timezone_name(other_user.time_zone))}\""
)
end
end
diff --git a/modules/costs/spec/features/time_entry_dialog_spec.rb b/modules/costs/spec/features/time_entry_dialog_spec.rb
index 2aa2a60a0f9..f639a62d499 100644
--- a/modules/costs/spec/features/time_entry_dialog_spec.rb
+++ b/modules/costs/spec/features/time_entry_dialog_spec.rb
@@ -31,6 +31,8 @@
require File.expand_path("#{File.dirname(__FILE__)}/../spec_helper.rb")
RSpec.describe "time entry dialog", :js, with_flag: :track_start_and_end_times_for_time_entries do
+ include Redmine::I18n
+
shared_let(:project) { create(:project_with_types) }
shared_let(:work_package_a) { create(:work_package, subject: "WP A", project:) }
@@ -118,7 +120,7 @@ RSpec.describe "time entry dialog", :js, with_flag: :track_start_and_end_times_f
time_logging_modal.update_field("user_id", other_user.name)
time_logging_modal.expect_user(other_user)
- time_logging_modal.shows_caption(I18n.t("notice_different_time_zones", tz: "(UTC+09:00) Osaka"))
+ time_logging_modal.shows_caption(I18n.t("notice_different_time_zones", tz: friendly_timezone_name(other_user.time_zone)))
end
end