Problems with INN-2.2.3 and SuSE6.4

Tom Kacvinsky tjk at ams.org
Mon Dec 11 03:38:38 UTC 2000


Hi,

When the code Russ quotes is invoked, yyYear is 2000 (yyYear is initialized to
tm->tm_year + 1900 later in the code, which [on a Solaris box] is 1900 + 100 =
2000).  With $4 = 99, the code works and yyYear is set to 1999.  When $4 = 100,
the year returned is 1900.  It looks like the code is broken in case $4 = 100.
I think it is broken when $4 = 101, even.  Think about it.  As the code is
written when $4 > 100, the year returned is 101.  Why should we worry about
this?  Because the news clients that are writing out 100 for the year 2000 are
most likely going to write out 101 for the year 2001.

We probably need to consider 3 caes:

case 1: 0 <= $4 < 100

case 2: 100 <= $4 <= 199

case 3: 199 < $4

I chose 199 as the cutoff because by 2099, one would hope that clients no longer
write out 20xx as 1xx, and 2099 is the last year of the form 20xx that can be
erroneously written as 1xx.  I hope that makes sense!  I have been trying ot
find a terse wording of this for the last 1/2 hour.  Blame the mathematician in
me!

Something like this:

  if ($4 > 199) {
    yyYear = $4;
  } else {
    yyYear = $4 + (yyYear / 100 + (yyYear % 100 - $4) / 50) * 100;
    if ($4 >= 100)
      yyYear = yyYear + 100;
  }

Below is some sample code, and the results.  Please note, I do not know if
yyYear will always be initialized to 1900 + (numbers of years since 1900).  This
is the weak link in the code below.

Tom

-- cut here --
#include <stdlib.h>


typedef struct year_struct {
  int fouryear;
  int year;
} year;

int main () {

  int yyYear = 2000 ;
  int yyIn = 99 ;
  int i;

  year Years[] = {{2000,97}, {2000,98}, {2000,99}, {2000,100}, {2000,101}, {2001,101}, {2002,102}, {2098,198}, {2099,199}};

  for (i = 0; i < 9; i++ ) {
    yyIn = Years[i].year ;
    yyYear = Years[i].fouryear ;


    if (yyIn > 199) {
      /* assume year is YYYY format, so need not to add 1900 */
      yyYear = yyIn ;
    } else {

      /* assume year is YY format, so need to add 1900 */
      yyYear = yyIn + (yyYear / 100 + (yyYear % 100 - yyIn) / 50) * 100 ;

      if ( yyIn >= 100)
	yyYear = yyYear + 100 ;

    }

    printf ("Four digit year: %d, Short Year: %d, Result: %d.\n", Years[i].fouryear, Years[i].year, yyYear) ;

  }

  return (0) ;

}

sun06> ./year
Four digit year: 2000, Short Year: 97, Result: 1997.
Four digit year: 2000, Short Year: 98, Result: 1998.
Four digit year: 2000, Short Year: 99, Result: 1999.
Four digit year: 2000, Short Year: 100, Result: 2000.
Four digit year: 2000, Short Year: 101, Result: 2001.
Four digit year: 2001, Short Year: 101, Result: 2001.
Four digit year: 2002, Short Year: 102, Result: 2002.
Four digit year: 2098, Short Year: 198, Result: 2098.
Four digit year: 2099, Short Year: 199, Result: 2099.

Tom

>
> Hm.  Looking at parsedate.y in 2.3, there are actually a whole bunch of
> places that should be handling this:
>
>             if ($4 > 100) {
>                 /* assume year is YYYY format, so need not to add 1900 */
>                 yyYear = $4;
>             } else {
>                 /* assume year is YY format, so need to add 1900 */
>                 yyYear = $4 + (yyYear / 100 + (yyYear % 100 - $4) / 50) * 100;
>             }
>
> I'm not sure why it's not doing what you want.  Hurm.  Although I also
> have no idea what that formula is really doing, since it's not obviously
> just adding 1900.
>
>







More information about the inn-workers mailing list