FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin para Harbour/xHarbour Sobre Cadenas de Tiempo
Posts: 105
Joined: Thu Feb 26, 2009 04:08 PM
Sobre Cadenas de Tiempo
Posted: Tue Apr 26, 2011 04:11 PM

Hola a todos, ojala alguien ya haya pasado por esto.

Mi cliente me pide que le muestre las notas de venta de 2 horas atras en cualquier horario
en mi tabla tengo un campo de texto con la hora en que se hicieron las notas
como puedo filtrarlas ?

si alguien me pudiera echar la mano.
De antemano muchas gracias.

Posts: 346
Joined: Mon Oct 05, 2009 03:35 PM
Re: Sobre Cadenas de Tiempo
Posted: Tue Apr 26, 2011 05:55 PM
Hola

no se si te sirva pero yo en una ocasión tuve que hacer esto con el calculo de horas extras, y lo que hice fue calcular los minutos de la hora que me devolvía la función time()

sería algo asi:
Code (fw): Select all Collapse
// nMinActual recoje los minutos transcurridos de la hora del computador

nMinActual := (val(strtran(substr(TIME(),1,2)," ","0"))*60 ) + val(strtran(substr(TIME(),4,2)," ","0"))

// nHaceDosHoras recoje el valor de de los minutos, restando 2 horas en minutos

nHaceDosHoras := nMinActual - 120


bueno obtienes los minutos transcurridos en una variable en la cual puedes filtrar en el campo de tu tabla.

se me ocurre de esta forma:
Code (fw): Select all Collapse
nMindelcampo := (val(strtran(substr(field->campohora,1,2)," ","0"))*60 ) + val(strtran(substr(field->campohora,4,2)," ","0"))

IF nMindelCampo = nHaceDosHoras
   .....
   // lo que necesites hacer
   .....
ENDIF


espero haberte ayudado.

saludos
SkyPe: armando.lagunas@hotmail.com

Mail: armando.lagunas@gmail.com
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Sobre Cadenas de Tiempo
Posted: Tue Apr 26, 2011 06:10 PM
creo recordar que xharbour y harbour ya manehjan el tipo de dato time, e incluso tiene funciones para manipulacion de horas.
DateTime() --> dDateTime
TtoS( <dDateTime>) --> cYYYYMMDDhhmmss.ccc
StoT( [<cDateTime>] ) --> dDateTime

Code (fw): Select all Collapse
// The example outlines basic operations with DateTime values and
// lists their results.

   PROCEDURE Main
      LOCAL d1, d2, nDiff

      SET CENTURY ON
      SET TIME FORMAT TO "hh:mm:ss.ccc"

      ? DateTime()                      // result: [today] [systemtime]
      ? {ˆ 2007/04/26}                  // result: 04/26/2007
      ? {ˆ 05:30:12.345}                // result: 12/30/1999 05:30:12.345
      ? {ˆ 05:30:12.345 PM}             // result: 12/30/1999 17:30:12.345

      ** Empty value
      ? d1 := {ˆ 0/0/0 }                // result:   /  /
      ? Empty( d )                      // result: .T.

      ** difference between DateTime and Date
      ? d1 := {ˆ 2007/04/26 18:30:00 }  // result: 04/26/2007 18:30:00.000
      ? d2 := StoD("20070426")          // result: 04/26/2007
      ? nDiff := d1-d2, "days"          // result: 0.77 days
      ? TString( nDiff*86400 )          // result: 18:30:00

      ** Adding 2 days to DateTime
      ? d1 + 2                          // result: 04/28/2007 18:30:00.000

      ** Adding 2 hours to DateTime
      ? d1 + 2/24                       // result: 04/26/2007 20:30:00.000

      ** Adding 2 minutes to DateTime
      ? d1 + 2/(24*60)                  // result: 04/26/2007 18:32:00.000

      ** Adding 2 seconds to DateTime
      ? d1 + 2/(24*3600)                // result: 04/26/2007 18:30:02.000

   RETURN
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 105
Joined: Thu Feb 26, 2009 04:08 PM
Re: Sobre Cadenas de Tiempo
Posted: Tue Apr 26, 2011 06:55 PM
Gracias Carlos

Lo solucione asi : Agrege un campo que se llama segundos numerico, y ahora cada vez que se guarda una nota se guardan los segundos calculados
los segundos calculados de la cadena de tiempo fue asi : hora * 60 * 60 lo minutos solo por 60
y sume los 3 y obtube los segundos totales

en el filtro
Code (fw): Select all Collapse
        nTime := RETORNA_SEGUNDOS(Time())  // aqui obtengo el los segundos pero en horas le resto 2
    cFiltro2 := "NOTASS->CAJA='"+AllTrim(aGENERAL[3])+"'"
    cFiltro1 := "NOTASS->SEGUNDOS >= "+AllTrim(Str(ntime))  
    cFiltro := "{||"+cFiltro2+" .AND. "+cFiltro1+"}"
    gFiltro := '"'+cFiltro2+' .AND. '+cFiltro1+'"'
    DbSetfilter(&cFiltro,&gFiltro)


solo asi.
Posts: 8515
Joined: Tue Dec 20, 2005 07:36 PM
Re: Sobre Cadenas de Tiempo
Posted: Tue Apr 26, 2011 07:43 PM

Javier, podrias muestrar esta función?

RETORNA_SEGUNDOS(Time())

Gracias, salu2

João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
Posts: 105
Joined: Thu Feb 26, 2009 04:08 PM
Re: Sobre Cadenas de Tiempo
Posted: Thu Apr 28, 2011 04:52 PM
Code (fw): Select all Collapse
FUNCTION RETORNA_SEGUNDOS(cTiempo)
    LOCAL nHora, nMinu, nSegu
    nHora := ((Val(SubStr(cTiempo,1,2))-2)*60)*60
    nMinu := Val(SubStr(cTiempo,4,2))*60
    nSegu := Val(SubStr(cTiempo,7,2))
RETURN (nHora+nMinu+nSegu)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sobre Cadenas de Tiempo
Posted: Fri Apr 29, 2011 02:56 AM
Both Harbour and xHarbour provide DateTime type. DBFCDX provides FieldType "T" to store DateTime values. It is now time for us to totally giveup the old complicated calculation with character value of Time().

In the following sample, I created a DBF with field type "T" and filled with some datetime values. While browsing I set the Scope Top to current time less 2 hours.
Code (fw): Select all Collapse
#include "FiveWin.Ch"
#include "ord.ch"
#include "xbrowse.ch"
#include "hbcompat.ch"

REQUEST DBFCDX

//----------------------------------------------------------------------------//

function Main()

   local oDlg, oBrw, oFont

   RDDSETDEFAULT( "DBFCDX" )
   SET DATE ITALIAN
   SET CENTURY ON
   SET TIME FORMAT TO "HH:MM"

   CreateTestDBF()

   USE TESTDTIM
   SET ORDER TO TAG TIMSTAMP
   SET SCOPETOP TO ( DateTime() - 2/24 )   // 2/24 = 2 hours
   GO TOP

   XBROWSER TITLE TTOC( DateTime() )

return nil

//----------------------------------------------------------------------------//

static function CreateTestDbf()

   field TIMSTAMP, TEXT

   local aCols := { ;
      { "TIMSTAMP",  "T",  8, 0  }, ;
      { "TEXT",      "C",  20,0  } }

   local t     := DateTime() - 5/24

   DBCREATE( "TESTDTIM", aCols )

   USE TESTDTIM EXCLUSIVE

   do while t < DateTime()
      APPEND BLANK
      TIMSTAMP    := t
      TEXT        := ATail( HB_ATokens( TTOC( t ), " " ) ) + ;
                     " Some text"
      t           += 1/24/4   // 1/24/4 = 15 minutes
   enddo

   INDEX ON TIMSTAMP TAG TIMSTAMP
   CLOSE TESTDTIM

return nil

//----------------------------------------------------------------------------//

Result:


In the above sample, I used FieldType "T", because I filled up different datetime values manually.

DBFCDX provides another FieldType "@". This field holds DateTime values, but we should not write to this field. DBFCDX automatically fills this field with the time the record is written automatically.

In real life, we may use "@" field type and let DBFCDX automatically record the time of writing the Data, instead of the program writing the timestamp. ( Note: xHarbour is working perfectly, but I found the my Harbour version does not fill this field correctly )
Regards



G. N. Rao.

Hyderabad, India
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Sobre Cadenas de Tiempo
Posted: Fri Apr 29, 2011 04:22 PM
hi, nageswaragunupudi

i delete lines of code with fwh calls, pure xharbour code.
Code (fw): Select all Collapse
    #include "ord.ch"

    REQUEST DBFCDX

    //----------------------------------------------------------------------------//

    function Main()

       local oDlg, oBrw, oFont

       RDDSETDEFAULT( "DBFCDX" )
       SET DATE ITALIAN
       SET CENTURY ON
       SET TIME FORMAT TO "HH:MM"

       CreateTestDBF()

       USE TESTDTIM
       SET ORDER TO TAG TIMSTAMP
       SET SCOPETOP TO ( DateTime() - 2/24 )   // 2/24 = 2 hours
       GO TOP
       browse()

    return nil

    //----------------------------------------------------------------------------//

    static function CreateTestDbf()

       field TIMSTAMP, TEXT
       local aCols := { ;
          { "TIMSTAMP",  "T",  8, 0  }, ;
          { "TEXT",      "C",  20,0  } }

       local t  := DateTime() - 5/24

       DBCREATE( "TESTDTIM", aCols )

       USE TESTDTIM EXCLUSIVE
       
       
       do while t < DateTime()

          APPEND BLANK
          TIMSTAMP    := t
          TEXT        := ATail( HB_ATokens( TTOC( t ), " " ) ) + ;
                         " Some text"
          t           += 1/24/4   // 1/24/4 = 15 minutes
       enddo

       INDEX ON TIMSTAMP TAG TIMSTAMP
       CLOSE TESTDTIM
       wait
    return nil


fail in this line

do while t < DateTime()
this is the info error:

Arguments .........: [ 1] = Type: N Val: 2455681.43 [ 2] = Type: T Val: Type: T

1 param: value 2455681.43
2 param: value 29/04/2011 10:18:00

compiling you code (full, no delete lines, incude call to fwh lib), fails, the datetime function no return value ?????
fails with apis mix between fwh and xharbour???
Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sobre Cadenas de Tiempo
Posted: Sat Apr 30, 2011 07:26 AM

I understand you are using Harbour ( not xHarbour ). Please comfirm.

DateTime() is function available in xHarbour.
Corresponding function in Harbour is HB_DateTime(). You may change DateTime() to HB_DateTime()

I included "hbcompat.ch". This include file translates DateTime() as HB_DateTime() if we are compiling with Harbour and translates HB_DateTime() as DateTime() if we are compiling with xHarbour.

similarly
HB_TTOC() and HB_CTOT() in Harbour are same as TTOC() and CTOT() in xHarbour.

Either you may hardcode these functions specially for Harbour or better you include the file "hbcompat.ch".

I compiled and tested my sample both with xHarbour and Harbour using the include file "hbcompat.ch".

While compiling with Harbour I also include xhb.lib and hbct.lib.

Note: I am not sure if the native ( Clipper compatible ) Browse() function in Harbour can handle new datatypes.

FWH's xBrowse() function handles all datatypes and all datasources.

Regards



G. N. Rao.

Hyderabad, India
Posts: 1789
Joined: Tue Oct 11, 2005 05:01 PM
Re: Sobre Cadenas de Tiempo
Posted: Sat Apr 30, 2011 04:49 PM

not, i use the last version from xharbour.com

salu2
carlos vargas

:-(

Salu2

Carlos Vargas

Desde Managua, Nicaragua (CA)
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sobre Cadenas de Tiempo
Posted: Sun May 01, 2011 05:23 AM
I have built exactly the sample posted by you in xHarbour ( without fivewin ) 1.2.1 build 6733 ( downloaded from free.xharbour.com ) and the exe runs without any errors:

Here is the output:

Regards



G. N. Rao.

Hyderabad, India
Posts: 842
Joined: Mon Oct 10, 2005 01:29 PM
Re: Sobre Cadenas de Tiempo
Posted: Mon May 02, 2011 12:44 PM

hi, nageswaragunupudi

if I compile xbrowse.prg I have this

Compiling 'C:\FWH_04\MY_FW\xbrowse.prg' and generating preprocessed output to 'C:\FWH_04\MY_FW\xbrowse.ppo'...
c:\Harbour\include\hbcompat.ch(266) Warning W0002 Redefinition or duplicate definition of #define GTI_WINDOW
c:\Harbour\include\hbcompat.ch(267) Warning W0002 Redefinition or duplicate definition of #define GTI_SCREEN
c:\Harbour\include\hbcompat.ch(268) Warning W0002 Redefinition or duplicate definition of #define GTI_CLIENT
c:\Harbour\include\hbcompat.ch(269) Warning W0002 Redefinition or duplicate definition of #define GTI_MAX
c:\Harbour\include\hbcompat.ch(338) Warning W0002 Redefinition or duplicate definition of #define HB_GTI_CLIPBOARDPAST

Regards Maurizio

Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Sobre Cadenas de Tiempo
Posted: Mon May 02, 2011 05:17 PM

Here it is compiling without any warnings in both xHarbour and Harbour.
Please make sure that your compile script does not include any other include files other than those included inside the xbrowse.prg.

Regards



G. N. Rao.

Hyderabad, India

Continue the discussion