home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 240.lha / PickPacket_v1.0 / Sources / date.c < prev    next >
C/C++ Source or Header  |  1989-05-04  |  2KB  |  63 lines

  1. #include "exec/types.h"
  2. #include "libraries/dos.h"
  3.  
  4. #define LEAPYEAR(year) (!((year)%4) && (year)%100)
  5.  
  6. void FormatDate(struct DateStamp *, char *);
  7.  
  8. void FormatDate(ds, string)
  9. struct DateStamp *ds;
  10. char *string;
  11. {
  12.    static char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  13.                             "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  14.    static int monthdays[] ={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
  15.    int day, month, year;
  16.    ULONG hours, minutes, secs;
  17.  
  18.    for(year=78, day=ds->ds_Days; day >= 366; year++)
  19.    {
  20.       day -= 365;
  21.       if(LEAPYEAR(year)) day--;  /* Leap day */
  22.    }
  23.    if(day == 365 && !LEAPYEAR(year))
  24.    {
  25.       day = 0;
  26.       year++;
  27.    }
  28.    if(LEAPYEAR(year)) monthdays[1] = 29;
  29.    else monthdays[1] = 28;
  30.  
  31.    for(month=0; 
  32.        month<12 && day >= monthdays[month]; 
  33.        day-=monthdays[month++]);
  34.  
  35.    day++;
  36.    string[0] = '0' + day/10;
  37.    string[1] = '0' + day%10;
  38.    string[2] = string[6] = '-';
  39.    memcpy(string+3, months[month], 3);
  40.    string[7] = '0' + year/10;
  41.    string[8] = '0' + year%10;
  42.    string[9] = ' ';
  43.  
  44.    secs = ((ULONG)ds->ds_Tick/50) + 
  45.           ((ULONG)ds->ds_Minute*60);
  46.  
  47.    hours   = secs / 3600;
  48.    secs   %= 3600;
  49.    minutes = secs / 60;
  50.    secs %= 60;
  51.  
  52.    string[10] = '0' + hours/10;
  53.    string[11] = '0' + hours%10;
  54.    string[12] = string[15] = ':';
  55.    string[13] = '0' + minutes/10;
  56.    string[14] = '0' + minutes%10;
  57.    string[16] = '0' + secs/10;
  58.    string[17] = '0' + secs%10;
  59.    string[18] = '\0';
  60.    return;
  61. }
  62.  
  63.