Skip to content

Commit afcd53c

Browse files
committed
handle time zones more robustly
user time zone of '' was freaking out production
1 parent 8d7399a commit afcd53c

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

app/controllers/common/application/before_filters.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,10 @@ def set_session_locale
106106
# set the current timezone, if the user has it configured.
107107
#
108108
def set_session_timezone
109-
Time.zone = current_user.time_zone if logged_in?
109+
Time.zone = current_user.time_zone
110+
rescue ArgumentError # invalid string
111+
Rails.logger.warn "Invalid time zone #{current_user.time_zone} for user #{current_user.login}"
112+
Time.zone = Time.zone_default
110113
end
111114

112115
#

app/models/unauthenticated_user.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,8 @@ def real?
6060
false
6161
end
6262

63+
def time_zone
64+
Time.zone_default
65+
end
66+
6367
end

app/models/user.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ def online?
171171
end
172172

173173
def time_zone
174-
read_attribute(:time_zone) || Time.zone_default
174+
read_attribute(:time_zone).presence || Time.zone_default
175175
end
176176

177177
#

0 commit comments

Comments
 (0)