BATCH - MODATE.ZIP - MODATE.C

 
Output of file : MODATE.C contained in archive : MODATE.ZIP

/*=========================================================*/
/* MODATE.C A modified ordinal date calculation routine */
/* by R.F. Genovese - Placed in the Public Domain */
/* (TurboC 2.0 tiny model) */
/*=========================================================*/

#include
#include
#include
#include

int is_leap_year(int year);

main()
{
/* DOS.H defined structures */
struct date d;
struct time t;
/* the ordinal date string */
char o_date[]="YYDDDHHMMSS";
/* cumulative number of days in months (non-leap year) */
int cdim[]={0,0,31,59,90,120,151,181,212,243,273,304,334};
/* utility */
unsigned int ddd;

clrscr();
printf("\nModified Ordinal Date Calculation\n");
/* get system date (note: must be accurate!) */
getdate(&d);
gettime(&t);
/* how many days have gone by? */
ddd=(int)d.da_day+cdim[d.da_mon];
/* correct for a leap year (good from 1582-present) */
if ((d.da_mon > 2) && (is_leap_year(d.da_year)))
ddd++;
/* make ordinal date string */
(void)sprintf(o_date,"%02d",d.da_year-1900);
(void)sprintf(&o_date[2],"%03d",ddd);
(void)sprintf(&o_date[5],"%02d",t.ti_hour);
(void)sprintf(&o_date[7],"%02d",t.ti_min);
(void)sprintf(&o_date[9],"%02d",t.ti_sec);
printf("\nDate=%02d/%02d/%4d and Time=%02d:%02d:%02d",
d.da_mon,d.da_day,d.da_year,t.ti_hour,t.ti_min,t.ti_sec);
printf("\n\nOrdinal Date String=[%s]\n",o_date);
return(0);
}

int is_leap_year(int year)
{
unsigned char ly=0; /* default=not leap year */

if(year%4==0) /* leap year is evenly divisible by 4 */
if(year%100!=0) /* and not a century year */
ly=1;
else
if(year%400==0) /* unless evenly divisible by 400 */
ly=1;
return(ly);
}