FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Funci贸n c gmtime(), obtener fecha y hora GMT
Posts: 35
Joined: Mon Jan 15, 2007 10:46 AM
Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Thu Sep 03, 2009 05:36 PM
Buenas tardes,

Necesito averiguar el tiempo GMT para un tema de cookies de un programa cgi,
investigando un poco he dado con la funci贸n ansi c gmtime(),
he hecho un programita de pruebas...
Code (fw): Select all Collapse
function main()
? migmttime()
return nil
聽
#pragma BEGINDUMP
#include "hbapi.h"
#include "time.h"
HB_FUNC ( MIGMTTIME )
{
time_t t;
struct tm *ptm;
time(&t);
ptm=gmtime(&t);
hb_retni ( ptm->tm_hour );
}
#pragma ENDDUMP


El cual funciona (devuelve la hora GMT) pero termina con una excepci贸n:

Unrecoverable error 6005: Exception error:

Exception Code:C0000005
Exception Address:00479E06
EAX:003A0B04 EBX:003A49F0 ECX:003A0B00 EDX:003A0B00
ESI:00491CEC EDI:004850D2 EBP:0012FF0C
CS:EIP:00479E06 SS:ESP:0012FF08
DS:0023 ES:0023 FS:003B GS:0000
Flags:00010206
CS:EIP: 83 4C 10 04 02 8B 08 83 E1 FC 3B 0D AC D6 48 00
SS:ESP: 009820A0 0012FF18 00479D70 003A49F0 0012FF24 00479671 003A49F0 0012F
F5C 00481B3E 003A49F0 00000002 004850FC 00481657 00000000 0048513C 00000000

C stack:
EIP: EBP: Frame: OldEBP, RetAddr, Params...
00479E06 0012FF0C 0012FF18 00479D70 003A49F0
00479D70 0012FF18 0012FF24 00479671 003A49F0
00479671 0012FF24 0012FF5C 00481B3E 003A49F0 00000002 004850FC 00481657 00
000000 0048513C 00000000 00491CE4
00481B3E 0012FF5C 0012FF80 004816A6 00491CE0 00000001 00000000 0048513C 00
000000 00480910 7FFDF000
004816A6 0012FF80 0012FF94 00480968 00000000 00000000 00000000
00480968 0012FF94 0012FFB8 0048189F 00000000 0000001A 00000000 7FFDF000 7F
FDF000 0012FFE0 0047B1FC
0048189F 0012FFB8 0012FFF0 00000000 0048513C 7C817077 0000001A 00000000 7F
FDF000 00000000 0012FFC8 894C5370


Modules:
0x00400000 0x0009F000 G:\pry0034\PRG\zpruebas2.exe
0x7C910000 0x000B8000 C:\WINDOWS\system32\ntdll.dll
0x7C800000 0x00103000 C:\WINDOWS\system32\kernel32.dll
0x7E390000 0x00091000 C:\WINDOWS\system32\USER32.DLL
0x77EF0000 0x00049000 C:\WINDOWS\system32\GDI32.dll
0x76340000 0x0001D000 C:\WINDOWS\system32\IMM32.DLL
0x77DA0000 0x000AC000 C:\WINDOWS\system32\ADVAPI32.dll
0x77E50000 0x00092000 C:\WINDOWS\system32\RPCRT4.dll
0x77FC0000 0x00011000 C:\WINDOWS\system32\Secur32.dll

驴Alguna idea?
Gracias y saludos.
David Monta帽o
Posts: 35
Joined: Mon Jan 15, 2007 10:46 AM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Thu Sep 03, 2009 06:03 PM
Parece que es un problema de acceso a memoria

el siguiente codigo me funciona
Code (fw): Select all Collapse
function main()
local i,atime:=migmttime()
for i:=1 to len(aTime)
聽 聽 ? aTime[i]
next
RETU

#pragma BEGINDUMP
#include "hbapi.h"
#include "hbapiitm.h"
#include "time.h"
HB_FUNC ( MIGMTTIME )
{
PHB_ITEM pArray=hb_itemArrayNew( 5 );
PHB_ITEM pItem;
long t;
struct tm *ptm;
time(&t);
ptm=gmtime(&t);
pItem = hb_itemPutNI( NULL, ptm->tm_mday );
聽 聽 聽 hb_itemArrayPut( pArray, 1, pItem );
聽 聽 聽 hb_itemRelease( pItem );
pItem = hb_itemPutNI( NULL, ptm->tm_mon+1 );
聽 聽 聽 hb_itemArrayPut( pArray, 2, pItem );
聽 聽 聽 hb_itemRelease( pItem );
pItem = hb_itemPutNI( NULL, ptm->tm_year+1900 );
聽 聽 聽 hb_itemArrayPut( pArray, 3, pItem );
聽 聽 聽 hb_itemRelease( pItem );
pItem = hb_itemPutNI( NULL, ptm->tm_hour );
聽 聽 聽 hb_itemArrayPut( pArray, 4, pItem );
聽 聽 聽 hb_itemRelease( pItem );
pItem = hb_itemPutNI( NULL, ptm->tm_min );
聽 聽 聽 hb_itemArrayPut( pArray, 5, pItem );
聽 聽 聽 hb_itemRelease( pItem );
hb_itemReturn( pArray );
}
#pragma ENDDUMP


Pero si intento devolver el 6 elemento da el mismo fallo que al principio.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Thu Sep 03, 2009 06:15 PM

David,

Aqui tu ejemplo funciona correctamente (el primer codigo que has puesto)

Estas usando BCC55 ?

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Thu Sep 03, 2009 06:23 PM
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 35
Joined: Mon Jan 15, 2007 10:46 AM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Thu Sep 03, 2009 06:28 PM

Si bcc 5.5.1
Harbour 2.0.0beta2 (Rev. 12195)

驴?

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Thu Sep 03, 2009 08:31 PM

Aqui funciona bien tanto con Harbour como con xHarbour

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 682
Joined: Tue Feb 14, 2006 09:48 AM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Fri Sep 04, 2009 07:05 AM
Si te sirve de algo, estas son las funciones que utilizo para recuperar la GMT
Code (fw): Select all Collapse
//--------------
FUNCTION Gmt()
   LOCAL cGmt:=Time()
   cGmt:=Str(Val(SubStr(cGmt,1,2))+TimeZone(),2)+SubStr(cGmt,3)
RETURN cGmt
//------------------
FUNCTION TimeZone()
   Local oReg, nRetVal
   oReg := TReg32():New(HKEY_LOCAL_MACHINE, "SYSTEM\CurrentControlSet\Control\TimeZoneInformation", .f. )
   nRetVal := oReg:Get( "ActiveTimeBias", 0 )
   oReg:Close()
   nRetVal := Round( nRetVal / 60, 0 )
Return nRetVal
Saludos desde Mallorca
Biel Maim贸
http://bielsys.blogspot.com/
Posts: 35
Joined: Mon Jan 15, 2007 10:46 AM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Fri Sep 04, 2009 08:13 AM

Gracias

:D

Posts: 35
Joined: Mon Jan 15, 2007 10:46 AM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Fri Sep 04, 2009 12:37 PM
Encabezonado un poco he probado que el siguiente c贸digo si me funciona...

Code (fw): Select all Collapse
function main()
? migmttime(3600)
RETU

#pragma BEGINDUMP
#include "hbapi.h"
#include "hbapiitm.h"
#include "time.h"
HB_FUNC ( MIGMTTIME )
{
long t;
char *wdays[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
char cRet[29];
struct tm *ptm;
//------------------------
hb_itemNew(NULL);
//------------------------
time(&t);
t+=hb_parnl(1);
ptm=gmtime(&t);
sprintf(cRet, "%s, %d-%d-%d %d:%d:%d GMT", wdays[ptm->tm_wday],ptm->tm_mday,ptm->tm_mon+1,ptm->tm_year+1900,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
hb_retc (cRet);
};
#pragma ENDDUMP


Si comento hb_itemNew(NULL); me produce error 驴que hace hb_itemnew?
no he probado a煤n con harbour 1.0

Saludos y buen fin de semana.
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Fri Sep 04, 2009 12:56 PM

Prueba a ponerle #include "FiveWin.ch" al comienzo

Aqui funciona bien, sin el hb_itemNew(), tanto en Harbour como xHarbour

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 35
Joined: Mon Jan 15, 2007 10:46 AM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Fri Sep 04, 2009 05:07 PM

Efectivamente Antonio he probado con Harbour 1.0.1 y funciona OK

Gracias-

Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Fri Sep 04, 2009 07:26 PM

David,

Aqui estamos usando Harbour 2.0 beta 2:

www.fivetechsoft.com/files/harbour.exe

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 35
Joined: Mon Jan 15, 2007 10:46 AM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Fri Sep 04, 2009 10:54 PM
Bueno dejo el c贸digo aqu铆 por si le puede servir a alguien,
quedaba el correcto formateo de la cadena

Saludos
David Monta帽o,

Code (fw): Select all Collapse
#pragma BEGINDUMP
#include "hbapi.h"
#include "time.h"
HB_FUNC ( MGMTIME )
{
long t;
char *wdays[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
char cRet[29];
struct tm *ptm;
time(&t);
t+=hb_parnl(1);
ptm=gmtime(&t);
sprintf(cRet, "%s, %02d-%02d-%04d %02d:%02d:%02d GMT", wdays[ptm->tm_wday],ptm->tm_mday,ptm->tm_mon+1,ptm->tm_year+1900,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
hb_retc (cRet);
};
#pragma ENDDUMP
Posts: 44158
Joined: Thu Oct 06, 2005 05:47 PM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Sat Sep 05, 2009 08:04 AM

David,

gracias! :-)

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 35
Joined: Mon Jan 15, 2007 10:46 AM
Re: Funci贸n c gmtime(), obtener fecha y hora GMT
Posted: Mon Sep 07, 2009 10:14 AM
Upps, el m茅s hay que mostrarlo como abreviatura :-)

Code (fw): Select all Collapse
#pragma BEGINDUMP
#include "hbapi.h"
#include "time.h"
HB_FUNC ( MGMTIME )
{
long t;
char *wdays[7] = {"Sun","Mon","Tue","Wed","Thu","Fri","Sat"};
char *amonths[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"};
char cRet[30];
struct tm *ptm;
time(&t);
t+=hb_parnl(1);
ptm=gmtime(&t);
sprintf(cRet, "%s, %02d-%s-%04d %02d:%02d:%02d GMT",wdays[ptm->tm_wday],ptm->tm_mday,amonths[ptm->tm_mon],ptm->tm_year+1900,ptm->tm_hour,ptm->tm_min,ptm->tm_sec);
hb_retc (cRet);
};
#pragma ENDDUMP