AI • Science • Technology • Future

Side Projects

Rounding Clock Times: Law, Fairness & Code

Image from the original article
Featured image: original publisher image. Via original publisher.

Most people don’t expect to be paid from 9:00 when they clock in at 8:58. Nor do they expect to be paid from 9:00 when they arrive at 9:07. Yet that’s exactly what happens on many time cards. This seemingly minor detail—rounding clock times—has deep implications for fairness, transparency, and legal compliance in workplace payroll systems.

What the law allows

Under the US Fair Labor Standards Act, an employer may round clock times to the nearest 5 minutes, the nearest tenth of an hour, or the nearest quarter of an hour. That is the whole test. The regulation — 29 CFR 785.48(b) — does not say “always round down” or “always round to the nearest”. It says the practice must average out, so it cannot systematically shave minutes off every shift.

The classic example is the 15-minute rule. A clock-in at 8:53 rounds to 8:45. A clock-in at 8:54 rounds to 9:00. The cut-off sits at 7 minutes and 30 seconds past the quarter, which in practice means 7 minutes either way. If your system rounds 8:53 to 8:45 but also rounds 9:07 to 9:00, the worker gains on one side and loses on the other, and over a month it balances. What is not allowed is a one-way rule — say, always rounding clock-ins forward and clock-outs backward — because that always takes time from the worker. That is not rounding, it is a pay cut dressed up as arithmetic.

What went wrong in the first version

The author’s initial timecard calculator used a simple formula: Math.round(minutes / 15) * 15. It correctly rounds time to the nearest 15-minute interval. But it failed real-world scenarios.

One flaw was the lunch break. An employee clocks out at 12:02 and back in at 12:31. The actual break is 29 minutes. Rounded, it shows 12:00 to 12:30—30 minutes. A user noted, ‘It looks like they took a full 30 minutes off, but they only took 29.’ On the flip side, a 29-minute break might round to 31 minutes, suggesting a longer break. These small errors add up over time and distort actual work hours.

Another issue was midnight. A night shift ending at 00:07 rounds to 00:00 in the original code. But that’s the previous day’s midnight. The shift duration becomes negative. As a developer explained, ‘The math was correct, but the timeline was broken. The system treated a shift ending at 00:07 as if it had started at midnight the day before—resulting in a negative duration.’ This shows time systems must manage day boundaries carefully.

How the author fixed it

The fix separates storage and display. Every time stamp is stored exactly—minutes since midnight, with a day offset for times past midnight. No data is lost.

Only a copy of the data is used for rounding. The function roundToQuarter(minutes) is: Math.round(minutes / 15) * 15. It runs on a temporary copy, not the stored value.

Image from the original article
original publisher image. Via original publisher. · Source

Two totals are shown: one from exact times, one from rounded times. If they differ by more than a few minutes in a week, the worker sees the gap and chooses which one their employer uses. Transparency beats cleverness here.

Two key rules matter. This is stated on the page so users can verify it. Second, rounding never crosses a day boundary. A clock-out at 00:07 stays in the same day’s shift. The day offset is applied before rounding, preventing negative durations and ensuring consistency.

Why the feature is optional

Not every employer rounds. Not every worker wants it. So the toggle defaults to off. When turned on, both exact and rounded totals appear side by side. This was a deliberate choice: a feature on by default is a decision made for the user. A pay decision should never be made quietly.

The central lesson is that payroll math is never just math. Every formula has a person on the other end—someone who depends on it for income and job security. The most honest version of any timecard system is one that shows how numbers are derived and allows users to verify them. Rounding to the nearest 15 minutes is legal, common, and easy to code. The real work lies in making it visible and verifiable to the worker.

For more on how AI tools can automate time tracking, see AI Coding Agent Builds Duolingo-Like App in Minutes.

Learn more about the legal basis of time rounding at the original source: Rounding Clock Times to the Nearest 15 Minutes.

Visit the timecard calculator at mytimecardcal.com.

Sources & further reading

Featured image: original publisher image. Via original publisher. Image source