Time Calculations

Time calculations are needed when placing GAT (Good At Time) and GTD (Good Till Date) orders. The simplest way is to convert the TimeNum to a SecondNum, perform your calculations in Seconds, and then convert the SecondNum back to a TimeNum. The first two functions below will do that for you.

The next function applies a reference expressed in seconds to your Reference time. This reference would typically be used to Calculate GAT times. You may need this function when you want to apply an offset to a Time Reference and have orders activated automatically during the day without having to be online.

function TimeNumToSecondNumTimeNumber )
Seconds int(TimeNumber%100);
Minutes int(TimeNumber/100%100);
Hours int(TimeNumber/10000%100);
NumberSecs int(3600*Hours+60*Minutes+Seconds);
return NumberSecs;
function SecondNumToTimeNumSecondNum )
Hours int(SecondNum /3600);
Minutes int((SecondNum -Hours*3600)/60);
Seconds int((SecondNum -Hours*3600)-Minutes*60);
TimeNumber Hours*10000 Minutes*100 Seconds;
return TimeNumber;
function ApplyOffsetToTimeNumRefTimeNumberOffset )
OffsetSecondNum TimeNumToSecondNumRefTimeNumber ) + Offset;
OffsetTimeNumber SecondNumToTimeNumOffsetSecondNum );
return OffsetTimeNumber;
OffSet Param("Offset in Seconds",0,-100,100,1);
RefTimeNum ParamTime("ReferenceTime",Now(2));
CalcTimeNum ApplyOffsetToTimeNumRefTimeNumOffset );
Title ="\n"+
" Reference Time: "+StrRight(NumToStr(DateTimeConvert2DateNum(), RefTimeNum),formatDateTime),11)+"\n"+
"Calculated Time: "+StrRight(NumToStr(DateTimeConvert2DateNum(), CalcTimeNum ),formatDateTime),11)+"\n";

Edited by Al Venosa.

Comments are closed.