Skip to content

fix(ministry): correct lost and stale time in the ministry timer - #5401

Open
ux-git wants to merge 1 commit into
sws2apps:mainfrom
ux-git:fix/ministry-timer
Open

fix(ministry): correct lost and stale time in the ministry timer#5401
ux-git wants to merge 1 commit into
sws2apps:mainfrom
ux-git:fix/ministry-timer

Conversation

@ux-git

@ux-git ux-git commented Sep 4, 2026

Copy link
Copy Markdown
Member

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 setInterval raised 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:

const getElapsedTime = useCallback(() => {
  if (timer.state !== 'started') return timer.value;

  return timer.value + Math.max(0, Math.floor((Date.now() - timer.start) / 1000));
}, [timer]);

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:

Scenario Before After
Stop and save a 3 hour session display stayed at 3:00 until the page was left 00:00 as soon as it is stopped
3 hours suspended with no wake up event nothing saved, no dialog 3:00 saved
Pause after 2 hours suspended froze the counter froze the elapsed time
Accuracy over a long session about 2.5 percent slow exact
Clock moved back 10 minutes showed -9:-51 and dropped the session 00:00, session still saved
Start 23:50, stop 00:20 n/a saved on the day it started

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings

…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.
@vercel

vercel Bot commented Sep 4, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
staging-organized-app Ready Ready Preview Sep 4, 2026 2:06am UTC
test-organized-app Ready Ready Preview Sep 4, 2026 2:06am UTC

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

Next included review available in 16 minutes.

Check out review usage here.

View limit details

Limit 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.

Learn how review limits work.

Review configuration:

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Team

Run ID: c0ff1559-6a0f-4245-8553-1349311ca8cf

📥 Commits

Reviewing files that changed from the base of the PR and between b8c9a3f and 1e561b4.

⛔ Files ignored due to path filters (1)
  • src/locales/en/ministry.json is excluded by !**/*.json
📒 Files selected for processing (4)
  • src/definition/user_field_service_reports.ts
  • src/features/ministry/report/ministry_timer/duration/useDuration.tsx
  • src/features/ministry/report/ministry_timer/index.tsx
  • src/features/ministry/report/ministry_timer/useMinistryTimer.tsx

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sonarqubecloud

sonarqubecloud Bot commented Sep 4, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant