From 655ff7c26f75ef96319ed7d4fd175df027b3ee7f Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Sat, 13 Nov 1999 12:38:23 +0000 Subject: [PATCH] 19991113-13:25 GMT+1 Victor Szel --- harbour/ChangeLog | 23 +++ harbour/include/extend.h | 1 + harbour/source/rtl/dates.c | 308 ++++++++++++++++++++++------------ harbour/source/rtl/extend.c | 37 ++++ harbour/source/rtl/math.c | 10 +- harbour/source/rtl/strings.c | 4 +- harbour/source/rtl/transfrm.c | 8 +- harbour/source/vm/hvm.c | 5 +- harbour/tests/rtl_test.prg | 136 +++++++++++++++ 9 files changed, 418 insertions(+), 114 deletions(-) diff --git a/harbour/ChangeLog b/harbour/ChangeLog index aa4c16c1f4..bfa845d428 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -1,3 +1,26 @@ +19991113-13:25 GMT+1 Victor Szel + * source/rtl/extend.c + include/extend.h + + hb_pardsbuff() Extend API function added, which does the same as + hb_pards(), but multi-thread friendly without any tricks, it will simply + accept a buffer for the return value. + * source/rtl/dates.c + source/rtl/math.c + source/rtl/strings.c + source/rtl/transform.c + * Changed to use hb_pardsbuff() instead of hb_pards() + DTOC(), DTOS(), MIN(), MAX(), TRANSFORM(), PAD*() + * tests/rtl_test.prg + + DTOC(), DTOS(), DAY(), MONTH(), YEAR(), DAY(), DOW(), CMONTH(), CDOW(), + TIME(), CTOD() regression tests added. + * source/rtl/dates.c + % Small optimalizations. + ! Error substitution added for all date functions. + + CTOD() - Added missing runtime error. + ! CDOW() - Fixed for empty and bad dates. + * source/vm/hvm.c + * hb_stack.szDate changed to local buffer. + 19991113-03:23 GMT+1 Victor Szel * source/rtl/itemapi.c % hb_evalNew(), hb_evalPutParam(), hb_evalRelease(), hb_itemRelease(), diff --git a/harbour/include/extend.h b/harbour/include/extend.h index d24c1ca6d5..d1a0540a6b 100644 --- a/harbour/include/extend.h +++ b/harbour/include/extend.h @@ -243,6 +243,7 @@ extern char * hb_parc( int iParam, ... ); /* retrieve a string parameter */ extern ULONG hb_parclen( int iParam, ... ); /* retrieve a string parameter length */ extern ULONG hb_parcsiz( int iParam, ... ); extern char * hb_pards( int iParam, ... ); /* retrieve a date as a string yyyymmdd */ +extern char * hb_pardsbuff( char * szDate, int iParam, ... ); /* retrieve a date as a string yyyymmdd */ extern ULONG hb_parinfa( int iParamNum, ULONG uiArrayIndex ); extern int hb_parinfo( int iParam ); /* Determine the param count or data type */ extern int hb_parl( int iParam, ... ); /* retrieve a logical parameter as an int */ diff --git a/harbour/source/rtl/dates.c b/harbour/source/rtl/dates.c index d5d49feb33..a765444b6d 100644 --- a/harbour/source/rtl/dates.c +++ b/harbour/source/rtl/dates.c @@ -101,6 +101,7 @@ double hb_secondsToday( void ) ftime( &tb ); oTime = localtime( &tb.time ); + return ( oTime->tm_hour * 3600 ) + ( oTime->tm_min * 60 ) + oTime->tm_sec + @@ -123,33 +124,32 @@ char * hb_cdow( int iDay ) long hb_dateEncode( long lDay, long lMonth, long lYear ) { - BOOL bValid = FALSE; - long lFactor = ( lMonth < 3 ) ? -1 : 0; - HB_TRACE(HB_TR_DEBUG, ("hb_dateEncode(%ld, %ld, %ld)", lDay, lMonth, lYear)); /* Perform date validation */ - if( lMonth >= 1 && lMonth <= 12 && lDay >= 1 - && lYear >= 1 && lYear <= 2999 ) + if( lYear >= 1 && lYear <= 2999 && + lMonth >= 1 && lMonth <= 12 && + lDay >= 1 ) { /* Month, year, and lower day limits are simple, but upper day limit is dependent upon month and leap year */ - int aiDayLimit[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; + USHORT auiDayLimit[ 12 ] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; if( ( ( lYear % 4 == 0 && lYear % 100 != 0 ) || lYear % 400 == 0 ) ) - aiDayLimit[ 1 ] = 29; + auiDayLimit[ 1 ] = 29; - if( lDay <= ( long ) aiDayLimit[ ( int ) lMonth - 1 ] ) - bValid = TRUE; + if( lDay <= ( long ) auiDayLimit[ ( int ) lMonth - 1 ] ) + { + long lFactor = ( lMonth < 3 ) ? -1 : 0; + + return ( 1461 * ( lFactor + 4800 + lYear ) / 4 ) + + ( ( lMonth - 2 - ( lFactor * 12 ) ) * 367 ) / 12 - + ( 3 * ( ( lFactor + 4900 + lYear ) / 100 ) / 4 ) + + lDay - 32075; + } } - if( bValid ) - return ( 1461 * ( lFactor + 4800 + lYear ) / 4 ) + - ( ( lMonth - 2 - ( lFactor * 12 ) ) * 367 ) / 12 - - ( 3 * ( ( lYear + 4900 + lFactor ) / 100 ) / 4 ) + - lDay - 32075; - else - return 0; + return 0; } void hb_dateDecode( long julian, long * plDay, long * plMonth, long * plYear ) @@ -168,14 +168,16 @@ void hb_dateDecode( long julian, long * plDay, long * plMonth, long * plYear ) V = 80 * julian / 2447; U = V / 11; - if( plDay ) *plDay = julian - ( 2447 * V / 80 ); - if( plMonth ) *plMonth = V + 2 - ( U * 12 ); - if( plYear ) *plYear = X + U + ( W - 49 ) * 100; + *plDay = julian - ( 2447 * V / 80 ); + *plMonth = V + 2 - ( U * 12 ); + *plYear = X + U + ( W - 49 ) * 100; } else + { *plDay = *plMonth = *plYear = 0; + } } void hb_dateStrPut( char * szDate, long lDay, long lMonth, long lYear ) @@ -212,10 +214,12 @@ void hb_dateStrGet( const char * szDate, long * plDay, long * plMonth, long * pl ( ( szDate[ 2 ] - '0' ) * 10 ) + ( szDate[ 3 ] - '0' ); } else + { /* Date string missing or bad length, so force an empty date */ *plDay = *plMonth = *plYear = 0; + } } /* This function always closes the date with a zero byte, so it needs a @@ -249,85 +253,98 @@ HARBOUR HB_CTOD( void ) { if( hb_pcount() == 1 ) { - char * szDate = hb_parc( 1 ); - int d_value = 0, m_value = 0, y_value = 0; - char szDateFormat[ 9 ]; - - if( szDate ) + if( ISCHAR( 1 ) ) { - int d_pos = 0, m_pos = 0, y_pos = 0; - int count, digit, size = strlen( hb_set.HB_SET_DATEFORMAT ); + char * szDate = hb_parc( 1 ); + int d_value = 0, m_value = 0, y_value = 0; + char szDateFormat[ 9 ]; - for( count = 0; count < size; count++ ) + if( szDate ) { - switch( hb_set.HB_SET_DATEFORMAT[ count ] ) + int d_pos = 0, m_pos = 0, y_pos = 0; + int count, digit, size = strlen( hb_set.HB_SET_DATEFORMAT ); + + for( count = 0; count < size; count++ ) { - case 'D': - case 'd': - if( d_pos == 0 ) - { - if( m_pos == 0 && y_pos == 0 ) d_pos = 1; - else if( m_pos == 0 || y_pos == 0 ) d_pos = 2; - else d_pos = 3; - } - break; - case 'M': - case 'm': - if( m_pos == 0 ) - { - if( d_pos == 0 && y_pos == 0 ) m_pos = 1; - else if( d_pos == 0 || y_pos == 0 ) m_pos = 2; - else m_pos = 3; - } - break; - case 'Y': - case 'y': - if( y_pos == 0 ) - { - if( m_pos == 0 && d_pos == 0 ) y_pos = 1; - else if( m_pos == 0 || d_pos == 0 ) y_pos = 2; - else y_pos = 3; - } + switch( hb_set.HB_SET_DATEFORMAT[ count ] ) + { + case 'D': + case 'd': + if( d_pos == 0 ) + { + if( m_pos == 0 && y_pos == 0 ) d_pos = 1; + else if( m_pos == 0 || y_pos == 0 ) d_pos = 2; + else d_pos = 3; + } + break; + case 'M': + case 'm': + if( m_pos == 0 ) + { + if( d_pos == 0 && y_pos == 0 ) m_pos = 1; + else if( d_pos == 0 || y_pos == 0 ) m_pos = 2; + else m_pos = 3; + } + break; + case 'Y': + case 'y': + if( y_pos == 0 ) + { + if( m_pos == 0 && d_pos == 0 ) y_pos = 1; + else if( m_pos == 0 || d_pos == 0 ) y_pos = 2; + else y_pos = 3; + } + } + } + + size = strlen( szDate ); + + for( count = 0; count < size; count++ ) + { + digit = szDate[ count ]; + if( isdigit( digit ) ) + { + if( d_pos == 1 ) + d_value = ( d_value * 10 ) + digit - '0'; + else if( m_pos == 1 ) + m_value = ( m_value * 10 ) + digit - '0'; + else if( y_pos == 1 ) + y_value = ( y_value * 10 ) + digit - '0'; + } + else if( digit != ' ' ) + { + d_pos--; + m_pos--; + y_pos--; + } + } + + if( y_value > 0 && y_value < 100 ) + { + count = hb_set.HB_SET_EPOCH % 100; + digit = hb_set.HB_SET_EPOCH / 100; + + if( y_value >= count ) + y_value += ( digit * 100 ); + else + y_value += ( ( digit * 100 ) + 100 ); } } - size = strlen( szDate ); + sprintf( szDateFormat, "%04i%02i%02i", y_value, m_value, d_value ); - for( count = 0; count < size; count++ ) + hb_retds( szDateFormat ); + } + else + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1119, NULL, "CTOD" ); + + if( pResult ) { - digit = szDate[ count ]; - if( isdigit( digit ) ) - { - if( d_pos == 1 ) - d_value = ( d_value * 10 ) + digit - '0'; - else if( m_pos == 1 ) - m_value = ( m_value * 10 ) + digit - '0'; - else if( y_pos == 1 ) - y_value = ( y_value * 10 ) + digit - '0'; - } - else if( digit != ' ' ) - { - d_pos--; - m_pos--; - y_pos--; - } - } - - if( y_value > 0 && y_value < 100 ) - { - count = hb_set.HB_SET_EPOCH % 100; - digit = hb_set.HB_SET_EPOCH / 100; - - if( y_value >= count ) - y_value += ( digit * 100 ); - else - y_value += ( ( digit * 100 ) + 100 ); + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); } } - - sprintf( szDateFormat, "%04i%02i%02i", y_value, m_value, d_value ); - - hb_retds( szDateFormat ); } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "CTOD" ); /* NOTE: Clipper catches this at compile time! */ @@ -353,7 +370,7 @@ char * hb_dtoc( const char * szDate, char * szFormattedDate, const char * szDate if( szDate && szFormattedDate && strlen( szDate ) == 8 ) /* A valid date is always 8 characters */ { - const char *szPtr; + const char * szPtr; int digit; BOOL used_d, used_m, used_y; @@ -509,13 +526,21 @@ HARBOUR HB_DTOC( void ) { if( ISDATE( 1 ) ) { - char * szDate = hb_pards( 1 ); + char szDate[ 9 ]; char szFormatted[ 11 ]; - hb_retc( hb_dtoc( szDate, szFormatted, hb_set.HB_SET_DATEFORMAT ) ); + hb_retc( hb_dtoc( hb_pardsbuff( szDate, 1 ), szFormatted, hb_set.HB_SET_DATEFORMAT ) ); } else - hb_errRT_BASE( EG_ARG, 1118, NULL, "DTOC" ); + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1118, NULL, "DTOC" ); + + if( pResult ) + { + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); + } + } } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "DTOC" ); /* NOTE: Clipper catches this at compile time! */ @@ -530,9 +555,21 @@ HARBOUR HB_DTOS( void ) if( hb_pcount() == 1 ) { if( ISDATE( 1 ) ) - hb_retc( hb_pards( 1 ) ); + { + char szDate[ 9 ]; + + hb_retc( hb_pardsbuff( szDate, 1 ) ); + } else - hb_errRT_BASE( EG_ARG, 1120, NULL, "DTOS" ); + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1120, NULL, "DTOS" ); + + if( pResult ) + { + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); + } + } } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "DTOS" ); /* NOTE: Clipper catches this at compile time! */ @@ -557,7 +594,7 @@ HARBOUR HB_HB_STOD( void ) hb_retds( hb_parc( 1 ) ); } -HARBOUR HB_DAY( void ) +HARBOUR HB_YEAR( void ) { if( hb_pcount() == 1 ) { @@ -569,13 +606,21 @@ HARBOUR HB_DAY( void ) hb_dateDecode( pDate->item.asDate.value, &lDay, &lMonth, &lYear ); - hb_retnllen( lDay, 3 ); + hb_retnllen( lYear, 5 ); } else - hb_errRT_BASE( EG_ARG, 1114, NULL, "DAY" ); + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1112, NULL, "YEAR" ); + + if( pResult ) + { + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); + } + } } else - hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "DAY" ); /* NOTE: Clipper catches this at compile time! */ + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "YEAR" ); /* NOTE: Clipper catches this at compile time! */ } HARBOUR HB_MONTH( void ) @@ -593,13 +638,21 @@ HARBOUR HB_MONTH( void ) hb_retnllen( lMonth, 3 ); } else - hb_errRT_BASE( EG_ARG, 1113, NULL, "MONTH" ); + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1113, NULL, "MONTH" ); + + if( pResult ) + { + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); + } + } } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "MONTH" ); /* NOTE: Clipper catches this at compile time! */ } -HARBOUR HB_YEAR( void ) +HARBOUR HB_DAY( void ) { if( hb_pcount() == 1 ) { @@ -611,13 +664,21 @@ HARBOUR HB_YEAR( void ) hb_dateDecode( pDate->item.asDate.value, &lDay, &lMonth, &lYear ); - hb_retnllen( lYear, 5 ); + hb_retnllen( lDay, 3 ); } else - hb_errRT_BASE( EG_ARG, 1112, NULL, "YEAR" ); + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1114, NULL, "DAY" ); + + if( pResult ) + { + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); + } + } } else - hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "YEAR" ); /* NOTE: Clipper catches this at compile time! */ + hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "DAY" ); /* NOTE: Clipper catches this at compile time! */ } HARBOUR HB_TIME( void ) @@ -663,6 +724,7 @@ HARBOUR HB_DATE( void ) oTime = localtime( &t ); sprintf( szResult, "%04d%02d%02d", oTime->tm_year + 1900, oTime->tm_mon + 1, oTime->tm_mday ); #endif + hb_retds( szResult ); } else @@ -704,7 +766,15 @@ HARBOUR HB_DOW( void ) hb_retnllen( 0, 3 ); } else - hb_errRT_BASE( EG_ARG, 1115, NULL, "DOW" ); + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1115, NULL, "DOW" ); + + if( pResult ) + { + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); + } + } } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "DOW" ); /* NOTE: Clipper catches this at compile time! */ @@ -724,7 +794,15 @@ HARBOUR HB_CMONTH( void ) hb_retc( hb_cmonth( lMonth ) ); } else - hb_errRT_BASE( EG_ARG, 1116, NULL, "CMONTH" ); + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1116, NULL, "CMONTH" ); + + if( pResult ) + { + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); + } + } } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "CMONTH" ); /* NOTE: Clipper catches this at compile time! */ @@ -738,13 +816,26 @@ HARBOUR HB_CDOW( void ) if( pDate ) { - long lDay, lMonth, lYear; + if( pDate->item.asDate.value ) + { + long lDay, lMonth, lYear; - hb_dateDecode( pDate->item.asDate.value, &lDay, &lMonth, &lYear ); - hb_retc( hb_cdow( hb_dow( lDay, lMonth, lYear ) ) ); + hb_dateDecode( pDate->item.asDate.value, &lDay, &lMonth, &lYear ); + hb_retc( hb_cdow( hb_dow( lDay, lMonth, lYear ) ) ); + } + else + hb_retc( "" ); } else - hb_errRT_BASE( EG_ARG, 1117, NULL, "CDOW" ); + { + PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1117, NULL, "CDOW" ); + + if( pResult ) + { + hb_itemReturn( pResult ); + hb_itemRelease( pResult ); + } + } } else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "CDOW" ); /* NOTE: Clipper catches this at compile time! */ @@ -757,3 +848,4 @@ HARBOUR HB_SECONDS( void ) else hb_errRT_BASE( EG_ARGCOUNT, 3000, NULL, "SECONDS" ); /* NOTE: Clipper catches this at compile time! */ } + diff --git a/harbour/source/rtl/extend.c b/harbour/source/rtl/extend.c index 6b0e42e719..2f1cfa5b75 100644 --- a/harbour/source/rtl/extend.c +++ b/harbour/source/rtl/extend.c @@ -235,6 +235,43 @@ char * hb_pards( int iParam, ... ) return hb_dateDecStr( hb_stack.szDate, 0 ); } +/* NOTE: szDate must be a 9 chars wide buffer. */ + +char * hb_pardsbuff( char * szDate, int iParam, ... ) +{ + HB_TRACE(HB_TR_DEBUG, ("hb_pardsbuff(%d, ...)", iParam)); + + if( ( iParam >= 0 && iParam <= hb_pcount() ) || ( iParam == -1 ) ) + { + PHB_ITEM pItem; + + if( iParam == -1 ) + pItem = &hb_stack.Return; + else + pItem = hb_stack.pBase + 1 + iParam; + + if( IS_BYREF( pItem ) ) + pItem = hb_itemUnRef( pItem ); + + if( IS_DATE( pItem ) ) + return hb_dateDecStr( szDate, pItem->item.asDate.value ); + + else if( IS_ARRAY( pItem ) ) + { + va_list va; + ULONG ulArrayIndex; + + va_start( va, iParam ); + ulArrayIndex = va_arg( va, ULONG ); + va_end( va ); + + return hb_arrayGetDS( pItem, ulArrayIndex, szDate ); + } + } + + return hb_dateDecStr( szDate, 0 ); +} + int hb_parl( int iParam, ... ) { HB_TRACE(HB_TR_DEBUG, ("hb_parl(%d, ...)", iParam)); diff --git a/harbour/source/rtl/math.c b/harbour/source/rtl/math.c index a8f5336b62..622929c6d1 100644 --- a/harbour/source/rtl/math.c +++ b/harbour/source/rtl/math.c @@ -300,8 +300,11 @@ HARBOUR HB_MAX( void ) } } else if( IS_DATE( p1 ) && IS_DATE( p2 ) ) - hb_retds( hb_itemGetNL( p1 ) >= hb_itemGetNL( p2 ) ? hb_pards( 1 ) : hb_pards( 2 ) ); + { + char szDate[ 9 ]; + hb_retds( hb_itemGetNL( p1 ) >= hb_itemGetNL( p2 ) ? hb_pardsbuff( szDate, 1 ) : hb_pardsbuff( szDate, 2 ) ); + } else { PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1093, NULL, "MAX" ); @@ -359,8 +362,11 @@ HARBOUR HB_MIN( void ) } } else if( IS_DATE( p1 ) && IS_DATE( p2 ) ) - hb_retds( hb_itemGetNL( p1 ) <= hb_itemGetNL( p2 ) ? hb_pards( 1 ) : hb_pards( 2 ) ); + { + char szDate[ 9 ]; + hb_retds( hb_itemGetNL( p1 ) <= hb_itemGetNL( p2 ) ? hb_pardsbuff( szDate, 1 ) : hb_pardsbuff( szDate, 2 ) ); + } else { PHB_ITEM pResult = hb_errRT_BASE_Subst( EG_ARG, 1092, NULL, "MIN" ); diff --git a/harbour/source/rtl/strings.c b/harbour/source/rtl/strings.c index cc3987ec5d..052d693d0f 100644 --- a/harbour/source/rtl/strings.c +++ b/harbour/source/rtl/strings.c @@ -381,7 +381,9 @@ static char * hb_itemPadConv( PHB_ITEM pItem, char * buffer, ULONG * pulSize ) } else if( IS_DATE( pItem ) ) { - szText = hb_dtoc( hb_pards( 1 ), buffer, hb_set.HB_SET_DATEFORMAT ); + char szDate[ 9 ]; + + szText = hb_dtoc( hb_pardsbuff( szDate, 1 ), buffer, hb_set.HB_SET_DATEFORMAT ); *pulSize = strlen( szText ); } else if( IS_INTEGER( pItem ) ) diff --git a/harbour/source/rtl/transfrm.c b/harbour/source/rtl/transfrm.c index 7d8d46ee77..c893bc8d81 100644 --- a/harbour/source/rtl/transfrm.c +++ b/harbour/source/rtl/transfrm.c @@ -572,8 +572,10 @@ HARBOUR HB_TRANSFORM( void ) } case IT_DATE: { + char szDate[ 9 ]; char szResult[ 11 ]; - DatePicture( hb_pards( 1 ), uiPicFlags, szResult ); + + DatePicture( hb_pardsbuff( szDate, 1 ), uiPicFlags, szResult ); hb_retc( szResult ); break; } @@ -613,8 +615,10 @@ HARBOUR HB_TRANSFORM( void ) } case IT_DATE: { + char szDate[ 9 ]; char szResult[ 11 ]; - DatePicture( hb_pards( 1 ), 0, szResult ); + + DatePicture( hb_pardsbuff( szDate, 1 ), 0, szResult ); hb_retc( szResult ); break; } diff --git a/harbour/source/vm/hvm.c b/harbour/source/vm/hvm.c index f02bdcbf50..3f455086d4 100644 --- a/harbour/source/vm/hvm.c +++ b/harbour/source/vm/hvm.c @@ -3088,7 +3088,10 @@ static void hb_stackDispLocal( void ) break; case IT_DATE: - printf( "DATE = \"%s\" ", hb_itemGetDS( pBase, hb_stack.szDate ) ); + { + char szDate[ 9 ]; + printf( "DATE = \"%s\" ", hb_itemGetDS( pBase, szDate ) ); + } break; case IT_DOUBLE: diff --git a/harbour/tests/rtl_test.prg b/harbour/tests/rtl_test.prg index 77ff19dbf7..36e7f1266b 100644 --- a/harbour/tests/rtl_test.prg +++ b/harbour/tests/rtl_test.prg @@ -145,6 +145,7 @@ FUNCTION Main( cPar1, cPar2 ) Main_HVM() Main_MATH() + Main_DATE() Main_STRINGS() #ifdef __HARBOUR__ New_STRINGS() @@ -1222,6 +1223,141 @@ STATIC FUNCTION Main_MATH() RETURN NIL +STATIC FUNCTION Main_DATE() + LOCAL cDate := "1999/11/25" + + /* YEAR() */ + + TEST_LINE( Year(NIL) , "E BASE 1112 Argument error YEAR F:S" ) + TEST_LINE( Year(100) , "E BASE 1112 Argument error YEAR F:S" ) +#ifdef __HARBOUR__ + TEST_LINE( Year(@sdDate) , 1980 ) /* Bug in CA-Cl*pper, it returns: "E BASE 1112 Argument error YEAR F:S" */ +#endif + TEST_LINE( Year(sdDate) , 1980 ) + TEST_LINE( Year(sdDateE) , 0 ) + + /* MONTH() */ + + TEST_LINE( Month(NIL) , "E BASE 1113 Argument error MONTH F:S" ) + TEST_LINE( Month(100) , "E BASE 1113 Argument error MONTH F:S" ) +#ifdef __HARBOUR__ + TEST_LINE( Month(@sdDate) , 1 ) /* Bug in CA-Cl*pper, it returns: "E BASE 1113 Argument error MONTH F:S" */ +#endif + TEST_LINE( Month(sdDate) , 1 ) + TEST_LINE( Month(sdDateE) , 0 ) + + /* DAY() */ + + TEST_LINE( Day(NIL) , "E BASE 1114 Argument error DAY F:S" ) + TEST_LINE( Day(100) , "E BASE 1114 Argument error DAY F:S" ) +#ifdef __HARBOUR__ + TEST_LINE( Day(@sdDate) , 1 ) /* Bug in CA-Cl*pper, it returns: "E BASE 1114 Argument error DAY F:S" */ +#endif + TEST_LINE( Day(sdDate) , 1 ) + TEST_LINE( Day(sdDateE) , 0 ) + + /* TIME() */ + + TEST_LINE( Len(Time()) , 8 ) + + /* DOW() */ + + TEST_LINE( Dow(NIL) , "E BASE 1115 Argument error DOW F:S" ) + TEST_LINE( Dow(100) , "E BASE 1115 Argument error DOW F:S" ) +#ifdef __HARBOUR__ + TEST_LINE( Dow(@sdDate) , 3 ) /* Bug in CA-Cl*pper, it returns: "E BASE 1115 Argument error DOW F:S" */ +#endif + TEST_LINE( Dow(sdDate) , 3 ) + TEST_LINE( Dow(sdDateE) , 0 ) + TEST_LINE( Dow(SToD("20000222")) , 3 ) + TEST_LINE( Dow(SToD("20000223")) , 4 ) + TEST_LINE( Dow(SToD("20000224")) , 5 ) + TEST_LINE( Dow(SToD("20000225")) , 6 ) + TEST_LINE( Dow(SToD("20000226")) , 7 ) + TEST_LINE( Dow(SToD("20000227")) , 1 ) + TEST_LINE( Dow(SToD("20000228")) , 2 ) + TEST_LINE( Dow(SToD("20000229")) , 3 ) + TEST_LINE( Dow(SToD("20000230")) , 0 ) + TEST_LINE( Dow(SToD("20000231")) , 0 ) + TEST_LINE( Dow(SToD("20000301")) , 4 ) + + /* CMONTH() */ + + TEST_LINE( CMonth(NIL) , "E BASE 1116 Argument error CMONTH F:S" ) + TEST_LINE( CMonth(100) , "E BASE 1116 Argument error CMONTH F:S" ) +#ifdef __HARBOUR__ + TEST_LINE( CMonth(@sdDate) , "January" ) /* Bug in CA-Cl*pper, it returns: "E BASE 1116 Argument error CMONTH F:S" */ +#endif + TEST_LINE( CMonth(sdDate) , "January" ) + TEST_LINE( CMonth(sdDateE) , "" ) + TEST_LINE( CMonth(SToD("19990101")) , "January" ) + TEST_LINE( CMonth(SToD("19990201")) , "February" ) + TEST_LINE( CMonth(SToD("19990301")) , "March" ) + TEST_LINE( CMonth(SToD("19990401")) , "April" ) + TEST_LINE( CMonth(SToD("19990501")) , "May" ) + TEST_LINE( CMonth(SToD("19990601")) , "June" ) + TEST_LINE( CMonth(SToD("19990701")) , "July" ) + TEST_LINE( CMonth(SToD("19990801")) , "August" ) + TEST_LINE( CMonth(SToD("19990901")) , "September" ) + TEST_LINE( CMonth(SToD("19991001")) , "October" ) + TEST_LINE( CMonth(SToD("19991101")) , "November" ) + TEST_LINE( CMonth(SToD("19991201")) , "December" ) + + /* CDOW() */ + + TEST_LINE( CDow(NIL) , "E BASE 1117 Argument error CDOW F:S" ) + TEST_LINE( CDow(100) , "E BASE 1117 Argument error CDOW F:S" ) +#ifdef __HARBOUR__ + TEST_LINE( CDow(@sdDate) , "Tuesday" ) /* Bug in CA-Cl*pper, it returns: "E BASE 1117 Argument error CDOW F:S" */ +#endif + TEST_LINE( CDow(sdDate) , "Tuesday" ) + TEST_LINE( CDow(sdDateE) , "" ) + TEST_LINE( CDow(SToD("20000222")) , "Tuesday" ) + TEST_LINE( CDow(SToD("20000223")) , "Wednesday" ) + TEST_LINE( CDow(SToD("20000224")) , "Thursday" ) + TEST_LINE( CDow(SToD("20000225")) , "Friday" ) + TEST_LINE( CDow(SToD("20000226")) , "Saturday" ) + TEST_LINE( CDow(SToD("20000227")) , "Sunday" ) + TEST_LINE( CDow(SToD("20000228")) , "Monday" ) + TEST_LINE( CDow(SToD("20000229")) , "Tuesday" ) + TEST_LINE( CDow(SToD("20000230")) , "" ) + TEST_LINE( CDow(SToD("20000231")) , "" ) + TEST_LINE( CDow(SToD("20000301")) , "Wednesday" ) + + /* DTOC() */ + + TEST_LINE( DToC(NIL) , "E BASE 1118 Argument error DTOC F:S" ) + TEST_LINE( DToC(100) , "E BASE 1118 Argument error DTOC F:S" ) + TEST_LINE( DToC("") , "E BASE 1118 Argument error DTOC F:S" ) +#ifdef __HARBOUR__ + TEST_LINE( DToC(@sdDate) , "1980.01.01" ) /* Bug in CA-Cl*pper, it returns: "E BASE 1118 Argument error DTOC F:S" */ +#endif + TEST_LINE( DToC(sdDate) , "1980.01.01" ) + TEST_LINE( DToC(sdDateE) , " . . " ) + + /* CTOD() */ + + TEST_LINE( CToD(NIL) , "E BASE 1119 Argument error CTOD F:S" ) + TEST_LINE( CToD(100) , "E BASE 1119 Argument error CTOD F:S" ) + TEST_LINE( CToD("") , SToD(" ") ) +#ifdef __HARBOUR__ + TEST_LINE( CToD(@cDate) , SToD("19991125") ) /* Bug in CA-Cl*pper, it returns: "E BASE 1119 Argument error CTOD F:S" */ +#endif + TEST_LINE( CToD(cDate) , SToD("19991125") ) + TEST_LINE( CToD("1999/11/25/10") , SToD("19991125") ) + + /* DTOS() */ + + TEST_LINE( DToS(NIL) , "E BASE 1120 Argument error DTOS F:S" ) + TEST_LINE( DToS(100) , "E BASE 1120 Argument error DTOS F:S" ) +#ifdef __HARBOUR__ + TEST_LINE( DToS(@sdDate) , "19800101" ) /* Bug in CA-Cl*pper, it returns: "E BASE 1120 Argument error DTOS F:S" */ +#endif + TEST_LINE( DToS(sdDate) , "19800101" ) + TEST_LINE( DToS(sdDateE) , " " ) + + RETURN NIL + STATIC FUNCTION Main_STRINGS() /* VAL() */