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 >
Wrap
C/C++ Source or Header
|
1989-05-04
|
2KB
|
63 lines
#include "exec/types.h"
#include "libraries/dos.h"
#define LEAPYEAR(year) (!((year)%4) && (year)%100)
void FormatDate(struct DateStamp *, char *);
void FormatDate(ds, string)
struct DateStamp *ds;
char *string;
{
static char *months[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
static int monthdays[] ={31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int day, month, year;
ULONG hours, minutes, secs;
for(year=78, day=ds->ds_Days; day >= 366; year++)
{
day -= 365;
if(LEAPYEAR(year)) day--; /* Leap day */
}
if(day == 365 && !LEAPYEAR(year))
{
day = 0;
year++;
}
if(LEAPYEAR(year)) monthdays[1] = 29;
else monthdays[1] = 28;
for(month=0;
month<12 && day >= monthdays[month];
day-=monthdays[month++]);
day++;
string[0] = '0' + day/10;
string[1] = '0' + day%10;
string[2] = string[6] = '-';
memcpy(string+3, months[month], 3);
string[7] = '0' + year/10;
string[8] = '0' + year%10;
string[9] = ' ';
secs = ((ULONG)ds->ds_Tick/50) +
((ULONG)ds->ds_Minute*60);
hours = secs / 3600;
secs %= 3600;
minutes = secs / 60;
secs %= 60;
string[10] = '0' + hours/10;
string[11] = '0' + hours%10;
string[12] = string[15] = ':';
string[13] = '0' + minutes/10;
string[14] = '0' + minutes%10;
string[16] = '0' + secs/10;
string[17] = '0' + secs%10;
string[18] = '\0';
return;
}