Files
stopwatch/app/controllers/stopwatch_running_timers_controller.rb
T
rickyandClaude Opus 5.5 9c937c6d6b 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>
2026-11-02 18:07:44 -05:00

52 lines
1.7 KiB
Ruby

# Lists everyone's running timers, and lets managers stop a timer someone forgot (optionally at the
# time they actually stopped working).
class StopwatchRunningTimersController < StopwatchController
before_action :authorize_view
def index
@rows = Stopwatch::RunningTimers.visible_to(User.current)
end
def stop
owner = User.find_by(id: params[:user_id])
return render_404 unless owner
timer = Stopwatch::Timer.new(owner)
unless timer.running?
flash[:warning] = l(:notice_stopwatch_timer_not_running, name: owner.name)
return redirect_to stopwatch_running_timers_path
end
row = Stopwatch::RunningTimers::Row.new(user: owner, timer: timer, time_entry: timer.time_entry)
return deny_access unless row.stoppable_by?(User.current)
stop_at = nil
if params[:stopped_at].present?
stop_at = parse_user_time(params[:stopped_at])
unless stop_at
flash[:error] = l(:error_stopwatch_invalid_stop_time)
return redirect_to stopwatch_running_timers_path
end
end
hours = timer.stop_for(at: stop_at, by: User.current)
flash[:notice] = l(:notice_stopwatch_timer_stopped_for, name: owner.name, hours: format_hours(hours.to_f))
redirect_to stopwatch_running_timers_path
end
private
def authorize_view
User.current.allowed_to?(:view_running_timers, nil, global: true) or deny_access
end
# The "stopped at" field is a local date and time in the viewer's time zone, or the server's local time for
# a viewer without one (as Redmine shows times)
def parse_user_time(value)
zone = User.current.time_zone
zone ? zone.parse(value.to_s) : Time.parse(value.to_s)
rescue ArgumentError
nil
end
end