SetFTime() conversion error

Post Reply
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

SetFTime() conversion error

Post by Badara Thiam »

Hello,

I am testing a xHarbour with FWH 8.6 application.
SetFTime() have a problem to return the time required :

*******************************************************
CLIPPER :

With Fivewin for Clipper , it make the time, but the seconds passed
to SetFTime() are not the seconds given to SetFTime() :

SetFTime( nIdent, "10:10:10", Date()) gives seconds * 2

file time is then "10:10:20".
*******************************************************
xHARBOUR :

With Fivewin for xHarbour , the hours and the seconds passed
to SetFTime() are not these given to SetFTime() :

SetFTime( nIdent, "10:10:10", Date()) gives hours + 2 and seconds - 2

file time is then "12:10:08".
*******************************************************
Tested with date franch format (DD/MM/YYYY)

Regards,
Badara Thiam
http://www.icim.fr
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Post by Antonio Linares »

Badara,

The C conversion funtions that we use seem to be ok, so the error has to be in the Windows API (?)

test.prg

Code: Select all

#include "FiveWin.ch"

function Main()

   local aTime := Test( "10:11:12" )

   MsgInfo( aTime[ 1 ] )
   MsgInfo( aTime[ 2 ] )
   MsgInfo( aTime[ 3 ] )

return nil

#pragma BEGINDUMP

#include <hbapi.h>

static unsigned int CharsToWord( char * pChars )
{
   unsigned int w = 0;

   if( pChars[ 0 ] != '0' )
      w = ( pChars[ 0 ] - '0' ) * 10;

   if( pChars[ 1 ] != '0' )
      w += ( pChars[ 1 ] - '0' );

   return w;
}

HB_FUNC( TEST )
{
   char * pTime = hb_parc( 1 );
   
   hb_reta( 3 );

   hb_stornl( CharsToWord( pTime ),     -1, 1 );
   hb_stornl( CharsToWord( pTime + 3 ), -1, 2 );
   hb_stornl( CharsToWord( pTime + 6 ), -1, 3 );
}   

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Post by Badara Thiam »

Antonio,

After others tests i see that the seconds
in leee, with xHarbour, is not the fact of
SetFTime() but of Directory().
The hours in more is the fact of SetFTime().

Test please with hour between 0 and 1:59
like this :

- SetFTime(nIdent, "01:00:00", Date())
or
- Hour between 22:01 and 23:59
for the file time before use SetFTime()


I will test today on other PC on XP.
Yesterday it was on Vista Homel Premium.

Regards,
Badara Thiam
http://www.icim.fr
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Post by Badara Thiam »

Antonio,

The function SetFTime() have a vicious error !!!

She write the Date/time of GMT time, not local date/time
passed in parameters.

The difference is not 2 hours now, but 1 hour,
since the french time is in Winter time...

Regards.
Badara Thiam
http://www.icim.fr
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Re: SetFTime() conversion error

Post by Badara Thiam »

Hello,

There is always a problem with SETFTIME() and SETFDATI() for [x]Harbour.
The date and time writted are not local date and time but GMT time.
In France there is different time in summer than in Winter.
This bug is a big problem for network. It is not possible to forget it...

Has someone solved this ?

Best regards.
Badara Thiam
http://www.icim.fr
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Re: SetFTime() conversion error

Post by Badara Thiam »

I think i have found the problem, it was in my code.
I used DTOS() to pass the date parameter to SetFTime()
and you know the result...

Sorry, forget my last post please.

Best Regards.
Badara Thiam
http://www.icim.fr
Davide
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: SetFTime() conversion error

Post by Davide »

Dear Badara,
Badara Thiam wrote:I think i have found the problem, it was in my code.
I used DTOS() to pass the date parameter to SetFTime()
I too have have the problem that the Time is GMT, so it's different when you look at the file with DIRECTORY (or just with a DIR from the Command Prompt)

Could you please explain me how you did solve it ?

Thanks,
Davide
User avatar
Badara Thiam
Posts: 160
Joined: Tue Oct 18, 2005 10:21 am
Location: France
Contact:

Re: SetFTime() conversion error

Post by Badara Thiam »

Hello

See below the actual state of my function SETFDATI(). You can see here where was the problem.
I don't give functions used in SETFDATI() like HEURES() who give the space time between two times in "C" type,
and HEURESADD() who add hours, minutes and seconds in "C" type also.

Regards

Code: Select all


*****************
FUNCTION SETFDATI(CFIC, QDATE, QHEURE)
*****************
* Enregistrement de la date et l'heure d'un fichier quelconque

LOCAL nDatePlus := 0
LOCAL cHeureDiff := "00:00:00"

LOCAL nATTRIB
LOCAL nIDENT
LOCAL nHeures
LOCAL nMinutes
LOCAL nSecondes
LOCAL dFDate := FILEDATE( CFIC )
LOCAL hFHeure := FILETIME( CFIC )
LOCAL HeureCalc

IF dFDate = QDATE .AND. hFHeure = QHEURE
  * Ok : rien à faire
  RETURN NIL
ENDIF

nATTRIB := FILEATTR( CFIC )
IF nATTRIB > 0
  SETFATTR(CFIC, 0)
ENDIF
nIDENT := FOPEN( CFIC, 18 )
IF nIDENT >= 0
  IF ISCLIPPER()

    SetFTime( nIDENT, LEFT(QHEURE,6) + PADL( INT( VAL( SUBSTR(QHEURE,7,2) ) / 2), 2, "0") , ;
    QDATE )

    FCLOSE( nIDENT )

  ELSE

    SetFTime( nIDENT, QHEURE, QDATE )

    dFDate := FILEDATE( CFIC )
    hFHeure := FILETIME( CFIC )

    FCLOSE( nIDENT )

    IF dFDate != QDATE .OR. hFHeure != QHEURE
    /* Si SetFTime() n'a pas affecté les bonnes date et heure au fichier (décalage temps GMT avec FWH86 ! ) */

      IF dFDate > QDATE
        nDatePlus := 1
      ELSEIF dFDate < QDATE
        nDatePlus := -1
      ELSE
        nDatePlus := 0
      ENDIF

      IF nDatePlus > 0
      * Si la date du fichier est supérieure à celle voulue !
        cHeureDiff := "-" + HEURES(QHEURE, hFHeure)
      ELSEIF nDatePlus < 0
        cHeureDiff := HEURES(hFHeure, QHEURE)
      ELSEIF QHEURE < hFHeure
        cHeureDiff := "-" + HEURES(QHEURE, hFHeure)
      ELSEIF QHEURE > hFHeure
        cHeureDiff := HEURES(hFHeure, QHEURE)
      ELSE
        cHeureDiff := "00:00:00"
      ENDIF

      nIDENT := FOPEN( CFIC, 18 )
      IF nIDENT >= 0

        HeureCalc := SETFDATIH(QHEURE, cHeureDiff, @QDATE)

        SetFTime( nIDENT, HeureCalc, DTOS( QDATE ) )
        FCLOSE( nIDENT )

      ENDIF
    ENDIF

  ENDIF

ENDIF
IF nATTRIB > 0
  SETFATTR(CFIC, nATTRIB)
ENDIF
RETURN NIL

 

Code: Select all

******************
FUNCTION SETFDATIH(QHEURE, cHeureDiff, QDATE)
******************
LOCAL cHeureNouv := LTRIM( HEURESADD( QHEURE, cHeureDiff ) )
IF LEFT(cHeureNouv,1) = "-"
  cHeureNouv := LTRIM( HEURESADD( "24:00:00", cHeureNouv ) )
  QDATE := QDATE - 1
ELSEIF VAL( LEFT(cHeureNouv, AT(":", cHeureNouv) -1 ) ) >= 24
  cHeureNouv := LTRIM( HEURESADD( "-24:00:00", cHeureNouv ) )
  QDATE := QDATE + 1
ENDIF
cHeureNouv := PADL(cHeureNouv, 8, "0")
RETURN cHeureNouv


 
Badara Thiam
http://www.icim.fr
Davide
Posts: 190
Joined: Tue Mar 14, 2006 1:59 am
Location: Italy

Re: SetFTime() conversion error

Post by Davide »

Dear Badara,
Badara Thiam wrote:See below the actual state of my function SETFDATI(). You can see here where was the problem.
thank you.
I finally found out that GetFTime() retrieves the same date/time of SetFTime(), so I solved my problem that way.
To retrieve the difference in hours (GMT+/-) you can just compare the result of Directory() with GetFTime()

Thanks again,
Davide
Post Reply