Add a closing time that stops timers

A new Closing time setting (e.g. 17:00, in each user's time zone): a timer started before closing stops
at closing time and its entry's comment notes it, so no time is logged after closing, even when nobody
stops it until the next day. A timer started after closing is overtime and keeps running, up to the
maximum timer length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BiwYMjhoQvL7XsKKfRz4pM
This commit is contained in:
Claude committed 2026-10-31 08:41:57 -04:00
1 parent 7266f7842a
commit 7349d9cf5a
6 files changed
+108 -4

No files matched your search

+35
View File
@@ -200,4 +200,39 @@ class TimerTest < ActiveSupport::TestCase
@timer.stop_for(by: @user)
refute_includes @time_entry.reload.comments.to_s, 'Timer stopped by'
end
# 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)
end
test "timer started before closing stops at closing time" do
Setting.plugin_stopwatch = Setting.plugin_stopwatch.merge('stop_time' => '17:00')
hours = @time_entry.hours
travel_to(closing_today - 2.hours) { @timer.start @time_entry }
travel_to(closing_today + 3.hours) { @timer.update }
@time_entry.reload
assert_in_delta hours + 2, @time_entry.hours, 0.01
refute @timer.running?
assert_includes @time_entry.comments, '17:00'
ensure
Setting.plugin_stopwatch = Setting.plugin_stopwatch.merge('stop_time' => '')
end
test "timer started after closing keeps running" do
Setting.plugin_stopwatch = Setting.plugin_stopwatch.merge('stop_time' => '17:00')
hours = @time_entry.hours
travel_to(closing_today + 1.hour) { @timer.start @time_entry }
travel_to(closing_today + 3.hours) { @timer.update }
@time_entry.reload
assert_in_delta hours + 2, @time_entry.hours, 0.01
assert @timer.running?
assert_equal 'work', @time_entry.comments
ensure
Setting.plugin_stopwatch = Setting.plugin_stopwatch.merge('stop_time' => '')
end
end