How to get Date and Time with oFTP

Postby Antonio Linares » Sat Nov 18, 2006 8:34 am

This is the implementation:
Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42077
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sat Nov 18, 2006 8:37 am

This is a sample of use (using your bytes):
Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42077
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby John » Sat Nov 18, 2006 8:47 am

Antonio,

looks great! How can i implement this?

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

Regards,

John.
John
 
Posts: 67
Joined: Mon Dec 26, 2005 7:44 am
Location: The Netherlands

Postby Antonio Linares » Sat Nov 18, 2006 8:51 am

To get the time a similar function is needed:
Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42077
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sat Nov 18, 2006 8:53 am

This is the final code for Class TFtp:
Code: Select all  Expand view
      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
User avatar
Antonio Linares
Site Admin
 
Posts: 42077
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby John » 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.
John
 
Posts: 67
Joined: Mon Dec 26, 2005 7:44 am
Location: The Netherlands

Postby Antonio Linares » 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
User avatar
Antonio Linares
Site Admin
 
Posts: 42077
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby Antonio Linares » Sat Nov 18, 2006 10:48 am

This is the right mask:

"%02i:%02i"
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42077
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby John » Sat Nov 18, 2006 1: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.
John
 
Posts: 67
Joined: Mon Dec 26, 2005 7:44 am
Location: The Netherlands

Postby Antonio Linares » Sat Nov 18, 2006 3:39 pm

John,

Try this one:
Code: Select all  Expand view
#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
User avatar
Antonio Linares
Site Admin
 
Posts: 42077
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Postby John » Sat Nov 18, 2006 4:48 pm

Hi Antonio,

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

Saludos,

John.
John
 
Posts: 67
Joined: Mon Dec 26, 2005 7:44 am
Location: The Netherlands

Postby Antonio Linares » Sun Nov 19, 2006 8:11 am

John,

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

yes :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Antonio Linares
Site Admin
 
Posts: 42077
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: nageswaragunupudi and 65 guests