Code: Select all
// \samples\DANIEL.PRG
#include "FiveWin.ch"
REQUEST HB_LANG_PT
REQUEST HB_CODEPAGE_PT850
STATIC oWnd
//----------------------------------------------------------------//
FUNCTION Main()
LOCAL oBar
SET DATE BRITISH
SET EPOCH TO 1950
SET CENTURY ON
SET SOFTSEEK OFF
SET WRAP ON
SETCANCEL( .F. )
SET CONFIRM OFF
SET DELETED ON
SET ESCAPE OFF
SET EXACT ON // CONTROLA O :=, = e ==
SET EXCLUSIVE OFF
SET MULTIPLE OFF
HB_LANGSELECT( 'PT' ) // Default language is now Portuguese
HB_SETCODEPAGE( "PT850" )
SkinButtons()
DEFINE WINDOW oWnd TITLE "Atualiza Hora"
DEFINE BUTTONBAR oBar _3D OF oWnd
DEFINE BUTTON OF oBar ACTION atualiza_hora()
SET MESSAGE OF oWnd TO "Atualiza Hora" NOINSET CLOCK DATE KEYBOARD
ACTIVATE WINDOW oWnd
RETURN nil
// -------------------------------------------------------------------------- //
// IDENTADO COM: HBFORMAT.EXE C:\XHARBOUR\BIN
// -------------------------------------------------------------------------- //
FUNCTION atualiza_hora()
LOCAL xdia_atu , xhora_atu
try
oHttp := CreateObject( "winhttp.winhttprequest.5.1" )
oHttp:SetTimeouts(40000,40000,40000,40000) // VERIFICAR SE FICA LENTO
oHttp:Open( "GET", "http://24timezones.com/pt_horamundial/brasilia_hora_local.php" , .F. )
oHttp:Send()
cHtml := oHttp:ResponseText()
catch
RETURN .T.
end
cHora := alltrim( StrExtract( cHtml, '<span id="currentTime">', '</span>' ) )
cHora1 := TRANSF( cHora, "99:99:99" )
x_am_pm := alltrim( substr( cHora , 10 , 2 ) )
ntamtot := len( cHora )
nposmesi := rat( ',' , cHora ) + 1
nposmesf := ( ntamtot - nposmesi ) - 4
nposanoi := ntamtot - 3
nposdiaf := rat( ',' , cHora ) - 1
nposdiai := nposdiaf - 1
nposdiaf := nposdiaf - nposdiai
dia := alltrim( substr( cHora , nposdiai , 2 ) )
mes := alltrim( substr( cHora , nposmesi , nposmesf ) )
ano := alltrim( substr( cHora , nposanoi , 4 ) )
IF x_am_pm = 'PM' .AND. ( val( substr( cHora1 , 1 , 2 ) ) < 12 )
xhora1 := zeracod( str( val(substr( cHora1 , 1 , 2 ) ) + 12 ,2 ) )
cHora1 := xhora1 + substr( cHora1 , 3 )
ENDIF
data_atual_site := dia + '/' + qmesnum( mes ) + '/' + ano
/*
? 'cHora' , cHora ,;
'cHora1' , cHora1 ,;
'Dia' , dia ,;
'Mes' , mes ,;
'Ano' , ano ,;
'x_am_pm' , x_am_pm,;
'data_atual_site' , data_atual_site,;
'DataAtual' , date(),;
'HoraAtual' , time()
*/
xdia_atu := date()
xhora_atu := time()
IF data_atual_site # dtoc( xdia_atu )
//xdate := "Date " + data_atual_site
//try
// winexec( xdate )
//catch
//end
msginfo( "Favor corrigir a data do seu Equipamento." + CRLF + CRLF + ;
"Data na Internet: " + data_atual_site + CRLF + ;
"Data do Equipamento: " + dtoc( xdia_atu ) , "CIACPD Informa." )
ENDIF
IF substr( cHora1 , 1 , 4 ) # substr( xhora_atu , 1 , 4 )
//try
// winexec( cHora1 )
//catch
//end
msginfo( "Favor corrigir a hora do seu Equipamento." + CRLF + CRLF + ;
"Hora na Internet: " + cHora1 + CRLF + ;
"Hora do Equipamento: " + xhora_atu , "CIACPD Informa." )
ENDIF
? cHora1, data_atual_site
RETURN NIL
// -------------------------------------------------------------------------- //
FUNCTION StrExtract( cText, cAfter, cBefore )
LOCAL cRet := SUBSTR( cText, AT( cAfter,cText ) + LEN( cAfter ) )
LOCAL n
IF ( n := AT( cBefore,cRet ) ) > 0
cRet := LEFT( cRet, n - 1 )
ENDIF */
RETURN ( cRet )
// -------------------------------------------------------------------------- //
FUNCTION ZeraCod( Cod )
RETURN Padl( AllTrim( Cod ), Len( cod ), [0] )
//----------------------------------------------------------------------------//
FUNCTION qmesnum( pmes )
LOCAL nmesnum
IF len( alltrim( pmes ) ) < 1
pmes := 'Janeiro'
ENDIF
PRIVATE Tmes := { "JANEIRO", "FEVEREIRO", "MARÇO", "ABRIL", "MAIO", "JUNHO", "JULHO", "AGOSTO", "SETEMBRO", "OUTUBRO", "NOVEMBRO", "DEZEMBRO" }
nmesnum := ascan( tmes, Alltrim( upper(pmes ) ) )
RETURN zeracod( str( nmesnum,2 ) )
//----------------------------------------------------------------------------//