2000-05-31 13:53 UTC+0100 Victor Szakats <info@szelvesz.hu>

This commit is contained in:
Viktor Szakats
2000-05-31 11:54:28 +00:00
parent 2c39ddf384
commit 07088ae6a6
9 changed files with 195 additions and 138 deletions

View File

@@ -1,3 +1,35 @@
2000-05-31 13:53 UTC+0100 Victor Szakats <info@szelvesz.hu>
* include/hbapi.h
* source/vm/extend.c
+ Added hb_retl() Extend API function.
* HB_EXTEND_API_MACROS renamed to HB_API_MACROS
* include/hbdate.h
* source/rtl/dates.c
* source/rtl/dateshb.c
+ Added hb_dateToday() and hb_dateTimeStr() functions.
* source/rtl/trim.c
% Some minor optimizations.
* source/vm/classes.c
! Fixed varning, adjusted variable scopes.
* contrib/libmisc/dates2.c
% Some fixes, optimizations and copyright added.
From Jose Lalin:
* contrib/libmisc/dates2.c
- removed all occurences of:
char * szDateFormat[]
sprintf( szDateFormat, "%04i%02i%02i", (int) lYear, (int) lMonth, (int) lDay );
hb_retds( szDateFormat );
+ replaced with:
hb_retd( lYear, lMonth, lDay );
* This will speed up things a bit.
2000-05-30 10:30 UTC+0300 Chen Kedem <niki@actcom.co.il>
* doc/en/objfunc.txt

View File

@@ -33,35 +33,44 @@
*
*/
/*
* The following parts are Copyright of the individual authors.
* www - http://www.harbour-project.org
*
* Copyright 1999 Jon Berg <jmberg@pnh10.med.navy.mil>
* DateTime()
*
* See doc/license.txt for licensing terms.
*
*/
#include <ctype.h>
#include <time.h>
#include "hbapi.h"
#include "hbapierr.h"
#include "hbapiitm.h"
#include "hbapilng.h"
#include "hbdate.h"
static int hb__daysinmonth[ 12 ] =
static int s_daysinmonth[ 12 ] =
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
int hb_isleapyear( long lYear )
BOOL hb_isleapyear( long lYear )
{
HB_TRACE(HB_TR_DEBUG, ("hb_isleapyear(%ld)", lYear));
return (( lYear % 4 == 0 && lYear % 100 != 0 ) || lYear % 400 == 0 )?1:0;
return ( lYear % 4 == 0 && lYear % 100 != 0 ) || ( lYear % 400 == 0 );
}
long hb_daysinmonth( long lYear, long lMonth )
{
int i;
HB_TRACE(HB_TR_DEBUG, ("hb_daysinmonth(%ld, %ld)", lYear, lMonth));
i = hb_isleapyear( lYear );
if( lMonth > 0 && lMonth < 13 )
return hb__daysinmonth[ lMonth-1 ] + ((i&&lMonth == 2)?1:0);
return 0;
return s_daysinmonth[ lMonth - 1 ] +
( ( lMonth == 2 && hb_isleapyear( lYear ) ) ? 1 : 0 );
else
return 0;
}
long hb_doy( long lYear, long lMonth, long lDay )
@@ -73,9 +82,8 @@ long hb_doy( long lYear, long lMonth, long lDay )
for( i = 1; i < lMonth; i++ )
iDoy += hb_daysinmonth( lYear, i );
iDoy += lDay;
return iDoy;
return iDoy + lDay;
}
long hb_wom( long lYear, long lMonth, long lDay )
@@ -86,7 +94,7 @@ long hb_wom( long lYear, long lMonth, long lDay )
iWom = lDay + hb_dateDOW( lYear, lMonth, 1 ) - 1;
if( iWom > 0 )
return ( iWom - hb_dateDOW( lYear, lMonth, lDay ) ) / 7 + 1 ;
return ( iWom - hb_dateDOW( lYear, lMonth, lDay ) ) / 7 + 1;
else
return 0;
}
@@ -98,11 +106,11 @@ long hb_woy( long lYear, long lMonth, long lDay, BOOL bISO )
HB_TRACE(HB_TR_DEBUG, ("hb_woy(%ld, %ld, %ld, %d)", lYear, lMonth, lDay, (int) bISO));
lDay = hb_doy( lYear, lMonth, lDay );
n = ( ( ( 1 - (bISO ? 1 : 0) ) % 7 ) ) - 1;
lDay += (n>0)?1:0;
n = ( ( ( 1 - ( bISO ? 1 : 0 ) ) % 7 ) ) - 1;
lDay += ( n > 0 ) ? 1 : 0;
iWeek = lDay / 7;
if( bISO )
iWeek += (n<4)?1:0;
iWeek += ( n < 4 ) ? 1 : 0;
else
++iWeek;
@@ -112,58 +120,54 @@ long hb_woy( long lYear, long lMonth, long lDay, BOOL bISO )
HB_FUNC( AMONTHS )
{
PHB_ITEM pReturn = hb_itemArrayNew( 12 ); /* Create array */
PHB_ITEM pString;
int i;
for( i = 0; i < 12; i++ )
{
pString = hb_itemNew( NULL );
hb_itemPutC( pString, ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_MONTH + i ) );
PHB_ITEM pString = hb_itemPutC( NULL, ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_MONTH + i ) );
hb_itemArrayPut( pReturn, i+1, pString );
hb_itemRelease ( pString );
hb_itemRelease( pString );
}
hb_itemReturn ( pReturn );
hb_itemReturn( pReturn );
hb_itemRelease( pReturn );
}
HB_FUNC( ADAYS )
{
PHB_ITEM pReturn = hb_itemArrayNew( 7 ); /* Create array */
PHB_ITEM pString;
int i;
for( i = 0; i < 7; i++ )
{
pString = hb_itemNew( NULL );
hb_itemPutC( pString, ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_DAY + i ) );
hb_itemArrayPut( pReturn, i+1, pString );
hb_itemRelease ( pString );
PHB_ITEM pString = hb_itemPutC( NULL, ( char * ) hb_langDGetItem( HB_LANG_ITEM_BASE_DAY + i ) );
hb_itemArrayPut( pReturn, i + 1, pString );
hb_itemRelease( pString );
}
hb_itemReturn ( pReturn );
hb_itemReturn( pReturn );
hb_itemRelease( pReturn );
}
HB_FUNC( ISLEAPYEAR )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
hb_retl( hb_isleapyear( lYear ) );
}
else
{
hb_errRT_TOOLS(EG_ARG, 4001, NULL, "ISLEAPYEAR");
}
hb_retl( FALSE );
}
HB_FUNC( DAYSINMONTH )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
@@ -175,42 +179,40 @@ HB_FUNC( DAYSINMONTH )
HB_FUNC( EOM )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
char szDateFormat[ 9 ];
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
lDay = hb_daysinmonth( lYear, lMonth );
sprintf( szDateFormat, "%04i%02i%02i", (int) lYear, (int) lMonth, (int) lDay );
hb_retds( szDateFormat );
hb_retd( lYear, lMonth, hb_daysinmonth( lYear, lMonth ) );
}
else
hb_retds( "" );
hb_retdl( 0 );
}
HB_FUNC( BOM )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
char szDateFormat[ 9 ];
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
sprintf( szDateFormat, "%04i%02i%02i", (int) lYear, (int) lMonth, 1 );
hb_retds( szDateFormat );
hb_retd( lYear, lMonth, 1 );
}
else
hb_retds( "" );
hb_retdl( 0 );
}
HB_FUNC( WOM )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
@@ -222,9 +224,10 @@ HB_FUNC( WOM )
HB_FUNC( DOY )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
@@ -238,9 +241,10 @@ HB_FUNC( DOY )
HB_FUNC( WOY )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
@@ -252,46 +256,39 @@ HB_FUNC( WOY )
HB_FUNC( EOY )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
char szDateFormat[ 9 ];
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
sprintf( szDateFormat, "%04i%02i%02i", (int) lYear, 12, 31 );
hb_retds( szDateFormat );
hb_retd( lYear, 12, 31 );
}
else
hb_retds( "" );
hb_retdl( 0 );
}
HB_FUNC( BOY )
{
if( ISDATE( 1 ) )
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
if( pDate )
{
PHB_ITEM pDate = hb_param( 1, HB_IT_DATE );
long lYear, lMonth, lDay;
char szDateFormat[ 9 ];
hb_dateDecode( hb_itemGetDL( pDate ), &lYear, &lMonth, &lDay );
sprintf( szDateFormat, "%04i%02i%02i", (int) lYear, 1, 1 );
hb_retds( szDateFormat );
hb_retd( lYear, 1, 1 );
}
else
hb_retds( "" );
hb_retdl( 0 );
}
HB_FUNC( DATETIME )
{
time_t current_time;
char * szResult = ( char * ) hb_xgrab( 26 );
time( &current_time );
szResult = strcpy( szResult, ctime( &current_time ) );
hb_retc( szResult );
hb_xfree( szResult );
hb_retc( ctime( &current_time ) );
}

View File

@@ -269,7 +269,7 @@ extern int hb_parni( int iParam, ... ); /* retrieve a numeric parameter as
extern long hb_parnl( int iParam, ... ); /* retrieve a numeric parameter as a long */
extern PHB_ITEM hb_param( int iParam, int iMask ); /* retrieve a generic parameter */
#ifdef HB_EXTEND_API_MACROS
#ifdef HB_API_MACROS
#include "hbapiitm.h"
@@ -281,6 +281,7 @@ extern PHB_ITEM hb_param( int iParam, int iMask ); /* retrieve a generic paramet
#define hb_retclen( szText, ulLen ) hb_itemPutCL( &hb_stack.Return, szText, ulLen )
#define hb_retds( szDate ) hb_itemPutDS( &hb_stack.Return, szDate )
#define hb_retd( lYear, lMonth, lDay ) hb_itemPutD( &hb_stack.Return, lYear, lMonth, lDay )
#define hb_retdl( lJulian ) hb_itemPutDL( &hb_stack.Return, lJulian )
#define hb_retl( iLogical ) hb_itemPutL( &hb_stack.Return, iLogical ? TRUE : FALSE )
#define hb_retnd( dNumber ) hb_itemPutND( &hb_stack.Return, dNumber )
#define hb_retni( iNumber ) hb_itemPutNI( &hb_stack.Return, iNumber )
@@ -299,6 +300,7 @@ extern void hb_retc( char * szText ); /* returns a string */
extern void hb_retclen( char * szText, ULONG ulLen ); /* returns a string with a specific length */
extern void hb_retds( char * szDate ); /* returns a date, must use yyyymmdd format */
extern void hb_retd( long lYear, long lMonth, long lDay ); /* returns a date */
extern void hb_retdl( long lJulian ); /* returns a long value as a julian date */
extern void hb_retl( int iTrueFalse ); /* returns a logical integer */
extern void hb_retnd( double dNumber ); /* returns a double */
extern void hb_retni( int iNumber ); /* returns a integer number */

View File

@@ -43,6 +43,8 @@ extern "C" {
#endif
extern double hb_dateSeconds( void );
extern void hb_dateToday( long * plYear, long * plMonth, long * plDay );
extern void hb_dateTimeStr( char * pszTime );
extern char * hb_dateCMonth( int iMonth );
extern char * hb_dateCDOW( int iDay );
extern long hb_dateDOW( long lYear, long lMonth, long lDay );

View File

@@ -53,7 +53,15 @@
*
*/
#define HB_OS_WIN_32_USED
#include <ctype.h>
#include <time.h>
#if defined( OS_UNIX_COMPATIBLE )
#include <sys/timeb.h>
#else
#include <sys\timeb.h>
#endif
#include "hbapi.h"
#include "hbdate.h"
@@ -373,3 +381,50 @@ long hb_dateDOW( long lYear, long lMonth, long lDay )
lYear + lYear / 4 - lYear / 100 + lYear / 400 + 6 ) % 7 + 1;
}
void hb_dateToday( long * plYear, long * plMonth, long * plDay )
{
#if defined(HB_OS_WIN_32)
{
SYSTEMTIME st;
GetLocalTime( &st );
*plYear = st.wYear;
*plMonth = st.wMonth;
*plDay = st.wDay;
}
#else
{
time_t t;
struct tm * oTime;
time( &t );
oTime = localtime( &t );
*plYear = oTime->tm_year + 1900;
*plMonth = oTime->tm_mon + 1;
*plDay = oTime->tm_mday;
}
#endif
}
/* NOTE: The passed buffer must be at least 9 chars long */
void hb_dateTimeStr( char * pszTime )
{
#if defined(HB_OS_WIN_32)
{
SYSTEMTIME st;
GetLocalTime( &st );
sprintf( pszTime, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond );
}
#else
{
time_t t;
struct tm * oTime;
time( &t );
oTime = localtime( &t );
sprintf( pszTime, "%02d:%02d:%02d", oTime->tm_hour, oTime->tm_min, oTime->tm_sec );
}
#endif
}

View File

@@ -54,7 +54,7 @@
*
*/
#define HB_OS_WIN_32_USED
#include <ctype.h>
#include "hbapi.h"
#include "hbapierr.h"
@@ -62,14 +62,6 @@
#include "hbset.h"
#include "hbdate.h"
#include <ctype.h>
#include <time.h>
#if defined( OS_UNIX_COMPATIBLE )
#include <sys/timeb.h>
#else
#include <sys\timeb.h>
#endif
HB_FUNC( CTOD )
{
if( ISCHAR( 1 ) )
@@ -300,45 +292,15 @@ HB_FUNC( DAY )
HB_FUNC( TIME )
{
char szResult[ 9 ];
#if defined(HB_OS_WIN_32)
{
SYSTEMTIME st;
GetLocalTime( &st );
sprintf( szResult, "%02d:%02d:%02d", st.wHour, st.wMinute, st.wSecond );
}
#else
{
time_t t;
struct tm * oTime;
time( &t );
oTime = localtime( &t );
sprintf( szResult, "%02d:%02d:%02d", oTime->tm_hour, oTime->tm_min, oTime->tm_sec );
}
#endif
hb_dateTimeStr( szResult );
hb_retclen( szResult, 8 );
}
HB_FUNC( DATE )
{
#if defined(HB_OS_WIN_32)
{
SYSTEMTIME st;
GetLocalTime( &st );
hb_retd( st.wYear, st.wMonth, st.wDay );
}
#else
{
time_t t;
struct tm * oTime;
time( &t );
oTime = localtime( &t );
hb_retd( oTime->tm_year + 1900, oTime->tm_mon + 1, oTime->tm_mday );
}
#endif
long lYear, lMonth, lDay;
hb_dateToday( &lYear, &lMonth, &lDay );
hb_retd( lYear, lMonth, lDay );
}
HB_FUNC( DOW )

View File

@@ -96,10 +96,10 @@ HB_FUNC( LTRIM )
}
}
/* NOTE: The second parameter is a Harbour extension [vszakats] */
/* trims trailing spaces from a string */
/* NOTE: The second parameter is a Harbour extension. */
HB_FUNC( RTRIM )
{
PHB_ITEM pText = hb_param( 1, HB_IT_STRING );
@@ -107,9 +107,9 @@ HB_FUNC( RTRIM )
if( pText )
{
char * pszText = hb_itemGetCPtr( pText );
BOOL bAnySpace = ( ISLOG( 2 ) ? hb_parl( 2 ) : FALSE );
hb_retclen( pszText, hb_strRTrimLen( pszText, hb_itemGetCLen( pText ), bAnySpace ) );
hb_retclen( pszText, hb_strRTrimLen( pszText, hb_itemGetCLen( pText ),
ISLOG( 2 ) ? hb_parl( 2 ) : FALSE ) );
}
else
{
@@ -124,29 +124,28 @@ HB_FUNC( RTRIM )
}
}
/* NOTE: The second parameter is a Harbour extension [vszakats] */
/* synonymn for RTRIM */
HB_FUNC( TRIM )
{
HB_FUNCNAME( RTRIM )();
}
/* NOTE: The second parameter is a Harbour extension [vszakats] */
/* trims leading and trailing spaces from a string */
/* NOTE: The second parameter is a Harbour extension. */
HB_FUNC( ALLTRIM )
{
if( ISCHAR( 1 ) )
PHB_ITEM pText = hb_param( 1, HB_IT_STRING );
if( pText )
{
char * szText = hb_parc( 1 );
BOOL bAnySpace = ( ISLOG( 2 ) ? hb_parl( 2 ) : FALSE );
ULONG ulLen = hb_strRTrimLen( szText, hb_parclen( 1 ), bAnySpace );
char * pszText = hb_itemGetCPtr( pText );
ULONG ulLen = hb_strRTrimLen( pszText, hb_itemGetCLen( pText ),
ISLOG( 2 ) ? hb_parl( 2 ) : FALSE );
szText = hb_strLTrim( szText, &ulLen );
hb_retclen( szText, ulLen );
hb_strLTrim( pszText, &ulLen );
hb_retclen( pszText, ulLen );
}
else
#ifdef HB_COMPAT_C53

View File

@@ -880,6 +880,7 @@ HB_FUNC( __CLSNEW )
/* SharedDatas */
if( pSprCls->uiDatasShared )
{
if( pNewCls->pSharedDatas )
{
pNewCls->pSharedDatas = ( PHB_ITEM * ) hb_xrealloc( pNewCls->pSharedDatas, pSprCls->uiDatasShared * sizeof( PHB_ITEM ) );
@@ -894,6 +895,7 @@ HB_FUNC( __CLSNEW )
pNewCls->uiDatasShared = pSprCls->uiDatasShared;
hb_xmemcpy( pNewCls->pSharedDatas, pSprCls->pSharedDatas, sizeof( PHB_ITEM ) * pSprCls->uiDatasShared );
}
}
/* Inlines */
pClsAnyTmp = hb_arrayClone( pSprCls->pInlines );
@@ -1501,22 +1503,20 @@ HB_FUNC( __CLSPARENT )
HB_FUNC( __SENDER )
{
PHB_ITEM pBase = hb_stack.pBase;
PHB_ITEM oReturn ;
PHB_ITEM oSender;
PHB_ITEM oSender = NULL;
USHORT iLevel = 3;
char * szNameSender;
while( iLevel > 0 && pBase != hb_stack.pItems )
{
pBase = hb_stack.pItems + pBase->item.asSymbol.stackbase;
oSender = pBase + 1;
if( ( iLevel-- == 2 && ( oSender )->type != HB_IT_BLOCK ) || ( oSender )->type == HB_IT_NIL )
if( ( iLevel-- == 2 && oSender->type != HB_IT_BLOCK ) || oSender->type == HB_IT_NIL )
break;
}
if( iLevel == 0 && ( oSender )->type == HB_IT_OBJECT )
hb_itemCopy(&hb_stack.Return, oSender);
if( iLevel == 0 && oSender && oSender->type == HB_IT_OBJECT )
hb_itemReturn( oSender );
}
/* ================================================ */
@@ -1758,10 +1758,10 @@ static HARBOUR hb___msgSuper( void )
static HARBOUR hb___msgSetClsData( void )
{
USHORT uiClass = ( hb_stack.pBase + 1 )->item.asArray.value->uiClass;
PHB_ITEM pReturn = hb_stack.pBase + 2;
if( uiClass && uiClass <= s_uiClasses )
{
PHB_ITEM pReturn = hb_stack.pBase + 2;
hb_arraySet( s_pClasses[ uiClass - 1 ].pClassDatas,
s_pMethod->uiData, pReturn );
hb_itemReturn( pReturn );
@@ -1776,10 +1776,10 @@ static HARBOUR hb___msgSetClsData( void )
static HARBOUR hb___msgSetShrData( void )
{
USHORT uiClass = ( hb_stack.pBase + 1 )->item.asArray.value->uiClass;
PHB_ITEM pReturn = hb_stack.pBase + 2;
if( uiClass && uiClass <= s_uiClasses )
{
PHB_ITEM pReturn = hb_stack.pBase + 2;
hb_itemCopy( *( s_pClasses[ uiClass - 1 ].pSharedDatas + s_pMethod->uiDataShared ), pReturn );
hb_itemReturn( pReturn );
}

View File

@@ -42,6 +42,7 @@
* hb_retnilen()
* hb_retnllen()
* hb_retndlen()
* hb_retdl()
*
* Copyright 2000 Jose Lalin <dezac@corevia.com>
* hb_retd()
@@ -476,6 +477,13 @@ void hb_retd( long lYear, long lMonth, long lDay )
hb_itemPutD( &hb_stack.Return, lYear, lMonth, lDay );
}
void hb_retdl( long lJulian )
{
HB_TRACE(HB_TR_DEBUG, ("hb_retdl(%ld)", lJulian));
hb_itemPutDL( &hb_stack.Return, lJulian );
}
void hb_retl( int iLogical )
{
HB_TRACE(HB_TR_DEBUG, ("hb_retl(%d)", iLogical));