Dev.to WebDev ๐Ÿ›  Dev ๐Ÿ‘ 0 ๐Ÿ“– 3 min read

Weighted overtime average: when one worker has two different hourly rates

Most overtime calculators assume one hourly rate. Real work is messier. I know people who stock shelves at $20 an hour on weekdays and wash dishes at $14 an hour at the weekend, all for the same employer. When that week

Most overtime calculators assume one hourly rate. Real work is messier. I know people who stock shelves at $20 an hour on weekdays and wash dishes at $14 an hour at the weekend, all for the same employer. When that week hits 50 hours, which rate does the overtime use? The answer is neither โ€” and this is the rule I had to build into the overtime calculator on mytimecardcal.com when I added support for mixed-rate weeks.

The rule, in plain words

Under the US Fair Labor Standards Act, overtime is paid at one and a half times the worker's regular rate for the week. When a worker earns two different rates in the same week, the regular rate is a weighted average: all straight-time earnings for the week, divided by all hours worked. You do not pick the higher rate, and you do not pay overtime at the rate of whichever job the extra hours happened to fall in.

Here is the worked example I test my calculator against.

A worker does 30 hours at $20 an hour, then 20 hours at $14 an hour. That is 50 hours total, so 10 of them are overtime hours.

  • Straight-time earnings: (30 ร— $20) + (20 ร— $14) = $600 + $280 = $880
  • Weighted regular rate: $880 รท 50 hours = $17.60
  • Overtime premium: 0.5 ร— $17.60 ร— 10 hours = $88
  • Total pay for the week: $880 + $88 = $968

The overtime premium is only half the regular rate, not one and a half times it, because the straight-time pay for those 10 hours is already inside the $880.

The mistake it prevents

The tempting shortcut is to pay the 10 overtime hours at 1.5 times the $14 weekend rate, which gives $210 of overtime pay instead of the $88 premium plus straight time, or to pay them at 1.5 times the $20 weekday rate. Both are wrong, and both cost one side real money. The weighted average exists precisely because neither job on its own describes what the worker actually earned that week.

There is one narrow alternative the law allows โ€” paying overtime at the rate in effect when the overtime was worked โ€” but only if the employer and worker agreed to it before the work was done. My calculator does not offer that path, because the agreement has to exist in advance and most mixed-rate workers I have heard from never had that conversation. The weighted average is the safe default, and it is the one I ship.

How I coded it

The implementation is small, which is why I like it. The calculator takes a list of rate entries, each with hours and an hourly rate, and:

  1. Sums straight-time pay across all entries.
  2. Sums total hours across all entries.
  3. Divides the first by the second for the regular rate.
  4. Works out overtime hours as total hours minus 40.
  5. Adds the half-rate premium for those hours.

No entry is allowed to carry its own overtime. The split only happens after the totals are known, which keeps the maths honest no matter how many rates are in the week. I also round the final pay to two decimal places and keep every intermediate figure unrounded, because rounding the regular rate early is how a paycheck ends up a few cents out โ€” and a few cents out is still wrong.

One edge case worth knowing: if the two rates are the same, the weighted average collapses back to that rate and the result is identical to a single-rate week. That is my smoke test. If a mixed-rate input with equal rates gives a different answer to the plain calculator, something in step three is broken.

Mixed-rate weeks are common in retail, hospitality and care work, where one person covers two roles. The maths is not hard, but it is exactly the kind of thing a worker should not have to do by hand at the kitchen table after a 50-hour week.

๐Ÿ“ฐ Read the original article on Dev.to WebDev

Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes โ€” full credit and traffic to the original publisher.