Hours Calculator: Quick Framework
1. Core Tasks
- Simple span: end - start (adjust if crosses midnight).
- Between dates: diff ms → days/hours/minutes.
- Work hours: (end − start − breaks) × days/week.
2. Flow
- Normalize times → 24h internal.
- Compute raw ms.
- Subtract unpaid breaks.
- Aggregate (daily → weekly → monthly → yearly).
3. Payroll Logic
- Regular = min(total, 40h).
- OT = max(0, total − 40h) × multiplier.
- Annual ≈ weekly × weeks/year.
4. Sanity Checks
- End before start → assume overnight +1 day.
- Break >= 0 & break < shift length.
- Daily hours not negative after subtraction.
5. Shortcuts
- Round only at display layer (keep ms internally).
- Batch compute weekly sums after per-row update.
- Prefill subsequent days from first day for fixed shifts.
6. Pitfalls
- AM/PM 12 edge (12 AM=00, 12 PM=12).
- Ignoring daylight saving in multi-day spans (consider timezone libs if critical).
- Double subtracting breaks on overnight shifts.
7. Micro Examples
09:00-17:00 break 1h → 7.00h
Week: 7h ×5 = 35h (no OT)
45h week @1.5 OT → 40 + 5×1.5 = 47.5 pay-hours
8. Mini FAQ
- Overnight shift? Add a day if end ≤ start.
- Partial hours? Keep decimal for payroll exports.
- Custom OT? Adjust threshold & multiplier.
9. Action Tip
Store raw ms per row; all summary views derive from that single source for consistency.