home *** CD-ROM | disk | FTP | other *** search
/ The Fred Fish Collection 1.5 / ffcollection-1-5-1992-11.iso / ff_disks / 300-399 / ff321.lzh / Whereis / src / date.c next >
C/C++ Source or Header  |  1990-02-27  |  819b  |  51 lines

  1. #ifndef datetype
  2.  #include "date.h"
  3. #endif
  4. #ifndef EXEC_TYPES_H
  5.  #include <exec/types.h>
  6. #endif
  7.  
  8. ULONG leapyear (year)
  9. ULONG year;
  10.  
  11. {
  12.   return (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) ? 366L : 365L;
  13. }
  14.  
  15.  
  16. void date(datep, days)
  17. struct date *datep;
  18. register ULONG days;
  19. {
  20.   register ULONG year=1978L, month=0L;
  21.  
  22.   static ULONG DaysofMonth[]=
  23.   { 31L, 28L, 31L, 30L,
  24.     31L, 30L, 31L, 31L,
  25.     30L, 31L, 30L, 31L };
  26.  
  27.   year=1978L;
  28.   while (days >= 366L)
  29.   {
  30.     days-= leapyear(year);
  31.     year++;
  32.   }
  33.   if (days == 365L && leapyear(year)!= 366L)
  34.      days-=365L;
  35.  
  36.   DaysofMonth[1]= leapyear(year)==366L? 29L : 28L;
  37.  
  38.   while (days >= DaysofMonth[month])
  39.   {
  40.     days-=DaysofMonth[month];
  41.     month++;
  42.   }
  43.  
  44.   days++;
  45.   month++;
  46.  
  47.   datep->day= (short) days;
  48.   datep->month= (short) month;
  49.   datep->year= year;
  50. }
  51.