KMPDU ;OAK/RAK - CM Tools Utility ;2/17/04 09:47
;;3.0;KMPD;;Jan 22, 2009;Build 42
;
GBLCHECK(GLOBAL) ;-- extrinsic function
;-----------------------------------------------------------------------
; GLOBAL.. Global name to be checked. Must be either:
; ^XTMP
; ^TMP
; ^UTILITY
;
; RESUTL: 0 - Does not pass.
; 1 - Passes.
;-----------------------------------------------------------------------
Q:$G(GLOBAL)="" 0
N GBL,I,RESULT
S RESULT=0
S GBL=GLOBAL
;-- remove '^'.
S GBL=$E(GBL,2,$L(GBL))
;-- remove '('.
S GBL=$P(GBL,"(")
F I="XTMP","TMP","UTILITY" I GBL=I S RESULT=1 Q
Q RESULT
;
FMDTI(Y,X) ;-- date/time in internal fileMan format.
;----------------------------------------------------------------------
; X - User response ('T', '12/12/94', etc.)
;
; Return: Y(0)=InternalFilemanDate
; Y(1)=ExternalFilemanDate
;----------------------------------------------------------------------
K Y
I $G(X)']"" S Y(0)="^" Q
N %DT,DATETIME
S %DT="ST" D ^%DT
S DATETIME=$S(Y>0:Y,1:"^")
K Y
;-- fm internal format.
S Y(0)=DATETIME
;-- external format.
S Y(1)=$$FMTE^XLFDT(DATETIME)
Q
;
KILL(RESULT,VARIABLE) ;-- kill variables.
;-----------------------------------------------------------------------
; VARIABLE... local or global variable to be killed.
;
; This subroutine kills variables (local or global). It should be used
; mostly to kill global variables that have been set when components
; have been populated with long lists that were set into temporary
; globals. If VARIABLE is a global variable, it must be either ^TMP or
; ^UTILITY to be killed.
;-----------------------------------------------------------------------
K RESULT S RESULT=""
I $G(VARIABLE)="" S RESULT="[No variable to kill]" Q
I $E(VARIABLE)="^" D Q:RESULT]""
.I '$$GBLCHECK(VARIABLE) D
..S RESULT="[Can only kill globals ^XTMP, ^TMP or ^UTILITY]"
K @VARIABLE
S RESULT="<"_VARIABLE_" killed>"
Q
;
TIMEADD(KMPDTM,KMPDADD) ;-- extrinsic function - add time
;----------------------------------------------------------------------
; KMPDTM... Current time in dy hr:mn:sc format
; KMPDTM... Time to add to current time in dy hr:mn:sc format
;
; RETURN: total in dy hr:mn:sc format
;----------------------------------------------------------------------
Q:$G(KMPDTM)="" ""
Q:$G(KMPDADD)="" KMPDTM
N DY,HR,MN,SC
; current time
S DY(1)=+$P(KMPDTM," ")
S HR(1)=+$P($P(KMPDTM," ",2),":")
S MN(1)=+$P($P(KMPDTM," ",2),":",2)
S SC(1)=+$P($P(KMPDTM," ",2),":",3)
; time to be added
S DY(2)=+$P(KMPDADD," ")
S HR(2)=+$P($P(KMPDADD," ",2),":")
S MN(2)=+$P($P(KMPDADD," ",2),":",2)
S SC(2)=+$P($P(KMPDADD," ",2),":",3)
; add seconds
S SC(3)=SC(1)+SC(2)
; if greater than 59 seconds
I SC(3)>59 S MN(3)=SC(3)\60,SC(3)=SC(3)-60
; add minutes
S MN(3)=$G(MN(3))+MN(1)+MN(2)
; if greater than 59 minutes
I MN(3)>59 S HR(3)=MN(3)\60,MN(3)=MN(3)-60
; add hours
S HR(3)=$G(HR(3))+HR(1)+HR(2)
; if greater than 23 hours
I HR(3)>23 S DY(3)=HR(3)\24,HR(3)=HR(3)-24
; days
S DY(3)=$G(DY(3))+DY(1)+DY(2)
;
Q DY(3)_" "_HR(3)_":"_MN(3)_":"_SC(3)
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HKMPDU 3243 printed Oct 16, 2024@17:41:47 Page 2
KMPDU ;OAK/RAK - CM Tools Utility ;2/17/04 09:47
+1 ;;3.0;KMPD;;Jan 22, 2009;Build 42
+2 ;
GBLCHECK(GLOBAL) ;-- extrinsic function
+1 ;-----------------------------------------------------------------------
+2 ; GLOBAL.. Global name to be checked. Must be either:
+3 ; ^XTMP
+4 ; ^TMP
+5 ; ^UTILITY
+6 ;
+7 ; RESUTL: 0 - Does not pass.
+8 ; 1 - Passes.
+9 ;-----------------------------------------------------------------------
+10 if $GET(GLOBAL)=""
QUIT 0
+11 NEW GBL,I,RESULT
+12 SET RESULT=0
+13 SET GBL=GLOBAL
+14 ;-- remove '^'.
+15 SET GBL=$EXTRACT(GBL,2,$LENGTH(GBL))
+16 ;-- remove '('.
+17 SET GBL=$PIECE(GBL,"(")
+18 FOR I="XTMP","TMP","UTILITY"
IF GBL=I
SET RESULT=1
QUIT
+19 QUIT RESULT
+20 ;
FMDTI(Y,X) ;-- date/time in internal fileMan format.
+1 ;----------------------------------------------------------------------
+2 ; X - User response ('T', '12/12/94', etc.)
+3 ;
+4 ; Return: Y(0)=InternalFilemanDate
+5 ; Y(1)=ExternalFilemanDate
+6 ;----------------------------------------------------------------------
+7 KILL Y
+8 IF $GET(X)']""
SET Y(0)="^"
QUIT
+9 NEW %DT,DATETIME
+10 SET %DT="ST"
DO ^%DT
+11 SET DATETIME=$SELECT(Y>0:Y,1:"^")
+12 KILL Y
+13 ;-- fm internal format.
+14 SET Y(0)=DATETIME
+15 ;-- external format.
+16 SET Y(1)=$$FMTE^XLFDT(DATETIME)
+17 QUIT
+18 ;
KILL(RESULT,VARIABLE) ;-- kill variables.
+1 ;-----------------------------------------------------------------------
+2 ; VARIABLE... local or global variable to be killed.
+3 ;
+4 ; This subroutine kills variables (local or global). It should be used
+5 ; mostly to kill global variables that have been set when components
+6 ; have been populated with long lists that were set into temporary
+7 ; globals. If VARIABLE is a global variable, it must be either ^TMP or
+8 ; ^UTILITY to be killed.
+9 ;-----------------------------------------------------------------------
+10 KILL RESULT
SET RESULT=""
+11 IF $GET(VARIABLE)=""
SET RESULT="[No variable to kill]"
QUIT
+12 IF $EXTRACT(VARIABLE)="^"
Begin DoDot:1
+13 IF '$$GBLCHECK(VARIABLE)
Begin DoDot:2
+14 SET RESULT="[Can only kill globals ^XTMP, ^TMP or ^UTILITY]"
End DoDot:2
End DoDot:1
if RESULT]""
QUIT
+15 KILL @VARIABLE
+16 SET RESULT="<"_VARIABLE_" killed>"
+17 QUIT
+18 ;
TIMEADD(KMPDTM,KMPDADD) ;-- extrinsic function - add time
+1 ;----------------------------------------------------------------------
+2 ; KMPDTM... Current time in dy hr:mn:sc format
+3 ; KMPDTM... Time to add to current time in dy hr:mn:sc format
+4 ;
+5 ; RETURN: total in dy hr:mn:sc format
+6 ;----------------------------------------------------------------------
+7 if $GET(KMPDTM)=""
QUIT ""
+8 if $GET(KMPDADD)=""
QUIT KMPDTM
+9 NEW DY,HR,MN,SC
+10 ; current time
+11 SET DY(1)=+$PIECE(KMPDTM," ")
+12 SET HR(1)=+$PIECE($PIECE(KMPDTM," ",2),":")
+13 SET MN(1)=+$PIECE($PIECE(KMPDTM," ",2),":",2)
+14 SET SC(1)=+$PIECE($PIECE(KMPDTM," ",2),":",3)
+15 ; time to be added
+16 SET DY(2)=+$PIECE(KMPDADD," ")
+17 SET HR(2)=+$PIECE($PIECE(KMPDADD," ",2),":")
+18 SET MN(2)=+$PIECE($PIECE(KMPDADD," ",2),":",2)
+19 SET SC(2)=+$PIECE($PIECE(KMPDADD," ",2),":",3)
+20 ; add seconds
+21 SET SC(3)=SC(1)+SC(2)
+22 ; if greater than 59 seconds
+23 IF SC(3)>59
SET MN(3)=SC(3)\60
SET SC(3)=SC(3)-60
+24 ; add minutes
+25 SET MN(3)=$GET(MN(3))+MN(1)+MN(2)
+26 ; if greater than 59 minutes
+27 IF MN(3)>59
SET HR(3)=MN(3)\60
SET MN(3)=MN(3)-60
+28 ; add hours
+29 SET HR(3)=$GET(HR(3))+HR(1)+HR(2)
+30 ; if greater than 23 hours
+31 IF HR(3)>23
SET DY(3)=HR(3)\24
SET HR(3)=HR(3)-24
+32 ; days
+33 SET DY(3)=$GET(DY(3))+DY(1)+DY(2)
+34 ;
+35 QUIT DY(3)_" "_HR(3)_":"_MN(3)_":"_SC(3)