Source Code of BD3N070.c

#include <jde.h>

#define bd3n070_c

/*****************************************************************************

* Source File: bd3n070

*

* Description: Date/Time functions Source File

*

* History:

* Date Programmer SAR# - Description

* ------

* Author 06/12/1997 Delancy 1 - Created

*

* Copyright (c) J.D. Edwards World Source Company, 1996

*

* This unpublished material is proprietary to J.D. Edwards World Source Company.

* All rights reserved. The methods and techniques described herein are

* considered trade secrets and/or confidential. Reproduction or

* distribution, in whole or in part, is forbidden except by express

* written permission of J.D. Edwards World Source Company.

****************************************************************************/

/**************************************************************************

* Notes:

*

**************************************************************************/

#include <bd3n070.h>

/**************************************************************************

* Business Function: JDEDateToReaderDeviceD3N

*

* Description: Convert JDE Date to Device Date - JDE

*

* Parameters:

* LPBHVRCOM lpBhvrCom Business Function Communications

* LPVOID lpVoid Void Parameter - DO NOT USE!

* LPDSDD3N070 lpDS Parameter Data Structure Pointer

*

*************************************************************************/

JDEBFRTN (ID) JDEBFWINAPI JDEDateToReaderDeviceD3N (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N070 lpDS)

{

/************************************************************************

* Variable declarations

************************************************************************/

short rc = 0;

/************************************************************************

* Declare structures

************************************************************************/

/************************************************************************

* Declare pointers

************************************************************************/

/************************************************************************

* Check for NULL pointers

************************************************************************/

if ((lpBhvrCom == (LPBHVRCOM) NULL) ||

(lpVoid == (LPVOID) NULL) ||

(lpDS == (LPDSDD3N070)NULL))

{

jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, "4363", (LPVOID) NULL);

return ER_ERROR;

}

/************************************************************************

* Set pointers

************************************************************************/

/************************************************************************

* Main Processing

************************************************************************/

rc = FormatDate(lpDS->szItemName, &lpDS->jdDate01, lpDS->szParamter1DataItem);

/************************************************************************

* Function Clean Up

************************************************************************/

return (ER_SUCCESS);

}

/**************************************************************************

* Business Function: ReaderDeviceDateToJDEDateD3N

*

* Description: Convert Device Date to JDE Date - JDE

*

* Parameters:

* LPBHVRCOM lpBhvrCom Business Function Communications

* LPVOID lpVoid Void Parameter - DO NOT USE!

* LPDSDD3N070 lpDS Parameter Data Structure Pointer

*

*************************************************************************/

JDEBFRTN (ID) JDEBFWINAPI ReaderDeviceDateToJDEDateD3N (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N070 lpDS)

{

/************************************************************************

* Variable declarations

************************************************************************/

short rc = 0;

/************************************************************************

* Declare structures

************************************************************************/

/************************************************************************

* Declare pointers

************************************************************************/

/************************************************************************

* Check for NULL pointers

************************************************************************/

if ((lpBhvrCom == (LPBHVRCOM) NULL) ||

(lpVoid == (LPVOID) NULL) ||

(lpDS == (LPDSDD3N070)NULL))

{

jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, "4363", (LPVOID) NULL);

return ER_ERROR;

}

/************************************************************************

* Set pointers

************************************************************************/

/************************************************************************

* Main Processing

************************************************************************/

rc = DeformatDate(&lpDS->jdDate01, lpDS->szItemName, lpDS->szParamter1DataItem);

/************************************************************************

* Function Clean Up

************************************************************************/

return (ER_SUCCESS);

}

/**************************************************************************

* Business Function: ComputeTimeDifferenceD3N

*

* Description: Computes Difference between 2 Date/Times

*

* Parameters:

* LPBHVRCOM lpBhvrCom Business Function Communications

* LPVOID lpVoid Void Parameter - DO NOT USE!

* LPDS lpDS Parameter Data Structure Pointer

*

*************************************************************************/

JDEBFRTN (ID) JDEBFWINAPI ComputeTimeDifferenceD3N (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N070A lpDS)

{

/************************************************************************

* Variable declarations

************************************************************************/

intrc;

intiOffset;

JDEDATEjdFirst, jdSecond;

time_ttimer;

unsigned longlFirst = 0;

unsigned longlSecond = 0;

unsigned longlDifference=0;

charszTemp[10] = "";

/************************************************************************

* Declare structures

************************************************************************/

struct tmtmFirst, tmSecond;

/************************************************************************

* Declare pointers

************************************************************************/

/************************************************************************

* Check for NULL pointers

************************************************************************/

if ((lpBhvrCom == (LPBHVRCOM) NULL) ||

(lpVoid == (LPVOID) NULL) ||

(lpDS == (LPDSDD3N070A ) NULL))

{

jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, "4363", (LPVOID) NULL);

return ER_ERROR;

}

/************************************************************************

* Set pointers

************************************************************************/

/************************************************************************

* Main Processing

************************************************************************/

if( ! strcmp( lpDS->szszGenericStr20A, "*NOW" ) )

{

JDEDATEToday(&jdFirst);

timer = time(0);

memcpy( &tmFirst, localtime( &timer ), sizeof( struct tm ));

}

else

{

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20A ,4);

tmFirst.tm_year = atoi(szTemp) - 1900;

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20A + 4 ,2);

tmFirst.tm_mon = atoi(szTemp) - 1;

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20A + 6 ,2);

tmFirst.tm_mday = atoi(szTemp);

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20A + 8 ,2);

tmFirst.tm_hour = atoi(szTemp);

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20A + 10 ,2);

tmFirst.tm_min = atoi(szTemp);

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20A + 12 ,2);

tmFirst.tm_sec = atoi(szTemp);

sprintf( szTemp, "%04d%02d%02d", tmFirst.tm_year + 1900, tmFirst.tm_mon + 1, tmFirst.tm_mday );

DeformatDate(&jdFirst, szTemp, "EOA");

}

if( ! strcmp( lpDS->szszGenericStr20B, "*NOW" ) )

{

JDEDATEToday(&jdSecond);

timer = time(0);

memcpy( &tmSecond, localtime( &timer ), sizeof( struct tm ));

}

else

{

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20B ,4);

tmSecond.tm_year = atoi(szTemp) - 1900;

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20B + 4 ,2);

tmSecond.tm_mon = atoi(szTemp) - 1;

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20B + 6 ,2);

tmSecond.tm_mday = atoi(szTemp);

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20B + 8 ,2);

tmSecond.tm_hour = atoi(szTemp);

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20B + 10 ,2);

tmSecond.tm_min = atoi(szTemp);

memset( szTemp, 0, sizeof(szTemp) );

strncpy(szTemp, lpDS->szszGenericStr20B + 12 ,2);

tmSecond.tm_sec = atoi(szTemp);

sprintf( szTemp, "%04d%02d%02d", tmSecond.tm_year + 1900, tmSecond.tm_mon + 1, tmSecond.tm_mday );

DeformatDate(&jdSecond, szTemp, "EOA");

}

rc = MathNumericToInt(&lpDS->mnmnTimeZoneOffset, &iOffset);

/***** TIME *****/

/* convert first time to total seconds */

lFirst = ( tmFirst.tm_hour * 3600 ) + (tmFirst.tm_min * 60) + tmFirst.tm_sec;

/* add time zone offset */

tmSecond.tm_hour += iOffset;

/* check for past midnight condition */

while( tmSecond.tm_hour >= 24 )

{

tmSecond.tm_hour -= 24;

jdSecond = AdvanceOneDay( jdSecond );

}

while( tmSecond.tm_hour < 0 )

{

tmSecond.tm_hour += 24;

jdSecond = DecrementOneDay( jdSecond );

}

/* convert second time to total seconds */

lSecond = (tmSecond.tm_hour * 3600 ) + (tmSecond.tm_min * 60) + tmSecond.tm_sec;

/* subtract difference */

lDifference = abs(lFirst - lSecond);

/* store difference */

rc = IntToMathNumeric((int) lDifference, &lpDS->mnMathNumeric01);

/***** DATE *****/

/* calc difference between dates */

lDifference = DateDifference(&jdFirst, &jdSecond);

/* store difference */

rc = IntToMathNumeric((int) lDifference, &lpDS->mnMathNumeric02);

/************************************************************************

* Function Clean Up

************************************************************************/

return (ER_SUCCESS);

}

JDEBFRTN (ID) JDEBFWINAPI GetCurrentDateTime (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N070B lpDS)

{

/************************************************************************

* Variable declarations

************************************************************************/

char *tme;

/************************************************************************

* Declare structures

************************************************************************/

time_ttimer;

struct tm*pNow;

JDEDATEjdToday;

intiOffset;

intrc;

/************************************************************************

* Declare pointers

************************************************************************/

/************************************************************************

* Check for NULL pointers

************************************************************************/

if ((lpBhvrCom == (LPBHVRCOM) NULL) ||

(lpVoid == (LPVOID) NULL) ||

(lpDS == (LPDSDD3N070B)NULL))

{

jdeErrorSet (lpBhvrCom, lpVoid, (ID) 0, "4363", (LPVOID) NULL);

return ER_ERROR;

}

/************************************************************************

* Set pointers

************************************************************************/

/************************************************************************

* Main Processing

************************************************************************/

timer = time(0);

pNow = localtime( &timer );

/* return todays date */

JDEDATEToday( &jdToday );

sprintf( lpDS->szszGenericStr20A, "%04d%02d%02d%02d%02d%02d",

jdToday.nYear, jdToday.nMonth, jdToday.nDay,

pNow->tm_hour, pNow->tm_min, pNow->tm_sec );

/* return todays date plus time zone offset */

rc = MathNumericToInt(&lpDS->mnmnTimeZoneOffset, &iOffset);

pNow->tm_hour += iOffset;

while( pNow->tm_hour >= 24 )

{

pNow->tm_hour -= 24;

jdToday = AdvanceOneDay( jdToday );

}

while( pNow->tm_hour < 0 )

{

pNow->tm_hour += 24;

jdToday = DecrementOneDay( jdToday );

}

sprintf( lpDS->szszGenericStr20B, "%04d%02d%02d%02d%02d%02d",

jdToday.nYear, jdToday.nMonth, jdToday.nDay,

pNow->tm_hour, pNow->tm_min, pNow->tm_sec );

/************************************************************************

* Function Clean Up

************************************************************************/

return (ER_SUCCESS);

}

Header File: BD3N070.h

/*****************************************************************************

* Header File: BD3N070.h

*

* Description: Date Conversion Header File

*

* History:

* Date Programmer SAR# - Description

* ------

* Author 06/12/1997 Delancy 1 - Created

*

*

* Copyright (c) J.D. Edwards World Source Company, 1996

*

* This unpublished material is proprietary to J.D. Edwards World Source

* Company. All rights reserved. The methods and techniques described

* herein are considered trade secrets and/or confidential. Reproduction

* or distribution, in whole or in part, is forbidden except by express

* written permission of J.D. Edwards World Source Company.

****************************************************************************/

#ifndef __BD3N070_H

#define __BD3N070_H

/*****************************************************************************

* Table Header Inclusions

****************************************************************************/

/*****************************************************************************

* External Business Function Header Inclusions

****************************************************************************/

/*****************************************************************************

* Global Definitions

****************************************************************************/

/*****************************************************************************

* Structure Definitions

****************************************************************************/

/*****************************************************************************

* DS Template Type Definitions

****************************************************************************/

/*****************************************

* TYPEDEF for Data Structure

* Template Name: JDE date conversion

* Template ID: DD3N070

* Generated: Thu Jun 12 17:04:53 1997

*

* DO NOT EDIT THE FOLLOWING TYPEDEF

* To make modifications, use the Everest Data Structure

* Tool to Generate a revised version, and paste from

* the clipboard.

*

**************************************/

#ifndef DATASTRUCTURE_DD3N070

#define DATASTRUCTURE_DD3N070

typedef struct tagDSDD3N070

{

char szItemName[33];

JDEDATE jdDate01;

char szParamter1DataItem[11];

} DSDD3N070, *LPDSDD3N070;

#define IDERRszItemName_1 1L

#define IDERRjdDate01_2 2L

#define IDERRszParamter1DataItem_3 3L

#endif

/*****************************************

* TYPEDEF for Data Structure

* Template Name: dcLINK Date/time Difference Parameters

* Template ID: DD3N070A

* Generated: Fri Jun 13 10:12:55 1997

*

* DO NOT EDIT THE FOLLOWING TYPEDEF

* To make modifications, use the Everest Data Structure

* Tool to Generate a revised version, and paste from

* the clipboard.

*

**************************************/

#ifndef DATASTRUCTURE_DD3N070A

#define DATASTRUCTURE_DD3N070A

typedef struct tagDSDD3N070A

{

char szszGenericStr20A[21];

char szszGenericStr20B[21];

MATH_NUMERIC mnmnTimeZoneOffset;

MATH_NUMERIC mnMathNumeric01;

MATH_NUMERIC mnMathNumeric02;

} DSDD3N070A, *LPDSDD3N070A;

#define IDERRszszGenericStr20A_1 1L

#define IDERRszszGenericStr20B_2 2L

#define IDERRmnmnTimeZoneOffset_3 3L

#define IDERRmnMathNumeric01_5 5L

#define IDERRmnMathNumeric02_6 6L

#endif

/*****************************************

* TYPEDEF for Data Structure

* Template Name: dcLINK Get current date and time

* Template ID: DD3N070B

* Generated: Mon Jun 30 20:52:42 1997

*

* DO NOT EDIT THE FOLLOWING TYPEDEF

* To make modifications, use the Everest Data Structure

* Tool to Generate a revised version, and paste from

* the clipboard.

*

**************************************/

#ifndef DATASTRUCTURE_DD3N070B

#define DATASTRUCTURE_DD3N070B

typedef struct tagDSDD3N070B

{

char szszGenericStr20A[21];

char szszGenericStr20B[21];

MATH_NUMERIC mnmnTimeZoneOffset;

} DSDD3N070B, *LPDSDD3N070B;

#define IDERRszszGenericStr20A_1 1L

#define IDERRszszGenericStr20B_3 3L

#define IDERRmnmnTimeZoneOffset_4 4L

#endif

/*****************************************************************************

* Source Preprocessor Definitions

****************************************************************************/

#if defined (JDEBFRTN)

#undef JDEBFRTN

#endif

#if defined (WIN32)

#if defined (WIN32)

#define JDEBFRTN(r) __declspec(dllexport) r

#else

#define JDEBFRTN(r) __declspec(dllimport) r

#endif

#else

#define JDEBFRTN(r) r

#endif

/*****************************************************************************

* Business Function Prototypes

****************************************************************************/

JDEBFRTN (ID) JDEBFWINAPI JDEDateToReaderDeviceD3N (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N070 lpDS);

JDEBFRTN (ID) JDEBFWINAPI ReaderDeviceDateToJDEDateD3N (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N070 lpDS);

JDEBFRTN (ID) JDEBFWINAPI ComputeTimeDifferenceD3N (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N070A lpDS);

JDEBFRTN (ID) JDEBFWINAPI GetCurrentDateTime (LPBHVRCOM lpBhvrCom, LPVOID lpVoid, LPDSDD3N070B lpDS);

/*****************************************************************************

* Internal Function Prototypes

****************************************************************************/

#endif /* __BD3N070_H */