Re: PPSkit-0.9.0 has a Y2K problem

Harald Koenig (koenig@tat.physik.uni-tuebingen.de)
Wed, 5 Jan 2000 15:56:51 +0100


On Jan 05, Ulrich Windl wrote:

> In PPSkit-0.9.0 I added a routine from fs/fat/misc.c to convert a UNIX date to
> broken time (YYYY MO DD HH MI SS). As it turned out the routine produced a
> 1999-12-32 on January 1st, and since then there's one day missing. Maybe I did
> something stupied, maybe the problem is also in the original routine. Anyway
> here is a test suite to see yourself:

this problem doesn't only show up for Y2K but before _any_ lap year!
and here is a fix for this off-by-one bug:

@@ -66,10 +67,10 @@
year = day / 365; /* non-leap years since epoch */
printf("[d=%d y=%d] ", day, year);
/* correct for leap years in epoch: 1972 (2) was the first */
- if ((year + 2) / 4 + 365 * year > day)
+ if ((year + 1) / 4 + 365 * year > day)
year--;
/* reduce to day in current year */
- day -= (year + 2) / 4 + 365 * year;
+ day -= (year + 1) / 4 + 365 * year;
printf("[d=%d y=%d] ", day, year);
/* map March, 1st to Feburary, 29nd for leap years */
if (day == 59 && ((year + 2) & 3) == 0) {

the code in 2.2.x kernel sources (fat_date_unix2dos() in fs/fat/misc.c)
looks ok though:

year = day/365;
if ((year+3)/4+365*year > day) year--;
day -= (year+3)/4+365*year;

because here `year' is based on 1980 (epoch for MSDOS) and not 1970,
which gives that offset of 2 (== 10 % 4).

Harald

-- 
All SCSI disks will from now on                     ___       _____
be required to send an email notice                0--,|    /OOOOOOO\
24 hours prior to complete hardware failure!      <_/  /  /OOOOOOOOOOO\
                                                    \  \/OOOOOOOOOOOOOOO\
                                                      \ OOOOOOOOOOOOOOOOO|//
Harald Koenig,                                         \/\/\/\/\/\/\/\/\/
Inst.f.Theoret.Astrophysik                              //  /     \\  \
koenig@tat.physik.uni-tuebingen.de                     ^^^^^       ^^^^^

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/