May 9, 2007
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 TimeNumToSecondNum( TimeNumber ) { Seconds = int(TimeNumber%100); Minutes = int(TimeNumber/100%100); Hours = int(TimeNumber/10000%100); NumberSecs = int(3600*Hours+60*Minutes+Seconds); return NumberSecs;
function SecondNumToTimeNum( SecondNum ) { 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 ApplyOffsetToTimeNum( RefTimeNumber, Offset ) { OffsetSecondNum = TimeNumToSecondNum( RefTimeNumber ) + Offset; OffsetTimeNumber = SecondNumToTimeNum( OffsetSecondNum ); return OffsetTimeNumber; }
OffSet = Param("Offset in Seconds",0,-100,100,1); RefTimeNum = ParamTime("ReferenceTime",Now(2)); CalcTimeNum = ApplyOffsetToTimeNum( RefTimeNum, Offset ); Title ="\n"+ " Reference Time: "+StrRight(NumToStr(DateTimeConvert( 2, DateNum(), RefTimeNum),formatDateTime),11)+"\n"+ "Calculated Time: "+StrRight(NumToStr(DateTimeConvert( 2, DateNum(), CalcTimeNum ),formatDateTime),11)+"\n";
Edited by Al Venosa.
Filed by Herman at 11:55 am under Real-Time AFL Programming
Comments Off on Time Calculations