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

Provide an abbreviated time zone display, and use that in meetings and time entries

Oliver Günther05ffafe7a1ee
diff --git a/lib_static/redmine/i18n.rb b/lib_static/redmine/i18n.rb
index a8e0e980deb..d9b93999538 100644
--- a/lib_static/redmine/i18n.rb
+++ b/lib_static/redmine/i18n.rb
@@ -39,10 +39,10 @@ module Redmine
def self.all_languages
@@all_languages ||= Rails.root.glob("config/locales/**/*.yml")
- .map { |f| f.basename.to_s.split(".").first }
- .reject! { |l| l.start_with?("js-") }
- .uniq
- .sort
+ .map { |f| f.basename.to_s.split(".").first }
+ .reject! { |l| l.start_with?("js-") }
+ .uniq
+ .sort
end
def self.start_of_week
@@ -153,17 +153,32 @@ module Redmine
# @param time [Time] The time to format.
# @param include_date [Boolean] Whether to include the date in the formatted
# output. Defaults to true.
+ # @param time_zone [ActiveSupport::TimeZone] Use a different time zone than the current users's.
+ # If provided, will output the time zone identifier
# @param format [String] The strftime format to use for the time. Defaults
# to the format in `Setting.time_format`.
# @return [String, nil] The formatted time string, or nil if the time is not
# provided.
- def format_time(time, include_date: true, format: Setting.time_format)
+ def format_time(time, include_date: true, time_zone: nil, format: Setting.time_format)
return nil unless time
- local = in_user_zone(time)
+ local =
+ if time_zone
+ time.in_time_zone(time_zone)
+ else
+ in_user_zone(time)
+ end
+
+ parts = []
+ parts << format_date(local) if include_date
+ parts <<
+ if format.blank?
+ ::I18n.l(local, format: :time)
+ else
+ local.strftime(format)
+ end
- (include_date ? "#{format_date(local)} " : "") +
- (format.blank? ? ::I18n.l(local, format: :time) : local.strftime(format))
+ parts.join(" ")
end
##
@@ -188,16 +203,15 @@ module Redmine
##
# Formats an ActiveSupport::TimeZone object into a user-friendly string.
# @param time_zone [ActiveSupport::TimeZone] The time zone to format.
+ # @param period [Timel] The time in which to represent the zone name.
+ # Relevant for DST considerations, e.g. "CET" vs. "CEST".
# @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
+ def friendly_timezone_name(time_zone, period: Time.current)
+ time_zone
+ .tzinfo
+ .period_for_utc(period.utc)
+ .abbreviation
+ .to_s
end
def 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.erb
index 645f710da98..1d364351994 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
@@ -61,13 +61,24 @@
flex_layout(align_items: :center) do |time|
time.with_column do
render(Primer::Beta::Text.new) do
- "#{format_time(@meeting.start_time, include_date: false)} - #{format_time(@meeting.end_time, include_date: false)}"
+ if @meeting.template?
+ time_zone = @series.time_zone
+ start_time = format_time(@meeting.start_time, time_zone:, include_date: false)
+ end_time = format_time(@meeting.end_time, time_zone:, include_date: false)
+ "#{start_time} - #{end_time}"
+ else
+ "#{format_time(@meeting.start_time, include_date: false)} - #{format_time(@meeting.end_time, include_date: false)}"
+ end
end
end
time.with_column(ml: 2) do
render(Primer::Beta::Text.new(color: :subtle, font_size: :small)) do
- formatted_time_zone_offset
+ if @meeting.template?
+ friendly_timezone_name(@series.time_zone, period: @meeting.start_time)
+ else
+ friendly_timezone_name(User.current.time_zone, period: @meeting.start_time)
+ end
end
end
end
diff --git a/modules/meeting/app/models/recurring_meeting.rb b/modules/meeting/app/models/recurring_meeting.rb
index 9f53985b45f..16b74e3a7a2 100644
--- a/modules/meeting/app/models/recurring_meeting.rb
+++ b/modules/meeting/app/models/recurring_meeting.rb
@@ -134,6 +134,11 @@ class RecurringMeeting < ApplicationRecord
super&.in_time_zone(time_zone)
end
+ def time_zone
+ time_zone_string = super || Setting.user_default_timezone.presence || "Etc/UTC"
+ ActiveSupport::TimeZone[time_zone_string]
+ end
+
def schedule
@schedule ||= IceCube::Schedule.new(start_time, duration: template&.duration).tap do |s|
s.add_recurrence_rule count_rule(frequency_rule)
@@ -161,20 +166,21 @@ class RecurringMeeting < ApplicationRecord
end
def full_schedule_in_words # rubocop:disable Metrics/AbcSize
+ time = "#{format_time(start_time, time_zone:, include_date: false)} (#{friendly_timezone_name(time_zone)})"
if has_ended?
I18n.t("recurring_meeting.in_words.full_past",
base: base_schedule,
- time: format_time(start_time, include_date: false),
+ time:,
end_date: format_date(last_occurrence))
elsif will_end?
I18n.t("recurring_meeting.in_words.full",
base: base_schedule,
- time: format_time(start_time, include_date: false),
+ time:,
end_date: format_date(last_occurrence))
else
I18n.t("recurring_meeting.in_words.never_ending",
base: base_schedule,
- time: format_time(start_time, include_date: false))
+ time:)
end
end
diff --git a/modules/meeting/spec/features/recurring_meetings/recurring_meeting_crud_spec.rb b/modules/meeting/spec/features/recurring_meetings/recurring_meeting_crud_spec.rb
index 09e711c2cff..142a4d2ac4a 100644
--- a/modules/meeting/spec/features/recurring_meetings/recurring_meeting_crud_spec.rb
+++ b/modules/meeting/spec/features/recurring_meetings/recurring_meeting_crud_spec.rb
@@ -151,7 +151,7 @@ RSpec.describe "Recurring meetings CRUD",
it "can edit the details of a recurring meeting" do
show_page.visit!
- show_page.expect_subtitle text: "Every week on Tuesday at 01:30 PM, ends on 01/14/2025"
+ show_page.expect_subtitle text: "Every week on Tuesday at 01:30 PM (UTC), ends on 01/14/2025"
show_page.edit_meeting_series
show_page.within_modal "Edit Meeting" do
@@ -164,7 +164,7 @@ RSpec.describe "Recurring meetings CRUD",
click_link_or_button("Save")
end
wait_for_network_idle
- show_page.expect_subtitle text: "Every day at 11:00 AM, ends on 01/07/2025"
+ show_page.expect_subtitle text: "Every day at 11:00 AM (UTC), ends on 01/07/2025"
end
it "shows the correct actions based on status" do
diff --git a/modules/meeting/spec/requests/recurring_meetings/recurring_meetings_dst_spec.rb b/modules/meeting/spec/requests/recurring_meetings/recurring_meetings_dst_spec.rb
index e938fd12e1b..3eadd596410 100644
--- a/modules/meeting/spec/requests/recurring_meetings/recurring_meetings_dst_spec.rb
+++ b/modules/meeting/spec/requests/recurring_meetings/recurring_meetings_dst_spec.rb
@@ -74,7 +74,8 @@ RSpec.describe "Recurring meetings show DST",
it "shows a stable 10AM schedule time" do
request
- expect(page).to have_text "Every week on Wednesday at 10:00 AM, ends on 05/07/2025"
+ timezone = friendly_timezone_name(berlin_user.time_zone)
+ expect(page).to have_text "Every week on Wednesday at 10:00 AM (#{timezone}), ends on 05/07/2025"
expect(page).to have_text "March 5, 2025 10:00"
expect(page).to have_text "March 12, 2025 10:00"
expect(page).to have_text "March 19, 2025 10:00"
@@ -86,10 +87,11 @@ RSpec.describe "Recurring meetings show DST",
context "with tokyo user that doesn't have DST" do
let(:current_user) { tokyo_user }
- it "changes times according to the CET DST" do
+ it "changes times according to the CET DST, but keeps the heading" do
request
- expect(page).to have_text "Every week on Wednesday at 06:00 PM, ends on 05/07/2025"
+ timezone = friendly_timezone_name(berlin_user.time_zone)
+ expect(page).to have_text "Every week on Wednesday at 10:00 AM (#{timezone}), ends on 05/07/2025"
expect(page).to have_text "March 5, 2025 18:00"
expect(page).to have_text "March 12, 2025 18:00"
expect(page).to have_text "March 19, 2025 18:00"