Closing time in local time for users without a time zone

Users without a time zone in their preferences fell back to UTC, so a 17:00 closing time stopped their
timers hours early (e.g. at noon on a US Eastern server). Like Redmine (User#today), they now get the
server's local time: for closing time, the Running timers page's "stopped at" field, and the "Timer
stopped by" note.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
rickyandClaude Opus 5.5 committed 2026-11-02 18:07:44 -05:00
1 parent 82ffe7ed49
commit 9c937c6d6b
7 files changed
+41 -15

No files matched your search

+2 -1
View File
@@ -54,7 +54,8 @@ class RunningTimersTest < Redmine::IntegrationTest
get '/stopwatch/running_timers'
assert_select "tr#stopwatch-running-timer-#{@worker.id} form.stopwatch-stop-form"
left_at = (2.hours.ago).in_time_zone(Time.zone).strftime('%Y-%m-%dT%H:%M') # 1 hour after starting
# jsmith has no time zone, so the field is in the server's local time
left_at = 2.hours.ago.getlocal.strftime('%Y-%m-%dT%H:%M') # 1 hour after starting
post "/stopwatch/running_timers/#{@worker.id}/stop", params: { stopped_at: left_at }
assert_redirected_to '/stopwatch/running_timers'
+21 -3
View File
@@ -203,9 +203,13 @@ class TimerTest < ActiveSupport::TestCase
# Closing time: timers started before closing stop at it; timers started after closing are overtime
def closing_today(hour = 17)
zone = @user.time_zone || Time.zone
now = Time.now.in_time_zone(zone)
zone.local(now.year, now.month, now.day, hour, 0)
if (zone = @user.time_zone)
now = Time.now.in_time_zone(zone)
zone.local(now.year, now.month, now.day, hour, 0)
else
now = Time.now
Time.local(now.year, now.month, now.day, hour, 0)
end
end
test "timer started before closing stops at closing time" do
@@ -235,4 +239,18 @@ class TimerTest < ActiveSupport::TestCase
ensure
Setting.plugin_stopwatch = Setting.plugin_stopwatch.merge('stop_time' => '')
end
# Redmine treats a user without a time zone as the server's local time (User#today), not UTC
test "closing time without a user time zone is in the server's local time" do
Setting.plugin_stopwatch = Setting.plugin_stopwatch.merge('stop_time' => '17:00')
@user.pref.update!(time_zone: '')
user = User.find(@user.id)
assert_nil user.time_zone
closing = Stopwatch.closing_time_on(Time.now, user)
assert_equal [17, 0], [closing.getlocal.hour, closing.getlocal.min]
assert_equal Time.now.to_date, closing.getlocal.to_date
ensure
Setting.plugin_stopwatch = Setting.plugin_stopwatch.merge('stop_time' => '')
end
end