๐ง๐ถ๐บ๐ฒ ๐ ๐ฎ๐๐ต ๐๐ ๐๐ฎ๐ฟ๐ฑ๐ฒ๐ฟ ๐ง๐ต๐ฎ๐ป ๐๐ ๐๐ผ๐ผ๐ธ๐
Adding durations seems easy. 2:45 plus 1:30 is simple. Then a bug appears. A user works from 11:45 PM to 7:15 AM. Your code says they worked negative 16 hours.
The obvious answer is often wrong.
Here are six common time bugs.
- Decimal Errors. Treating 1:30 as 1.30. It is 1.5 hours.
- Midnight Wraps. End time is before start time. Add a full day to fix this.
- AM and PM Logic. 12 PM is noon. 12 AM is midnight. Store 24 hour times internally.
- Daylight Savings. Days are 23 or 25 hours long. Use UTC or epoch seconds.
- Unit Mix-ups. Some systems use milliseconds. Others use seconds. Mixing them ruins the result.
- Payroll Rounding. Convert minutes to decimals. Set a clear rounding rule.
Most bugs come from doing math on strings or local times. These formats are not additive.
Use this pipeline.
- Parse input into one base unit.
- Do your math.
- Format for humans at the end.
This process stops time bugs.