because I don't know very much about C-programming,
I have a question using existing C-functions from Clipper-times.
In my collection, there are many useful C-sources ( h - files included ).
Is there something special, to take care of ?
C - sample to calculate the ISO-week-Number ( week-splitting, julian-date and leap-year is calculated ) :
- Code: Select all Expand view
#include "extend.h"
#include "headpwa5.h"
extern int _dat_pruef(int, int, int), _is_schalt(int);
extern long _jul_datum(int, int, int);
extern void _datum(int *, int *, int *, long);
/* Call : WOCHNR( <day>, <month>, <year> )
* WOCHNR( <date> )
* Function: ISO-Week-No. of a given Date
* Return: Week-Number
* Note: expN = <day>, <month>, <year>
* expD = <date>
*/
CLIPPER WOCHNR()
{
int tag, monat, jahr, anz_tg, wochnr, dow;
long dtm, wrkdtm;
char *datum;
if( PCOUNT == 3 && ISNUM(1) && ISNUM(2) && ISNUM(3) )
{
tag = _parni(1);
monat = _parni(2);
jahr = _parni(3);
jahr += jahr < 100 ? 1900 : 0;
if(_dat_pruef(tag, monat, jahr) < 0)
{
_retni(-1); /* Error */
return;
}
}
else if( PCOUNT == 1 && ISDATE(1) )
{
datum = _pards(1);
_date_to_num(datum, &tag, &monat, &jahr);
}
else
{
_retl(FALSE); /* .F., because of error */
return;
}
dtm = _jul_datum(tag, monat, jahr);
wrkdtm = _jul_datum(1, 1, jahr); /* Date1.1.jj */
while(1)
{
dow = (wrkdtm % 7L) + 1; /* Week-day Mo=1,...So=7 */
if(dow > 1 && dow <= 4)
wrkdtm -= 7L; /* Week before */
while(1)
{
dow = (wrkdtm % 7L) + 1; /* Week-day Mo=1,...So=7 */
if(dow == 1) /* 1. Monday seek */
break; /* stop */
wrkdtm++;
}
anz_tg = (int)(dtm - wrkdtm); /* running day from 1. Monday */
if(anz_tg >= 0)
break; /* stop */
wrkdtm = _jul_datum(1, 1, jahr - 1); /* Date 1.1. year before */
}
wochnr = (anz_tg / 7) + 1; /* Week-No. */
if(wochnr == 53)
{
wrkdtm = _jul_datum(1, 1, jahr + 1); /* Date 1.1. next year */
dow = (wrkdtm % 7L) + 1; /* Weekday Mo=1,...So=7 */
if(dow >= 1 && dow <= 4)
wochnr = 1;
}
_retni(wochnr);
}
Regards
Uwe