{
  "id": 17603368,
  "title": "Building a Work-Hours Calculator? Time Arithmetic Is the Trap",
  "url": "https://urgent.news/2026/11/01/building-a-work-hours-calculator-time-arithmetic-is-the-trap",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-11-01T13:12:57.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/maher_ikramah_4a3da041672/building-a-work-hours-calculator-time-arithmetic-is-the-trap-27g7"
  },
  "original_language": "en",
  "account": "When developing a work-hours calculator, there are four common pitfalls developers encounter. To avoid these issues, follow a few key steps. First, store times as minutes since midnight rather than as decimal numbers. This avoids problems with floating-point arithmetic causing rounding errors. Convert all time inputs to minutes using a function like `toMinutes`. Second, perform all calculations using integers by subtracting breaks in minutes before any rounding takes place. Only round once at the end to display the final result. Third, for overnight shifts, use modular arithmetic to wrap the time difference around a 24-hour day. Fourth, validate your calculator with concrete test cases covering all scenarios, including bi-weekly paychecks and overnight shifts. Test the calculator's state when first loaded as well, ensuring all displayed numbers are consistent. Following these steps will ensure your calculator reliably produces the correct results.",
  "summary": "If you have ever built a timesheet tool, a shift planner, or a payroll helper, you know the feature looks trivial until you write the first test. Start time minus end time, minus a break, times an hourly rate. What could go wrong? Plenty — and almost all of it comes from treating time like ordinary decimal numbers. This article walks through the four traps that bite every work-hours calculator,…",
  "key_points": [
    "Store times as minutes since midnight to avoid floating-point rounding errors",
    "Perform calculations using integers, subtracting breaks before rounding, only round at end",
    "Use modular arithmetic for overnight shifts, wrap time difference around 24-hour day"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 1,
    "also_reported_by": []
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}