Hasty Briefsbeta

Bilingual

Fixing a small calc.exe bug (2019)

2 days ago
  • #Date Calculation
  • #Software Bug
  • #Open Source
  • A bug in Windows Calculator's date difference feature was discovered, where calculating the difference between July 31st and December 30th incorrectly displayed '5 months, 613566756 weeks, 3 days'.
  • The bug stems from the non-associative behavior of the AddMonths function, where adding months to a date like July 31st can land on different days depending on the sequence of operations.
  • The calculation uses unsigned integers, causing negative day differences to wrap around to large numbers when decremented, leading to inflated week counts.
  • A minimal fix was proposed by adjusting the logic to handle the AddMonths idiosyncrasies, resulting in more accurate but still unintuitive outputs like '4 months, 4 weeks, 1 day'.
  • Alternative solutions suggested include avoiding unsigned types, using Julian days, leveraging C++11 date libraries, or iterating through calendar units for more human-intuitive results.