Skip to content
Method

How hours are calculated

Every HourSum page shares one calculation engine. This page documents it in full, with the arithmetic shown line by line so any total can be checked by hand.

The four steps

  1. Read each clock time as minutes after midnight. 09:00 becomes 540 minutes, 17:30 becomes 1,050 minutes. A 12-hour input such as 5:15 PM is converted to 1,035 minutes.
  2. Subtract the start from the end. If the end is smaller than the start, add 1,440 minutes (24 hours) and mark the row as an overnight shift.
  3. Deduct the unpaid break. Break minutes come either from a minutes field or from a break start and end. A break equal to or longer than the shift is reported as an error. A clock-time break must fall entirely within its shift, including when either one crosses midnight.
  4. Convert for display. Hours and minutes come from integer division by 60; decimal hours come from dividing the worked minutes by 60 and rounding to the chosen precision.
workedMinutes = (endMinutes - startMinutes) - breakMinutes
decimalHours  = round(workedMinutes / 60, precision)
hours         = floor(workedMinutes / 60)
minutes       = workedMinutes % 60

Worked examples

1. A standard day with an unpaid break

09:00 to 17:30 with a 30-minute unpaid break. The span is 1,050 − 540 = 510 minutes, which is 8h 30m. Deducting the break leaves 480 minutes: 8h 00m, or 8.00 decimal hours. A 60-minute lunch instead leaves 450 minutes — 7h 30m and 7.50.

2. An overnight shift

22:00 to 06:00. The end (360 minutes) is smaller than the start (1,320 minutes), so 1,440 is added to the end: 1,800 − 1,320 = 480 minutes. That is 8h 00m and 8.00 decimal hours, with the row marked “+1 day”.

3. Adding rows

1h 45m plus 0h 30m. In minutes that is 105 + 30 = 135, which is 2h 15m and 2.25 decimal hours. Adding the decimal figures row by row would have produced the same answer here, but not when rounded rows are summed, which is why the engine adds minutes first.

4. Converting a duration

45 minutes is 45 ÷ 60 = 0.75 decimal hours. Going the other way, 7.75 decimal hours is 7.75 × 60 = 465 minutes, which is 7h 45m.

5. Adding durations directly

When the durations are already known — 2h 30m plus 1h 45m — the hours and minutes calculator skips the clock times and sums row minutes: 150 + 105 = 255, which is 4h 15m and 4.25 decimal hours. Minutes above 59 carry into hours automatically, so 25h 90m is 1,590 minutes, or 26h 30m. The decimal figure is taken from the exact minute total once, never rounded per row.

6. Rounding to the nearest quarter hour

09:00 to 17:42 is 522 minutes, or 8.70 decimal hours. Rounded to the nearest quarter it becomes 8.75. The minute total stays 522 — only the decimal and any pay estimate based on it change.

What is excluded on purpose

How the engine is tested

The calculation functions are covered by automated unit tests. The suite includes a standard day with a lunch deduction, an overnight shift, a break entered as a clock window, an overnight break, multiple rows, 12-hour inputs, quarter-hour and one-decimal rounding, and the conversion cases above — plus the invalid inputs that must be rejected rather than guessed at.

Check anything that looks wrong

If a total disagrees with your own working, the printed summary lists each row, the break deducted and the rounding applied, which is usually enough to find the difference. If it still looks like a bug, tell us the times and the expected result.