fix(ministry): correct lost and stale time in the ministry timer - #5401
fix(ministry): correct lost and stale time in the ministry timer#5401ux-git wants to merge 1 commit into
Conversation
…unter The elapsed time was kept in a counter that a background tab stops advancing, so a session that ran while the phone was asleep was saved short, and pausing froze the counter instead of the time that had really passed. The elapsed time is now read from the moment the session started, which the timer already stored, so a suspended tab only delays the display and never the total. The counter also had to be copied back into the view after every change, and the copy was skipped whenever the value before and after a stop matched, which left the stopped timer showing the time of the session that had just ended. Nothing is copied any more. A session that runs past midnight is now reported on the day it started, so it stays in the month the publisher went out, and the day is kept in the timer record so that it survives a reload. Seconds are rounded instead of dropped, a clock corrected backwards can no longer show a negative duration, and stopping a session too short to record says so instead of resetting silently.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reachedNext included review available in 16 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Team Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (4)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|



Description
Two problems were reported from real use on phones: after stopping a session and saving it, the timer kept showing the time of the session that had just ended until the page was left and opened again, and a session that ran for two or three hours was sometimes saved as about one.
Both come from the same place. The elapsed time was kept in a counter that a
setIntervalraised once a second, while the moment the session started was already stored in the timer record and only consulted on mount and when the tab became visible again. A phone that suspends the page stops the counter, so pausing, stopping and saving all worked from a number that was behind the clock.The elapsed time is now derived from the moment the session started, every time it is read:
The interval no longer adds anything up, it only asks for a repaint, and it depends on the timer state alone instead of being torn down and recreated on every tick. Pause and stop call the same function rather than reading the display. Because there is no second copy of the elapsed time any more, there is also nothing to copy back into the view after a stop, which is what used to leave the old time on screen: the copy was skipped whenever the value before and after the stop happened to match, which is exactly what happens when a session is stopped without ever being paused.
A session that runs past midnight is now reported on the day it started, so that it stays in the month the publisher went out rather than moving into a month that may already have been submitted. The day is kept in the timer record so that it survives a pause, a reload and the app being closed, and it falls back to the start of the running segment for records saved before the day was stored. A locked month still falls through to the first day of the next one.
Smaller fixes in the same area: seconds are rounded instead of dropped, a device clock corrected backwards can no longer show a negative duration and lose the session, stopping a session too short to record now says so instead of resetting silently, and the dialog that opens after a stop keeps the day the time was saved on instead of following the clock into the next day.
Measured in the app, driving the timer with the device clock moved forward, before and after the change:
Type of change
Checklist: