Convert a duration to tick

This method converts a duration in ticks. The default duration is
second but it can be minute, hour or day.

For example: a quarantine equals 207 360 000 ticks

This code is 16R6 compatible. For previous 4D versions you can remove the assert test.

https://forums.4d.com/4DBB_Main/x_User/3906/files/34405979.zip

<code 4D>
// Method Convert_to_tick receives a duration and converts it to ticks
//
// #SYNTAX: $L_Erreur:=Convert_to_tick(value;{unit})
// #PARAMETERS:
// $0 Long : Tick conversion
// $1 Real : value to be converted to tick
// $1 Text : optional, sec, min, hour default = sec

// #DATE CREATION: 21/03/2020 #AUTHOR: Bertrand SOUBEYRAND info@soubeyrand-4d-developer.eu
// #DATE MODIFICATION: 00/00/0000
// #NOTE:

// #HEADER VERSION: 2

// #20200321-1

C_LONGINT($0;$L_Tick)
C_REAL($1;$R_Value)
$R_Value:=$1

C_TEXT($T_Unit)
$T_Unit:=“sec” // Default converts seconds to tick

If (Count parameters=2)

C_TEXT($2;$T_Unit)
$T_Unit:=$2

C_COLLECTION($C_Valid_unit)
$C_Valid_unit:=New collection("sec";"min";"hour";"heure";"stunde";"jour";"day";"tag")

ASSERT($C_Valid_unit.indexOf($T_Unit)#-1;"The optional param unit is not valid")

End if

Case of
: ($T_Unit=“day”) | ($T_Unit=“jour”) | ($T_Unit=“tag”)

	$L_Tick:=$R_Value*60*60*60*24  // day to tick
	
: ($T_Unit="hour") | ($T_Unit="heure") | ($T_Unit="stunde")
	
	$L_Tick:=$R_Value*60*60*60  // hours to tick
	
: ($T_Unit="min")
	
	$L_Tick:=$R_Value*60*60  // minutes to tick
	
Else 
	$L_Tick:=$R_Value*60  // secondes to tick

End case

$0:=$L_Tick // doesn’t check the length of a longint !

// EOM

</code 4D>