mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-11-17 19:50:36 -05:00
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:
1 parent
82ffe7ed49
commit
9c937c6d6b
7 files changed
+41
-15
No files matched your search
+21
-3
@@ -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
|
||||
Reference in new issue
Block a user