Hi Ferdinando,

        I am not sure I understand exactly what you are trying to do. Here are 
a few utility methods that I have used over the years, perhaps one or more of 
them might be of use to you.

John

> On Sep 5, 2016, at 10:52 PM, stardata.info <[email protected]> wrote:

> I need to check the timeout in one communication process.
> For timeout qty i use ticks unity, how i can do for to measure if the timeout 
> inserted is elapsed?
> I have current time, but he is not expressed in ticks, is necessary to 
> convert the current time in ticks?
> Someone have a code for do this?


__________________________________________________________
__________________________________________________________
  // Method: NumToTicks
  // ----------------------------------------------------
  // User name (OS): John Baughman  
  // Date and time: September 23, 1994
  // ----------------------------------------------------
  // Description
  //Convert a number of seconds, minutes or hours to ticks
  //
  // Parameters
C_REAL($num;$1;$ticks;$0)
$num:=$1

C_TEXT($timeIncrement;$2)
$timeIncrement:=$2
  // ----------------------------------------------------

Case of 
: ($timeIncrement="s")
$ticks:=$num*60

: ($timeIncrement="m")
$ticks:=$num*60*60

: ($timeIncrement="h")
$ticks:=$num*60*60*60


End case 

$0:=$ticks


__________________________________________________
__________________________________________________
  // Method: TicksToNum_jut
  // ----------------------------------------------------
  // User name (OS): John Baughman
  // Date and time: January 23, 1999
  // ----------------------------------------------------
  // Description
  //Convert ticks to a number of seconds, minutes or hours
  //
  // Parameters
C_LONGINT($ticks;$1)
$ticks:=$1

C_TEXT($timeIncrment;$2)
$timeIncrement:=$2

C_REAL($num;$0)
  // ----------------------------------------------------

Case of 

: ($timeIncrement="s")
$num:=$1/60

: ($timeIncrement="m")
$num:=($1/60)/60

: ($timeIncrement="h")
$num:=(($1/60)/60)/60

End case 

$0:=$num

__________________________________________________
__________________________________________________
  // Method: NumToTicks_Jut
  // ----------------------------------------------------
  // User name (OS): John Baughman  
  // Date and time: September 23, 1994
  // ----------------------------------------------------
  // Description
  //Convert a number of seconds, minutes or hours to ticks
  //
  // Parameters
C_REAL($num;$1;$ticks;$0)
$num:=$1

C_TEXT($timeIncrement;$2)
$timeIncrement:=$2
  // ----------------------------------------------------

Case of 
: ($timeIncrement="s")
$ticks:=$num*60

: ($timeIncrement="m")
$ticks:=$num*60*60

: ($timeIncrement="h")
$ticks:=$num*60*60*60


End case 

$0:=$ticks

__________________________________________________
__________________________________________________
  // Method: TicksTilTime
  // ----------------------------------------------------
  // User name (OS): John Baughman
  // Date and time: August 5, 1994
  // ----------------------------------------------------
  // Description
  //$2 is the start time and $1 is the end time
  //If no times are passed the number of ticks between the current time and 
midnight is returned.
  //If only $1 (the end time) is passed, the number of ticks between the the 
current time and $1 (end time) returned.
  //If $1 (end time) and $2 (start time) are both passed the number of ticks 
beween the 2 times are returned
  //If $1 is ?00:00:00?, the end time is midnight (?24:00:00?)
  //Works over midnight but only within a 24 hour period. If the end time is 
earlier than the start time, then end time is assumed to be next day.

  // Parameters
C_TIME($timeTo;$1;$timeFrom;$2)
C_LONGINT($0)

If (Count parameters=2)
$timeFrom:=$2

Else 
$timeFrom:=Current time(*)

End if 

If (Count parameters=0)
$timeTo:=?00:00:00?

Else 
$timeTo:=$1

End if 
  // ----------------------------------------------------

If ($timeTo#?00:00:00?)
If ($timeTo>=$timeFrom)
$0:=NumToTicks ($timeTo-$timeFrom;"s")  

Else 
$0:=NumToTicks (?24:00:00?-$timeFrom+$timeTo;"s")

End if 

Else   //
$0:=NumToTicks (?24:00:00?-$timeFrom;"s")

End if 

__________________________________________________
__________________________________________________
 // Method: Timer
  // ----------------------------------------------------
  // User name (OS): John Baughman
  // Date and time: January 23, 1999
  // ----------------------------------------------------
  // Description
  //by passing pointers to your own start variable you can have more than
  //one timer going at a time
  //Timer(start)
  //Timer("t") -> ticks since start
  //Timer("s") -> seconds since start
  //Timer("m") -> minutes since start
  //Timer("h") -> hours since start
  //Timer(stop)

If (False)  //Example
Timer ("Start")
While (Not(<>QuitMaintenance)) & (Timer ("s")<10)
  //waiting for the <>QuitMaintenance variable to be set to true for max of 10 
seconds
End while 
End if 

C_LONGINT(vTimerStartTime;$TimerCurrentTicks)
$TimerCurrentTicks:=Tickcount  //get the ticks first for accuracy

C_REAL($0)
C_POINTER($startPtr;$CheckPtr)

If (Count parameters=1)
$StartPtr:=->vTimerStartTime

Else 
$StartPtr:=$2

End if 

If ($1="Start")
$StartTime:=$TimerCurrentTicks

End if 

Case of 

: ($1="Stop")
$StartPtr->:=0

: ($1="Start")
$StartPtr->:=$StartTime

: ($StartPtr->=0)
IDLE
$0:=0

: ($1="t")
$0:=$TimerCurrentTicks-$StartPtr->

Else 
$0:=TicksToNum ($TimerCurrentTicks-$StartPtr->;$1)


End case 


**********************************************************************
4D Internet Users Group (4D iNUG)
FAQ:  http://lists.4d.com/faqnug.html
Archive:  http://lists.4d.com/archives.html
Options: http://lists.4d.com/mailman/options/4d_tech
Unsub:  mailto:[email protected]
**********************************************************************

Reply via email to