// // TimeDiff.vdm Christian Ziemski 23.11.2003 // 30.06.2004 // // // Prints out the difference between the two given timestamps. // // And divides that time by the given divisor. (Max. in milli-seconds yet) // // // IN: T-Reg 103: 1.st time 2.nd time [divisor] // HH:MM:SS[.CC] HH:MM:SS[.CC] [nnn] // // ^= 2x (Time(EXTRA+NOMSG)) // // OUT: T-Reg 104 with the results (as text) // // Will handle max. 24 hours, of course. // // The print out is a bit specialized for now. // But that will change in later versions. // //----------------------------------------------------------------------------- Buf_Switch(Buf_Free) Reg_Ins(103) BoF if (Match("|[|X]|D|[|D]:|D|D:|D|D|[.|D|D]|X|D|[|D]:|D|D:|D|D|[.|D|D]") != 0) { Message("Error: T-Reg 103 must contain two timestamps in the form HH:MM:SS[.CC] \n and an optional divisor. All divided by whitespace.\n") Buf_Quit(OK) return } Match("|X", ADVANCE) Num_Push(90,99) // save the used registers // evaluate hours, minutes, seconds, milli-seconds of starting time #91=Num_Eval() Char(3) #92=Num_Eval() Char(3) #93=Num_Eval(ADVANCE) if (Cur_Char==46) { // if on '.' => milli seconds there Char(1) #94=Num_Eval(ADVANCE) } else { #94=0 } Search("|!|X") // evaluate hours, minutes, seconds, milli-seconds of end time // to build the gone time #99=Num_Eval() #91=#99-#91 Char(3) #99=Num_Eval() #92=#99-#92 Char(3) #99=Num_Eval(ADVANCE) #93=#99-#93 if (Cur_Char==46) { // if on '.' => milli seconds there Char(1) #99=Num_Eval(ADVANCE) } else { #99=0 } #94=#99-#94 Search("|!|X", NOERR) // look for the optional divisor if (EM) { #103=1 } else { #103=Num_Eval() } // adjusting if (#94 < 0) { #94+=100 #93--} if (#93 < 0) { #93+=60 #92--} if (#92 < 0) { #92+=60 #91--} if (#91 < 0) { #91+=24 } // list the results Out_Reg(104) Message("Duration for ") Num_Type(#103, FORCE+NOCR) Message(" calls : ") if (#91<10) { Type_Char(48) } Num_Type(#91, LEFT+NOCR) Type_Char(58) if (#92<10) { Type_Char(48) } Num_Type(#92, LEFT+NOCR) Type_Char(58) if (#93<10) { Type_Char(48) } Num_Type(#93, LEFT+NOCR) Type_Char(46) if (#94<10) { Type_Char(48) } Num_Type(#94, LEFT+NOCR) #95=#91*60*60 + #92*60 + #93 // seconds // additionally show seconds for info Message(" (") Num_Type(#95, LEFT+NOCR) Message(".") if (#94<10) { Type_Char(48) } Num_Type(#94, LEFT+NOCR) Message(" seconds)") Message("\n") if (#103 > 1) { // if divisor is greater 1 Message(" for 1") Message(" call : ") #96=#95*100 + #94 // milli-seconds for whole loop #97=(#96 / #103) // milli-seconds per call #98=#97 / 100 // seconds per call if (#98<10000000){ Type_Char(32) } if (#98<1000000) { Type_Char(32) } if (#98<100000) { Type_Char(32) } if (#98<10000) { Type_Char(32) } if (#98<1000) { Type_Char(32) } if (#98<100) { Type_Char(32) } if (#98<10) { Type_Char(32) } Num_Type(#98, LEFT+NOCR) Message(".") #99=#97-#98*100 // remaining milli-seconds per call if (#99<10) { Type_Char(48) } Num_Type(#99, LEFT+NOCR) Message(" seconds\n\n") } Out_Reg(CLEAR) // Reg_Type(104) Buf_Quit(OK) Num_Pop(90,99) return