April
2005, Issue 177
Test Your
EQ
|
Answer
6You’ve
probably realized that Daylight Savings Time is the problem.
In many jurisdictions, clocks are set ahead by 1 h at
2:00 a.m. on the first Sunday in April and set back by
1 h at 2:00 a.m. on the last Sunday in October.
You’d
probably guess that it’s during the hour on either side
of 2:00 a.m. on those dates that the algorithm fails,
but that isn’t the case. Even though the time of day 86,400
s earlier at those times isn’t the same as the current
time of day, the date is still correct.
The
real problem occurs at the following midnight. The last
Sunday in October is 25 h long, and the first Sunday in
April is 23 h long. So, at 23:59 on October 27, 2002,
“yesterday,” according to the simplistic algorithm, was
still the October 27. Similarly, at 00:01 on April 8,
2002 (Monday), it would have reported that “yesterday’
was April 6 (Saturday). It’s better to use an algorithm
that maps dates directly to and from contiguous integers,
such as Zeller’s congruence.
Contributor:
David Tweed