The Daily WTF
Normally, I wouldn’t have much to say about a simple “it’s a mere arithmetic error” type of code sample. But this submission from Taylor adds an important factor: it’s a basic arithmetic mistake in date handling code, in a legacy product that’s been in use for decades. Oh, and it’s written in Delphi.
ElapsedSeconds := Round( (Now – StartTime) * 24.0 * 60.0 * 60.0); Days := ElapsedSeconds div 86400; Hours := ElapsedSeconds mod 86400 div 3660; Minutes := ElapsedSeconds mod 86400 mod 3660 div 60; Seconds := ElapsedSeconds mod 86400 mod 3660 mod 60;
I’m not going to get too uppity about the bare constants in the first line. HOURS_PER_DAY would help readability, but it’s pretty clear what this line is doing: converting a number of days into a number of elapsed seconds.
The following lines then pick that number of seconds back apart into a more
To read the full article click on the 'post' link at the top.