date -d "next thur"
Version:
coreutils-7.2 (fixed in 7.3)
How to reproduce?
If today’s date is Thursday (Sept. 6, 2012), then run the following command:
$ coreutils-7.2/src/date -d "next thur"
Symptom:
Wrong result.
The output printed:
Thu Sep 6 00:00:00 PDT 2012
However, the correct output should be
Thu Sep 13 00:00:00 PDT 2012
Root cause:
The problem is because of getdate.y -- wrong calculation.
In getdate.y, the parser interpret the “next wed” differently.
get_date {
…
/* tm is a struct storing the time info of the current time,
where tm_wday stores the day of week [0-6]. In this case
tm.tm_wday = 4.
pc stores the command-line arg parsing info. So
pc.day_number stores the day of week of the request (in this case
pc.day_number equals 4 since the command arg is “next thur”).
So the bug is that originally it didn’t expect the case where
tm.tm_wday == pc.day_number (both thursday). */
tm.tm_mday += ((pc.day_number - tm.tm_wday + 7) % 7
+ 7 * (pc.day_ordinal -
+ (0 < pc.day_ordinal
+ && tm.tm_wday == pc.day_number)));
- (0 < pc.day_ordinal)));
}
Is there an error message?
No.
Can Errlog/developer anticipate an error message?
No. The error condition is subtle, and if we assume developers can anticipate the error, it means they can fix the bug