#ifndef datetype
 #include "date.h"
#endif
#ifndef EXEC_TYPES_H
 #include <exec/types.h>
#endif

ULONG leapyear (year)
ULONG year;

{
  return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 366L : 365L;
}


void date(datep, days)
struct date *datep;
register ULONG days;
{
  register ULONG year=1978L, month=0L;

  static ULONG DaysofMonth[]=
  { 31L, 28L, 31L, 30L,
    31L, 30L, 31L, 31L,
    30L, 31L, 30L, 31L };

  year=1978L;
  while (days >= 366L)
  {
    days-= leapyear(year);
    year++;
  }
  if (days == 365L && leapyear(year)!= 366L)
     days-=365L;

  DaysofMonth[1]= leapyear(year)==366L? 29L : 28L;

  while (days >= DaysofMonth[month])
  {
    days-=DaysofMonth[month];
    month++;
  }

  days++;
  month++;

  datep->day= (short) days;
  datep->month= (short) month;
  datep->year= year;
}
