
  function drdate(d : dateln) : integer;
  { 1 jan 1978 <--> drd = 1. assumes valid d }

    CONST dayspermonth : array[1..12] of byte =
            ( 31,28,31,30,31,30,31,31,30,31,30,31);

    var
      year, month, day, i  : integer;

  begin
    i := 11*ord('0');
    year  := 10 * ord(d[7]) + ord(d[8]) - i + 1900;
    month := 10 * ord(d[1]) + ord(d[2]) - i;
    day   := 10 * ord(d[4]) + ord(d[5]) - i;
    if europe then
      begin
        i := month;
        month := day;
        day := i;
      end;
    if year < 66 then
      year := year + 100;
    if ( (year mod 4) = 0) then
      dayspermonth[2] := 29; { doesn't take into account 1900 or 2100 }
    if (year < 1978) or (month = 0) or (day = 0) then
      drdate := 0
    else begin
      year := (year - 1976);
      i := year div 4;
      year := year mod 4;
      day := day - 731 { from 1 jan 1976, -1 } + 1461 * i;
      if (year > 0) or (month > 2) then
        day := day+1;
      day := day + 365 * year;
      for i := 1 to month-1 do
        day := day + dayspermonth[i];
      drdate := day;
    end;
  end; { drdate }

