Internet Date

Internet Date

Postby Jeff Barnes » Thu Nov 22, 2012 11:55 pm

Hi,

Is there a way to get the current date via FWH from the internet?
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Internet Date

Postby StefanHaupt » Fri Nov 23, 2012 7:54 am

Jeff,

here is what you need. (not tested yet)

tsntp.rar
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Internet Date

Postby Jeff Barnes » Sun Nov 25, 2012 11:43 pm

Thanks Stefan but I get this error:

Module: 'tsntp.prg' was compiled into PCODE version 7, this version of xHarbour expects version: 10
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Internet Date

Postby StefanHaupt » Mon Nov 26, 2012 8:28 am

Hmm, it´s an older lib, I have no sources, sorry.
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Internet Date

Postby StefanHaupt » Mon Nov 26, 2012 8:29 am

I found parts of the source here
http://www4.zzz.com.tw/phpbb2/viewtopic.php?t=29

But the function GetSntp() is missing, maybe you can contact the author
kind regards
Stefan
StefanHaupt
 
Posts: 824
Joined: Thu Oct 13, 2005 7:39 am
Location: Germany

Re: Internet Date

Postby Jeff Barnes » Mon Nov 26, 2012 7:23 pm

Thanks Stefan,

I was able to get it working by linking the .lib file then adding an INCLUDE "TSNTP.PRG"

Code: Select all  Expand view

Func    Test()
Local   aNet      := {},;
        nPort     := 123,;
        cIp       := "time.windows.com",;
        lSync     := .T.,;
        oSntp     := NIL;
        cNetDate
        oSntp := TSntp():New( cIP, nPort, lSync )

        If oSntp:GetData()
           // orignal code:   ? oSntp:Date(), "date"
           cNetDate := oSntp:Date()
        Else
           cNetDate := "99/99/99"
        EndIf

Return  cNetDate
 


Code: Select all  Expand view

// TSNTP.PRG
// Copyright by WenSheng come from TAIWAN
#include "hbclass.ch"
#include "common.ch"
CLASS   TSNTP

        DATA    cServer,;       // server name/ip
                nPort,;         // server port
                lSync,;         // Sync flag
                lError

        DATA    nYear,;
                nMonth,;
                nDay,;
                nWeek,;
                nDayOfYear

        DATA    nHours,;
                nMinute,;
                nSeconds

        METHOD  New(cServer, nPort, lSync)
        METHOD  GetData()
        MESSAGE DATE    METHOD  _Date()
        MESSAGE TIME    METHOD  _Time()

ENDCLASS

//
METHOD  New( cServer, nPort, lSync )    CLASS   TSNTP
DEFAULT cServer to "time.windows.com"   // 主機名稱
DEFAULT nPort   to 123                  // 主機 port
DEFAULT lSync   to .F.                  // 時間同步

        ::cServer   := cServer
        ::nPort     := nPort
        ::lSync     := lSync
        ::lError    := .F.

RETURN  Self

//
METHOD  GetData()   CLASS   TSNTP
Local   xRet    := GetSNTP( ::cServer, ::nPort, ::lSync )
        If ValType(xRet) == "N"
           ::lError   := .T.
           ::nYear    := 0
           ::nMonth   := 0
           ::nDay     := 0
           ::nHours   := 0
           ::nMinute  := 0
           ::nSeconds := 0
           ::nWeek    := 0
           ::nDayOfYear := 0
        Else
           ::lError := .F.
           //          0        1         2
           //          12345678901234567890
           // 取得資料 yyyymmddhhmmsswyda
           ::nYear    := Val( Substr( xRet,  1, 4 ))
           ::nMonth   := Val( Substr( xRet,  5, 2 ))
           ::nDay     := Val( Substr( xRet,  7, 2 ))
           ::nHours   := Val( Substr( xRet,  9, 2 ))
           ::nMinute  := Val( Substr( xRet, 11, 2 ))
           ::nSeconds := Val( Substr( xRet, 13, 2 ))
           ::nWeek    := Val( Substr( xRet, 15, 1 ))
           ::nDayOfYear := Val( Substr( xRet, 16, 3 ))
        EndIf

RETURN  ! ::lError

//
METHOD  _Date()     CLASS   TSNTP
RETURN  StoD( PadL( ::nYear, 4, "0" )+;
              PadL( ::nMonth, 2, "0" )+;
              PadL( ::nDay, 2, "0" ))

//
METHOD  _Time()     CLASS   TSNTP
RETURN  PadL( ::nHours, 2, "0" )+":"+;
        PadL( ::nMinute, 2, "0" )+":"+;
        PadL( ::nSeconds, 2, "0" )

 
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Internet Date

Postby Biel EA6DD » Tue Nov 27, 2012 3:06 pm

An alternative using JSON, http://json-time.appspot.com/
Code: Select all  Expand view

FUNCTION testTime()
   LOCAL oHttp, hTime,cTime
   oHttp:=CreateObject( "winhttp.winHttpRequest.5.1" )
   oHttp:Open("GET","http://json-time.appspot.com/time.json",.F.)
   oHttp:Send()
   oHttp:waitForResponse()
   IF oHttp:Status == 200
      hb_jsondecode(oHttp:ResponseText(),@hTime) //Parse JSON to hash
      cTime:=Str(hTime["hour"],2)+":"+Str(hTime["minute"],2)+":"+Str(hTime["second"],2)
      //--- just for test output data
      xBrowse(hTime) //All data in hash,
      MsgInfo(cTime+" GMT") //Time GMT
      MsgInfo(hTime["datetime"]) //Date time
      //--
   ENDIF
RETURN cTime
 
Saludos desde Mallorca
Biel Maimó
http://bielsys.blogspot.com/
User avatar
Biel EA6DD
 
Posts: 682
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca

Re: Internet Date

Postby albeiroval » Tue Nov 27, 2012 11:51 pm

Hi jeff,

where I get "tsntp.rar" or hb_fun_getsntp(...) function

thanks,

Albeiro,
Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
User avatar
albeiroval
 
Posts: 359
Joined: Tue Oct 16, 2007 5:51 pm
Location: Barquisimeto - Venezuela

Re: Internet Date

Postby Jeff Barnes » Wed Nov 28, 2012 12:09 am

Hi Alberio,

Stefan provided a link to tsntp.rar above but here it is again:


http://www.file-upload.net/download-6844934/tsntp.rar.html
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Internet Date

Postby albeiroval » Wed Nov 28, 2012 12:37 am

jeff,

I sent the link to babylon search, I do not want to install it, could you send me the zip file "tsntp.rar" to my mail "albeiroval@gmail.com" ..

thanks,

regards,

Albeiro,
Saludos,
Regards,

Albeiro Valencia
www.avcsistemas.com
User avatar
albeiroval
 
Posts: 359
Joined: Tue Oct 16, 2007 5:51 pm
Location: Barquisimeto - Venezuela

Re: Internet Date

Postby Jeff Barnes » Wed Nov 28, 2012 12:56 am

Hi Albeiro

Check your email :)
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: Internet Date

Postby Ugo » Sat Aug 10, 2013 11:09 pm

Hi all,

after download of sntp.lib and test it, i found that after, about 32 call date-time test, the result is only FAIL!

I have some question:

- There is a limit of use this lib? (max number calling in a exe session?)
- How to remove it?
- Is possible to obtain more time precision from internet sntp?
- Exist GetSntp source code, how find it?

Thank you for your reply.
Ciao, best regards,
Ugo
User avatar
Ugo
 
Posts: 283
Joined: Sat Oct 15, 2005 6:40 am
Location: Turin, Italy

Re: Internet Date

Postby ADutheil » Sat Aug 10, 2013 11:52 pm

I use this function to check date

Code: Select all  Expand view
FUNCTION Vencido
LOCAL nTime := fCreate( "chkdtime.bat" )
LOCAL cBuff := ""
LOCAL lRetu := .F.
LOCAL cDbar := "/" //
LOCAL aEOL := { Chr(13) + Chr(10), Chr(13), Chr(10) }
 
fWrite( nTime, "w32tm /stripchart /samples:1 /dataonly /computer:time.window.com >chkdtime.txt" )
fClose( nTime )
ShellExecute( 0, "open", "chkdtime.bat",,, )
WaitSeconds( 2 )
IF ( nTime := fOpen( "chkdtime.txt" ) ) > 0
    WHILE hb_fReadLine( nTime, @cBuff, aEOL  ) = 0
        IF cDbar $ cBuff
            cBuff := subStr( cBuff, at( cDbar, cBuff ) - 2 )
            IF cToD( subStr( cBuff, 1, at( " ", cBuff ) - 1 ) ) > cToD( "01/01/14" )
                msgStop( "O PERÍODO DE AVALIAÇÃO TERMINOU" + CRLF + "SOLICITE UMA VERSÃO ATUALIZADA AO DESENVOLVEDOR", "Atenção" )
                lRetu := .T.
            ENDIF
            EXIT
        ENDIF
    ENDDO
    fClose( nTime )
ENDIF
fErase( "chkdtime.bat" )
fErase( "chkdtime.txt" )
RETURN ( lRetu )
Regards,

André Dutheil
FWH 13.04 + HB 3.2 + MSVS 10
ADutheil
 
Posts: 368
Joined: Sun May 31, 2009 6:25 pm
Location: Salvador - Bahia - Brazil

Re: Internet Date

Postby Ugo » Sun Aug 11, 2013 10:24 am

Hi Andrè
ADutheil wrote:I use this function to check date ...

Thank you, but my necessity is to have in return the exact TIME more exactly possible.

From my search, the ntp protocol can return exactly also 1/1000 sec!

The function "getsntp" is a good solution, is quick and use the standard protocol ntp.

The question is: where find it?

Can you help me?

Thank in advance.
Ciao, best regards,
Ugo
User avatar
Ugo
 
Posts: 283
Joined: Sat Oct 15, 2005 6:40 am
Location: Turin, Italy

Re: Internet Date

Postby James Bott » Sun Aug 11, 2013 2:23 pm

Ugo,

There are two links to the source code further up in this message thread.

James
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Antonio Linares and 11 guests