On Mon, 19 Oct 2009, Francesco Saverio Giudice wrote:
Hi,
> Infact is not for core code, but for functions that have "old"
> parameters separated like MyFunc( dDate, cTime ) and in case of
> explicit check of date and time like:
> ? "cTime = ", cTime := Time()
> ? "dDate = ", dDate := Date()
> ? "tTimeStamp = ", tTimeStamp := hb_DateTime()
> ? dDate == tTimeStamp // it returns .F.
'dDate = tTimeStamp' returns .T. if date part is the same.
> ? cTime == tTimeStamp // this gives "Error BASE/1070 Argument
> error: =="
TIME() function returns time with second precision formatted to "hh:mm:ss".
tTimeStamp value contains time in millisecond precision which can be
formatted into different forms depending on user local setting, i.e.
to 12 or 24 hour format wit or without seconds or milliseconds.
In Clipper code people use different representations for time.
As I can see you were using "hh:mm:ss". Usually I was using
numeric value in format like <nSec>[.<nSecPart>]. It's value returns
by seconds() and if necessary I was converting it to "hh:mm:ss.mmm"
I do not see any reason why we should prefer "hh:mm:ss" which strips
information about milliseconds instead of using "hh:mm:ss.mmm" and
in general I do not see any reason why we should force our local
preferences in core code ;)
> >>HB_TTOT( tTimeStamp ) -> cTime
> >>HB_TTOC( tTimeStamp, "", "HH:MM:SS" ) -> cTime
> I have not request formatting functions, simply functions that
> extract date and time parts from a timestamp value.
But the function you presented do not extract the time part of
timestamp value (HB_NTOT( HB_TTON( tTimeStamp ) % 1 ) returns
time part) but only returns the time cut to second precision
formatted as "hh:mm:ss" string.
Because in most of cases I was using numeric value returned by
second for time then for me such function should work like:
( HB_TTON( tTimeStamp ) % 1 )
> But I can do the same using #xtranslate command or adding function
> at prg level. My request is only to have a core function if this is
> faster than using prg functions.
Pleas note that you requested about sth what depends on local preferences
rather then universal functionality. You want to extract time from
timestamp value as string in format "hh:mm:ss". I would preffer numeric
value comparable to second() results. Someone else may preffer string
in format "hh:mm:ss.fff" and someone else in format like "hh:mm:ss.ff"
(it's compatible with TIMETOSC()/SECTOTIME() CT3 functions)
HB_TTOD() job is simple and I'll add it but the second function seems
that should be implemented locally by user because it have to be tuned
to local preferences encoded in existing Clipper code.
It's rather very simple job using existinf timestamp functions so it
should not be a problem.
We can only add function which will divide timestamp value into date
and numeric value with seconds in a day (just like the value returned by
second()) because unlike string representations we have only one format
here:
/* HB_TSDECODE( tTimeStamp, [ @<dDate> ], [ @<nSeconds> ] ) */
HB_FUNC( HB_TSDECODE )
{
long lDate, lTime;
if( hb_partdt( &lDate, &lTime, 1 ) )
{
hb_stordl( lDate, 2 );
hb_stornd( ( double ) lTime / 1000, 3 );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME,
HB_ERR_ARGS_BASEPARAMS );
}
But for converstion to string we should intorduce additional parameter
with time value format, i.e.:
/* HB_TSDECODE( tTimeStamp, [ @<dDate> ], [ @<seconds> ] [, <cTimeFormat>] )
*/
HB_FUNC( HB_TSDECODE )
{
long lDate, lTime;
if( hb_partdt( &lDate, &lTime, 1 ) )
{
const char * szFormat = hb_parc( 4 );
hb_stordl( lDate, 2 );
if( szFormat )
{
char szBuffer[ 27 ];
if( *szFormat = '\0' )
szFormat = hb_setGetTimeFormat();
hb_storc( hb_timeStampFormat( szBuffer, "", szFormat,
lDate, lTime ), 3 );
}
else
hb_stornd( ( double ) lTime / 1000, 3 );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME,
HB_ERR_ARGS_BASEPARAMS );
}
or maybe better add new function (please think about the name) which will
work like:
HB_FUNC( ... )
{
long lDate, lTime;
if( hb_partdt( &lDate, &lTime, 1 ) )
{
const char * szFormat = hb_parc( 4 );
char szBuffer[ 27 ];
if( !szFormat )
szFormat = hb_setGetTimeFormat();
hb_stordl( lDate, 2 );
hb_storc( hb_timeStampFormat( szBuffer, "", szFormat,
lDate, lTime ), 3 );
}
else
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME,
HB_ERR_ARGS_BASEPARAMS );
}
And probably we should also add corresponding function for reverted
conversion:
HB_TSENCODE( <dDate>, <nTime> | <cTime> ) -> <tTimeStamp>
Here we can try to decode <cTime> without any additional format parameters.
best regards,
Przemek
BTW:
HB_FUNC( HB_TTOD )
{
long lDate, lTime;
if( hb_partdt( &lDate, &lTime, 1 ) )
hb_retdl( lDate );
else
hb_errRT_BASE_SubstR( EG_ARG, 3012, NULL, HB_ERR_FUNCNAME,
HB_ERR_ARGS_BASEPARAMS );
}
_______________________________________________
Harbour mailing list
[email protected]
http://lists.harbour-project.org/mailman/listinfo/harbour