From 36d05d2e93ab9ef95e2962f921213d1927c777f4 Mon Sep 17 00:00:00 2001 From: Francesco Saverio Giudice Date: Sun, 22 Mar 2009 21:15:31 +0000 Subject: [PATCH] 2009-03-22 22:13 UTC+0100 Francesco Saverio Giudice (info/at/fsgiudice.com) + harbour/source/rtl/tscalart.c + Added scalar TIMESTAMP * harbour/source/rtl/Makefile + tscalart.c added * harbour/include/hbclass.ch * added HBTIMESTAMP scalar type to ENABLE TYPE CLASS * harbour/source/rtl/tscalar.prg + added scalar class TIMESTAMP with methods to extract parts from Timestamp: Date(), Time(), Year(), Month(), Day(), Hour(), Minute(), Sec() * added methods Year(), Month(), Day() to Date scalar class * harbour/contrib/hbwin/win_ole.c * updated for new Timestamp type --- harbour/ChangeLog | 15 +++++++ harbour/contrib/hbwin/win_ole.c | 36 ++++++++++++++-- harbour/include/hbclass.ch | 6 +-- harbour/source/rtl/Makefile | 1 + harbour/source/rtl/tscalar.prg | 62 ++++++++++++++++++++++++++++ harbour/source/rtl/tscalart.c | 73 +++++++++++++++++++++++++++++++++ 6 files changed, 186 insertions(+), 7 deletions(-) create mode 100644 harbour/source/rtl/tscalart.c diff --git a/harbour/ChangeLog b/harbour/ChangeLog index 9f51c556ad..5e91d599ad 100644 --- a/harbour/ChangeLog +++ b/harbour/ChangeLog @@ -8,6 +8,21 @@ 2009-12-31 13:59 UTC+0100 Foo Bar (foo.bar foobar.org) */ +2009-03-22 22:13 UTC+0100 Francesco Saverio Giudice (info/at/fsgiudice.com) + + harbour/source/rtl/tscalart.c + + Added scalar TIMESTAMP + * harbour/source/rtl/Makefile + + tscalart.c added + * harbour/include/hbclass.ch + * added HBTIMESTAMP scalar type to ENABLE TYPE CLASS + * harbour/source/rtl/tscalar.prg + + added scalar class TIMESTAMP with methods to extract + parts from Timestamp: + Date(), Time(), Year(), Month(), Day(), Hour(), Minute(), Sec() + * added methods Year(), Month(), Day() to Date scalar class + * harbour/contrib/hbwin/win_ole.c + * updated for new Timestamp type + 2009-03-22 21:54 UTC+0100 Przemyslaw Czerpak (druzus/at/priv.onet.pl) * harbour/source/rtl/valtoexp.prg + added timestamp support to hb_valToExp() and hb_cStr() functions diff --git a/harbour/contrib/hbwin/win_ole.c b/harbour/contrib/hbwin/win_ole.c index 2e9237cee8..52e9709f53 100644 --- a/harbour/contrib/hbwin/win_ole.c +++ b/harbour/contrib/hbwin/win_ole.c @@ -306,6 +306,8 @@ void hb_oleItemToVariant( VARIANT *pVariant, PHB_ITEM pItem ) VariantClear( pVariant ); + hb_ToOutDebug( "\n\rhb_itemType( pItem ) =%i\n\r", hb_itemType( pItem ) ); + switch( hb_itemType( pItem ) ) { case HB_IT_NIL: @@ -429,6 +431,8 @@ void hb_oleItemToVariant( VARIANT *pVariant, PHB_ITEM pItem ) { long lDate = hb_itemGetDL( pItem ); + hb_ToOutDebug( "Sono in HB_IT_DATE" ); + if( lDate == 0 ) pVariant->n1.n2.vt = VT_NULL; else if( bByRef ) @@ -446,6 +450,30 @@ void hb_oleItemToVariant( VARIANT *pVariant, PHB_ITEM pItem ) } break; + case HB_IT_TIMESTAMP: + { + double dDateTime = hb_itemGetTD( pItem ); + + hb_ToOutDebug( "Sono in HB_IT_TIMESTAMP" ); + + if( dDateTime == 0 ) + pVariant->n1.n2.vt = VT_NULL; + + else if( bByRef ) + { + hb_itemPutND( pItem, ( dDateTime - (double) 2415019 ) ); + + pVariant->n1.n2.vt = VT_BYREF | VT_DATE; + pVariant->n1.n2.n3.pdblVal = &( pItem->item.asDouble.value ); + } + else + { + pVariant->n1.n2.vt = VT_DATE; + pVariant->n1.n2.n3.dblVal = ( dDateTime - (double) 2415019 ); + } + } + break; + case HB_IT_POINTER: pVariant->n1.n2.vt = VT_PTR; pVariant->n1.n2.n3.byref = hb_itemGetPtr( pItem ); @@ -803,11 +831,11 @@ static void FreeParams( DISPPARAMS *pDispParams, PHB_ITEM *aPrgParams ) break; case VT_BYREF | VT_DATE: - hb_itemPutDL( pItem, ( long ) ( *( pVariant->n1.n2.n3.pdblVal ) ) + 2415019 ); + hb_itemPutTD( pItem, *pVariant->n1.n2.n3.pdblVal + ( double ) 2415019 ); break; case VT_DATE: - hb_itemPutDL( pItem, ( long ) ( pVariant->n1.n2.n3.dblVal ) + 2415019 ); + hb_itemPutTD( pItem, pVariant->n1.n2.n3.dblVal + ( double ) 2415019 ); break; case VT_BYREF | VT_EMPTY: @@ -1185,11 +1213,11 @@ HRESULT hb_oleVariantToItem( PHB_ITEM pItem, VARIANT *pVariant ) } case VT_DATE | VT_BYREF: - hb_itemPutDL( pItem, ( long ) ( *pVariant->n1.n2.n3.pdblVal ) + 2415019 ); + hb_itemPutTD( pItem, *pVariant->n1.n2.n3.pdblVal + ( double ) 2415019 ); break; case VT_DATE: - hb_itemPutDL( pItem, ( long ) ( pVariant->n1.n2.n3.dblVal ) + 2415019 ); + hb_itemPutTD( pItem, pVariant->n1.n2.n3.dblVal + ( double ) 2415019 ); break; case VT_EMPTY | VT_BYREF: diff --git a/harbour/include/hbclass.ch b/harbour/include/hbclass.ch index f67c04379d..0648b37157 100644 --- a/harbour/include/hbclass.ch +++ b/harbour/include/hbclass.ch @@ -590,13 +590,13 @@ DECLARE HBClass ; __clsAssocType( __clsInstSuper( @() ), # ) #command ENABLE TYPE CLASS ; + ARRAY, BLOCK, CHARACTER, DATE, HASH, LOGICAL, NIL, NUMERIC, SYMBOL, TIMESTAMP, POINTER> ; [, ] => ; + ARRAY, BLOCK, CHARACTER, DATE, HASH, LOGICAL, NIL, NUMERIC, SYMBOL, TIMESTAMP, POINTER>] => ; REQUEST HB [, HB] #command ENABLE TYPE CLASS ALL => ; REQUEST HBArray, HBBlock, HBCharacter, HBDate, HBHash, ; - HBLogical, HBNil, HBNumeric, HBSymbol, HBPointer + HBLogical, HBNil, HBNumeric, HBSymbol, HBTimeStamp, HBPointer #endif /* HB_CLASS_CH_ */ diff --git a/harbour/source/rtl/Makefile b/harbour/source/rtl/Makefile index 3b25e41a0b..57e0569d4b 100644 --- a/harbour/source/rtl/Makefile +++ b/harbour/source/rtl/Makefile @@ -158,6 +158,7 @@ C_SOURCES=\ tscalarn.c \ tscalarp.c \ tscalars.c \ + tscalart.c \ tscalaru.c \ type.c \ val.c \ diff --git a/harbour/source/rtl/tscalar.prg b/harbour/source/rtl/tscalar.prg index cbe05c7a69..a2a3eee737 100644 --- a/harbour/source/rtl/tscalar.prg +++ b/harbour/source/rtl/tscalar.prg @@ -82,6 +82,7 @@ METHOD AsString() CLASS ScalarObject CASE "M" CASE "C" ; RETURN Self CASE "D" ; RETURN DToC( Self ) + CASE "T" ; RETURN HB_TToC( Self ) CASE "H" ; RETURN "{ ... => ... }" CASE "L" ; RETURN iif( Self, ".T.", ".F." ) CASE "N" ; RETURN hb_NToS( Self ) @@ -98,6 +99,7 @@ METHOD AsExpStr() CLASS ScalarObject CASE "M" CASE "C" ; RETURN '"' + Self + '"' CASE "D" ; RETURN 'CToD("' + DToC( Self ) + '")' + CASE "T" ; RETURN 'HB_CToT("' + HB_TToC( Self ) + '")' ENDSWITCH RETURN ::AsString() @@ -271,6 +273,9 @@ METHOD AsExpStr() CLASS Character CREATE CLASS Date INHERIT HBScalar FUNCTION __HBDate + METHOD Year() + METHOD Month() + METHOD Day() METHOD AsString() METHOD AsExpStr() @@ -282,6 +287,63 @@ METHOD AsString() CLASS Date METHOD AsExpStr() CLASS Date RETURN 'CToD("' + ::AsString() + '")' +METHOD Year() CLASS Date + RETURN Year( Self ) + +METHOD Month() CLASS Date + RETURN Month( Self ) + +METHOD Day() CLASS Date + RETURN Day( Self ) + +/* -------------------------------------------- */ + +CREATE CLASS TimeStamp INHERIT HBScalar FUNCTION __HBTimeStamp + + METHOD Date() + METHOD Time() + METHOD Year() + METHOD Month() + METHOD Day() + METHOD Hour() + METHOD Minute() + METHOD Sec() + + METHOD AsString() + METHOD AsExpStr() + +ENDCLASS + +METHOD AsString() CLASS TimeStamp + RETURN HB_TTOS( Self ) + +METHOD AsExpStr() CLASS TimeStamp + RETURN 'HB_STOT("' + ::AsString() + '")' + +METHOD Date() CLASS TimeStamp + RETURN HB_TTOC( Self, NIL, "" ) + +METHOD Time() CLASS TimeStamp + RETURN HB_TTOC( Self, "", "HH:MM:SS" ) + +METHOD Year() CLASS TimeStamp + RETURN Year( Self ) + +METHOD Month() CLASS TimeStamp + RETURN Month( Self ) + +METHOD Day() CLASS TimeStamp + RETURN Day( Self ) + +METHOD Hour() CLASS TimeStamp + RETURN HB_HOUR( Self ) + +METHOD Minute() CLASS TimeStamp + RETURN HB_MINUTE( Self ) + +METHOD Sec() CLASS TimeStamp + RETURN HB_SEC( Self ) + /* -------------------------------------------- */ CREATE CLASS Hash INHERIT HBScalar FUNCTION __HBHash diff --git a/harbour/source/rtl/tscalart.c b/harbour/source/rtl/tscalart.c new file mode 100644 index 0000000000..cf98da683b --- /dev/null +++ b/harbour/source/rtl/tscalart.c @@ -0,0 +1,73 @@ +/* + * $Id$ + */ + +/* + * Harbour Project source code: + * Date scalar class function + * + * Copyright 2007 Przemyslaw Czerpak + * www - http://www.harbour-project.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software; see the file COPYING. If not, write to + * the Free Software Foundation, Inc., 59 Temple Place, Suite 330, + * Boston, MA 02111-1307 USA (or visit the web site http://www.gnu.org/). + * + * As a special exception, the Harbour Project gives permission for + * additional uses of the text contained in its release of Harbour. + * + * The exception is that, if you link the Harbour libraries with other + * files to produce an executable, this does not by itself cause the + * resulting executable to be covered by the GNU General Public License. + * Your use of that executable is in no way restricted on account of + * linking the Harbour library code into it. + * + * This exception does not however invalidate any other reasons why + * the executable file might be covered by the GNU General Public License. + * + * This exception applies only to the code released by the Harbour + * Project under the name Harbour. If you copy code from other + * Harbour Project or Free Software Foundation releases into a copy of + * Harbour, as the General Public License permits, the exception does + * not apply to the code that you add in this way. To avoid misleading + * anyone as to the status of such modified files, you must delete + * this exception notice from them. + * + * If you write modifications of your own for Harbour, it is your choice + * whether to permit this exception to apply to your modifications. + * If you do not wish that, delete this exception notice. + * + */ + +#include "hbapi.h" +#include "hbvm.h" + +HB_FUNC_EXTERN( __HBTIMESTAMP ); + +HB_FUNC( HBTIMESTAMP ) +{ + HB_FUNC_EXEC( __HBTIMESTAMP ); + + if( hb_vmRequestQuery() == 0 ) + { + PHB_ITEM pItem = hb_param( -1, HB_IT_ANY ); + + if( HB_IS_OBJECT( pItem ) ) + { + hb_vmPushDynSym( hb_dynsymGetCase( "NEW" ) ); + hb_vmPush( pItem ); + hb_vmSend( 0 ); + } + } +}