From e9697922c1d660337980ecf0d5d957b16d725fc6 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Tue, 9 Jun 2026 08:58:45 -0400 Subject: [PATCH] Handle offset relative to TZ in options list (#39334) --- app/helpers/settings_helper.rb | 4 ++++ .../preferences/appearance/show.html.haml | 2 +- spec/helpers/settings_helper_spec.rb | 16 ++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index 196eac52d5..11786b22fe 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -57,6 +57,10 @@ module SettingsHelper end end + def time_zone_options + ActiveSupport::TimeZone.all.map { |tz| ["(GMT#{tz.now.formatted_offset}) #{tz.name}", tz.tzinfo.name] } + end + private def links_for_featured_tags(tags) diff --git a/app/views/settings/preferences/appearance/show.html.haml b/app/views/settings/preferences/appearance/show.html.haml index 202dd53103..9488972705 100644 --- a/app/views/settings/preferences/appearance/show.html.haml +++ b/app/views/settings/preferences/appearance/show.html.haml @@ -16,7 +16,7 @@ wrapper: :with_label .fields-group.fields-row__column.fields-row__column-6 = f.input :time_zone, - collection: ActiveSupport::TimeZone.all.map { |tz| ["(GMT#{tz.formatted_offset}) #{tz.name}", tz.tzinfo.name] }, + collection: time_zone_options, hint: false, selected: current_user.time_zone || Time.zone.tzinfo.name, wrapper: :with_label diff --git a/spec/helpers/settings_helper_spec.rb b/spec/helpers/settings_helper_spec.rb index 63773634e9..d45940b57b 100644 --- a/spec/helpers/settings_helper_spec.rb +++ b/spec/helpers/settings_helper_spec.rb @@ -50,4 +50,20 @@ RSpec.describe SettingsHelper do end end end + + describe '#time_zone_options' do + subject { helper.time_zone_options } + + context 'when summer time is in effect' do + before { travel_to(Date.new(2026, 6, 1)) } + + it { is_expected.to include(['(GMT-08:00) Alaska', 'America/Juneau']) } + end + + context 'when summer time is not in effect' do + before { travel_to(Date.new(2025, 12, 1)) } + + it { is_expected.to include(['(GMT-09:00) Alaska', 'America/Juneau']) } + end + end end