Función c gmtime(), obtener fecha y hora GMT

Función c gmtime(), obtener fecha y hora GMT

Postby damosi » Thu Sep 03, 2009 5: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: Select all  Expand view

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:001B:00479E06 SS:ESP:0023: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
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Re: Función c gmtime(), obtener fecha y hora GMT

Postby damosi » Thu Sep 03, 2009 6:03 pm

Parece que es un problema de acceso a memoria

el siguiente codigo me funciona
Code: Select all  Expand view

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.
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Re: Función c gmtime(), obtener fecha y hora GMT

Postby Antonio Linares » Thu Sep 03, 2009 6:15 pm

David,

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

Estas usando BCC55 ?
regards, saludos

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

Re: Función c gmtime(), obtener fecha y hora GMT

Postby Antonio Linares » Thu Sep 03, 2009 6:23 pm

Image
regards, saludos

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

Re: Función c gmtime(), obtener fecha y hora GMT

Postby damosi » Thu Sep 03, 2009 6:28 pm

Si bcc 5.5.1
Harbour 2.0.0beta2 (Rev. 12195)

¿?
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Re: Función c gmtime(), obtener fecha y hora GMT

Postby Antonio Linares » Thu Sep 03, 2009 8:31 pm

Aqui funciona bien tanto con Harbour como con xHarbour
regards, saludos

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

Re: Función c gmtime(), obtener fecha y hora GMT

Postby Biel EA6DD » Fri Sep 04, 2009 7:05 am

Si te sirve de algo, estas son las funciones que utilizo para recuperar la GMT
Code: Select all  Expand view

//--------------
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/
User avatar
Biel EA6DD
 
Posts: 682
Joined: Tue Feb 14, 2006 9:48 am
Location: Mallorca

Re: Función c gmtime(), obtener fecha y hora GMT

Postby damosi » Fri Sep 04, 2009 8:13 am

Gracias
:D
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Re: Función c gmtime(), obtener fecha y hora GMT

Postby damosi » Fri Sep 04, 2009 12:37 pm

Encabezonado un poco he probado que el siguiente código si me funciona...

Code: Select all  Expand view

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.
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Re: Función c gmtime(), obtener fecha y hora GMT

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

Re: Función c gmtime(), obtener fecha y hora GMT

Postby damosi » Fri Sep 04, 2009 5:07 pm

Efectivamente Antonio he probado con Harbour 1.0.1 y funciona OK

Gracias-
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Re: Función c gmtime(), obtener fecha y hora GMT

Postby Antonio Linares » Fri Sep 04, 2009 7:26 pm

David,

Aqui estamos usando Harbour 2.0 beta 2:
www.fivetechsoft.com/files/harbour.exe
regards, saludos

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

Re: Función c gmtime(), obtener fecha y hora GMT

Postby damosi » 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: Select all  Expand view

#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
 
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Re: Función c gmtime(), obtener fecha y hora GMT

Postby Antonio Linares » Sat Sep 05, 2009 8:04 am

David,

gracias! :-)
regards, saludos

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

Re: Función c gmtime(), obtener fecha y hora GMT

Postby damosi » Mon Sep 07, 2009 10:14 am

Upps, el més hay que mostrarlo como abreviatura :D

Code: Select all  Expand view

#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
 
damosi
 
Posts: 35
Joined: Mon Jan 15, 2007 10:46 am

Next

Return to FiveWin para Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 9 guests