mirror of
https://github.com/rickbarrette/stopwatch.git
synced 2026-11-17 19:50:36 -05:00
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:
6 files changed
+108
-4
No files matched your search
@@ -51,6 +51,26 @@ module Stopwatch
|
||||
hours.positive? ? hours : nil
|
||||
end
|
||||
|
||||
# Closing time (stop time), as [hour, minute], or nil when none is set. Timers started before closing
|
||||
# stop at closing time; timers started after closing (overtime) keep running.
|
||||
def self.stop_time
|
||||
value = settings['stop_time'].to_s.strip
|
||||
return nil unless (m = value.match(/\A(\d{1,2}):(\d{2})\z/))
|
||||
|
||||
hour, minute = m[1].to_i, m[2].to_i
|
||||
hour < 24 && minute < 60 ? [hour, minute] : nil
|
||||
end
|
||||
|
||||
# Closing time on the day of the given time, in the user's time zone, or nil when no stop time is set
|
||||
def self.closing_time_on(time, user)
|
||||
hour, minute = stop_time
|
||||
return nil unless hour
|
||||
|
||||
zone = user.time_zone || Time.zone
|
||||
day = time.in_time_zone(zone)
|
||||
zone.local(day.year, day.month, day.day, hour, minute)
|
||||
end
|
||||
|
||||
# Colour-code the issue Start/Stop links (green to start, red to stop)
|
||||
def self.highlighted_links
|
||||
settings['highlighted_links'].to_s == '1'
|
||||
|
||||
Reference in new issue
Block a user