From de51ef0ce5132e65efa978e17ed3d4b184b14aa5 Mon Sep 17 00:00:00 2001 From: Echo Date: Mon, 1 Dec 2025 10:57:09 -0500 Subject: [PATCH] fix bad timezone handling (#670) --- app/models/user.rb | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 500336e..e80e533 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -209,11 +209,22 @@ class User < ApplicationRecord end def parse_and_set_timezone(timezone) - begin - tz = ActiveSupport::TimeZone.find_tzinfo(timezone) - self.timezone = tz.name - rescue TZInfo::InvalidTimezoneIdentifier => e - Rails.logger.error "Invalid timezone #{timezone} for user #{id}: #{e.message}" + as_tz = ActiveSupport::TimeZone[timezone] + + unless as_tz + begin + tzinfo = TZInfo::Timezone.get(timezone) + as_tz = ActiveSupport::TimeZone.all.find do |z| + z.tzinfo.identifier == tzinfo.identifier + end + rescue TZInfo::InvalidTimezoneIdentifier + end + end + + if as_tz + self.timezone = as_tz.name + else + Rails.logger.error "Invalid timezone #{timezone} for user #{id}" end end