#ifndef DATASTRUCTURE_D5800034C
#define DATASTRUCTURE_D5800034C
typedef struct tagDSD5800034C
{
JDEDATE jdDateIn;
MATH_NUMERIC mnTimeIn;
JDEDATE jdDateOut;
MATH_NUMERIC mnTimeOut;
MATH_NUMERIC mnRollYears;
MATH_NUMERIC mnRollMonths;
MATH_NUMERIC mnRollDays;
MATH_NUMERIC mnRollHours;
MATH_NUMERIC mnRollMinutes;
MATH_NUMERIC mnRollSeconds;
} DSD5800034C, *LPDSD5800034C;
#define IDERRjdDateIn_1 1L
#define IDERRmnTimeIn_2 2L
#define IDERRjdDateOut_3 3L
#define IDERRmnTimeOut_4 4L
#define IDERRmnRollYears_5 5L
#define IDERRmnRollMonths_6 6L
#define IDERRmnRollDays_7 7L
#define IDERRmnRollHours_8 8L
#define IDERRmnRollMinutes_9 9L
#define IDERRmnRollSeconds_10 10L
#endif
JDEBFRTN (ID) JDEBFWINAPI AcmeRollDateTime (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSD5800034C lpDS)
{
/************************************************************************
* Variable declarations
************************************************************************/
JDEDATE jd;
long ryr=0,rmth=0,rday=0,rhr=0,rmin=0,rsec=0,h,m,s,x;
/************************************************************************
* Check for NULL pointers
************************************************************************/
if ((lpBhvrCom == (LPBHVRCOM) NULL) ||
(lpVoid == (LPVOID) NULL) ||
(lpDS == (LPDSD5800034C) NULL))
{
jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, _J("4363"), (LPVOID) NULL);
return ER_ERROR;
}
/************************************************************************
* Main Processing
************************************************************************/
MathNumericToLong(&lpDS->mnRollYears, &ryr);
MathNumericToLong(&lpDS->mnRollMonths, &rmth);
MathNumericToLong(&lpDS->mnRollDays, &rday);
MathNumericToLong(&lpDS->mnRollHours, &rhr);
MathNumericToLong(&lpDS->mnRollMinutes,&rmin);
MathNumericToLong(&lpDS->mnRollSeconds,&rsec);
/***** roll time *****/
I5800034_BreakDownTime(&lpDS->mnTimeIn, &h, &m, &s);
/* seconds */
s += rsec;
x = s / 60;
rmin += x;
s -= (x * 60);
if(s < 0)
{
s += 60;
rmin--;
}
/* min */
m += rmin;
x = m / 60;
rhr += x;
m -= (x * 60);
if(m < 0)
{
m += 60;
rhr--;
}
/* hour */
h += rhr;
x = h / 24;
rday += x;
h -= (x * 24);
if(h < 0)
{
h += 24;
rday--;
}
IntToMathNumeric((h * 10000) + (m * 100) + s, &lpDS->mnTimeOut);
/***** roll date *****/
rmth += ryr * 12;
//AdvanceDate(&lpDS->jdDateOut, &lpDS->jdDateIn, rmth, rday); debug, this doesnt work as expected
/* the documentation is at best confusing for Advancedate, passing both rmth and rday on single call does not produce
expected results. Passing 0 for month and rday for days should work and appears to be working
in other places in custom code. However I am a little concerned, so I am going to use AdvanceOneDay/DecrementOneDay
api in this function. May be a little slower, but I feel more comfortable with what the API is doing.
*/
//if(rday != 0) debug, following if,else should work but.... documentation is not clear
// AdvanceDate(&jd, &lpDS->jdDateIn, 0, rday);
//else
// jd = lpDS->jdDateIn;
jd = lpDS->jdDateIn;
for(x = 0; x < rday; x++)
jd = AdvanceOneDay(jd);
for(x = 0; x < (rday * -1); x++)
jd = DecrementOneDay(jd);
if(rmth != 0)
AdvanceDate(&lpDS->jdDateOut, &jd, rmth, 0);
else
lpDS->jdDateOut = jd;
/************************************************************************
* Function Clean Up
************************************************************************/
return (ER_SUCCESS);
}
static void I5800034_BreakDownTime(LPMATH_NUMERIC pmnTime, long *h, long *m, long *s)
{
long t;
MathNumericToLong(pmnTime, &t);
*h = t / 10000;
*m = (t / 100) - ((*h) * 100);
*s = t - ( ((*h) * 10000) + ((*m) * 100) );
if(*h > 24 || *h < 0)
*h = 0;
if(*m > 60 || *m < 0)
*m = 0;
if(*s > 60 || *s < 0)
*s = 0;
}