Handle offset relative to TZ in options list (#39334)

This commit is contained in:
Matt Jankowski 2026-06-09 08:58:45 -04:00 committed by GitHub
parent a2064d4c7f
commit e9697922c1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View File

@ -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)

View File

@ -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

View File

@ -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