Part-time salary conversion: the same maths with fewer hours
When I built the salary-to-hourly calculator, the first version assumed everyone works full time. Forty hours a week, fifty-two weeks a year, 2,080 hours in total. It worked for the standard case, and it was wrong for a
When I built the salary-to-hourly calculator, the first version assumed everyone works full time. Forty hours a week, fifty-two weeks a year, 2,080 hours in total. It worked for the standard case, and it was wrong for a huge number of real people.
Part-time workers kept typing in their numbers and getting answers that made no sense. Someone earning $25 an hour for 24 hours a week was being told their yearly salary was $52,000. It is not. It is $31,200. The maths is the same, but the hours are not, and that one wrong assumption ruined the whole result.
The formula does not change, the inputs do
Converting an hourly rate to a yearly salary is three multiplications:
hourly rate x hours per week x weeks per year = annual salary
For a full-time worker that is $25 x 40 x 52 = $52,000. For a part-time worker on 24 hours a week it is $25 x 24 x 52 = $31,200. Same formula, different hours, very different answer. Going the other way is one division:
annual salary / (hours per week x weeks per year) = hourly rate
So a $30,000 part-time salary on 20 hours a week is $30,000 / 1,040 = $28.85 an hour. Compare that with the full-time version: $30,000 / 2,080 = $14.42 an hour. Same salary figure, double the hourly rate, because the hours are halved. This is the mistake I see most often. People divide a part-time salary by 2,080 and conclude they are paid badly, when the real hourly rate is perfectly reasonable.
The traps I had to handle
The first trap is weeks per year. Not everyone works 52 weeks. A school worker on a term-time contract might work 39 weeks. At $20 an hour for 25 hours a week, that is $19,500 a year, not $26,000. So the calculator asks for weeks per year as its own field, and defaults it to 52 rather than hiding it.
The second trap is unpaid time off. If a part-time worker takes two unpaid weeks, the salary drops by two weeks of pay, and the hourly rate stays the same. I show both numbers side by side so the gap is obvious.
The third trap is overtime. Under federal rules overtime starts after 40 hours in a week, and a part-time worker almost never gets there. But some states have daily overtime rules, and a part-timer working one long 10-hour Saturday can still earn overtime on that day. The conversion calculator does not pretend to know that. It shows the straight conversion and points at the overtime calculator for the rest.
The fourth trap is benefits. A part-time salary is rarely just the pay. Holiday entitlement, sick pay and pension contributions are often pro-rated. I do not try to price benefits in the calculator, and I say so on the page, because a number that quietly leaves something out is worse than no number at all.
What I changed in the code
The fix was small, which is the annoying part. The old code had a constant:
const FULL_TIME_HOURS = 2080;
Every conversion divided or multiplied by it. I replaced it with a value computed from the inputs:
const annualHours = hoursPerWeek * weeksPerYear;
const hourlyRate = annualSalary / annualHours;
const annualSalary = hourlyRate * annualHours;
The inputs are validated the same way as every other field on the site: hours per week must be between 1 and 80, weeks per year between 1 and 52, and anything outside that range shows a plain message instead of a silly number. All of it runs in the browser, so no pay details ever leave the device.
The lesson is one I keep relearning. A calculator is only as honest as its assumptions, and the default assumption is usually the full-time one. Most of the work is not the formula. It is finding the assumption, making it visible, and letting the person change it. If you want to try the conversion with your own hours, you can run it on mytimecardcal.com and see the hourly and yearly figures update as you type.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.