FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour How to get Date and Time with oFTP
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 08:34 AM
This is the implementation:
#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( FILETIMETODATE ) // cFileTime --> dDate
{
   SYSTEMTIME st;
   
   FileTimeToSystemTime( ( FILETIME * ) hb_parc( 1 ), &st );
   
   hb_retd( st.wYear, st.wMonth, st.wDay );
}    	

#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 08:37 AM
This is a sample of use (using your bytes):
function Main()

   MsgInfo( FileTimeToDate( Chr( 0 ) + Chr( 46 ) + Chr( 46 ) + Chr( 201 ) + ;
                            Chr( 78 ) + Chr( 240 ) + Chr( 198 ) + Chr( 1 ) ) )
   
return nil

The shown date is 10/15/06 which it is correct :-)

We are going to modify Class TFtp to automatically use this function.
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 67
Joined: Mon Dec 26, 2005 07:44 AM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 08:47 AM

Antonio,

looks great! How can i implement this?

Or shall i wait for your modifications and test them here?

Regards,

John.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 08:51 AM
To get the time a similar function is needed:
#pragma BEGINDUMP

#include <hbapi.h>
#include <windows.h>

HB_FUNC( FILETIMETOTIME )
{
   SYSTEMTIME st;
   char * buffer[ 5 ];
   
   FileTimeToSystemTime( ( FILETIME * ) hb_parc( 1 ), &st );

   wsprintf( buffer, "%i:%i", st.wHour, st.wMinute );
   
   hb_retclen( buffer, 5 );
}    	
#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 08:53 AM
This is the final code for Class TFtp:
      if ! Empty( oWin32FindData:cFileName )
         AAdd( aFiles, { oWin32FindData:cFileName,;
                         oWin32FindData:nSizeLow,;
                         FileTimeToDate( oWin32FindData:nLastWriteAccess ),;
                         FileTimeToTime( oWin32FindData:nLastWriteAccess ) } )
         while InternetFindNextFile( hFTPDir, @cBuffer )
            oWin32FindData:cBuffer = cBuffer
            AAdd( aFiles, { oWin32FindData:cFileName,;
                            oWin32FindData:nSizeLow,;
                            FileTimeToDate( oWin32FindData:nLastWriteAccess ),;
                            FileTimeToTime( oWin32FindData:nLastWriteAccess ) } )
         end
      endif
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 67
Joined: Mon Dec 26, 2005 07:44 AM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 10:10 AM

Antonio,

when adding the two implementations and the code i get this compiling message:

Warning W8075 TFTP.PRG 151: Suspicious pointer conversion in function HB_FUN_FIL ETIMETOTIME
Warning W8075 TFTP.PRG 153: Suspicious pointer conversion in function HB_FUN_FIL ETIMETOTIME

it refers to this:
wsprintf( buffer, "%i:%i", st.wHour, st.wMinute );

hb_retclen( buffer, 5 );

The date is returned fine, the time returns 3:8 instead of 3:08

Regards,

John.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 10:45 AM

John,

This is wrong:
char * buffer[ 5 ];

It should be:
char buffer[ 5 ];

Also, we need to change "%i:%i" in order to get two digits format for each value. We are searching for the right format.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 10:48 AM

This is the right mask:

"%02i:%02i"

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 67
Joined: Mon Dec 26, 2005 07:44 AM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 01:39 PM

Antonio,

That solved the problem!

I've tested the results but the time 14:58 gets interpreted as 08:58. Also the seconds seem to be missing?

Best regards,

John.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 03:39 PM
John,

Try this one:
#pragma BEGINDUMP 

#include <hbapi.h> 
#include <windows.h> 

HB_FUNC( FILETIMETOTIME ) 
{ 
   SYSTEMTIME st;
   char buffer[ 9 ];
   
   FileTimeToSystemTime( ( FILETIME * ) hb_parc( 1 ), &st );

   wsprintf( buffer, "%02i:%02i:%02i", st.wHour, st.wMinute, st.wSecond );
   
   hb_retclen( buffer, 8 );
}        
#pragma ENDDUMP
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 67
Joined: Mon Dec 26, 2005 07:44 AM
How to get Date and Time with oFTP
Posted: Sat Nov 18, 2006 04:48 PM

Hi Antonio,

everything seems to work fine now, thanks! Will this be implemented in one of the next releases?

Saludos,

John.

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
How to get Date and Time with oFTP
Posted: Sun Nov 19, 2006 08:11 AM

John,

> Will this be implemented in one of the next releases?

yes :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com

Continue the discussion