INHUTS ;JMB; 18 Sep 96 09:35;Monitoring utilities
;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
;COPYRIGHT 1991-2000 SAIC
Q
;
QUIT() ;User presses any key
;OUTPUT
; function: 1 - time to exit
; 0 - continue
Q:INTASKED 0
N %,INEXIT S INEXIT=0
R %#1:0 I $L(%)!$T S INEXIT=1
Q INEXIT
;
FT0(DA) ;Returns formatted date-time
;INPUT:
; DA - Date to be formatted in $H format
;OUTPUT:
; Function value - Time difference in format:
; "HH:II:SS", "T-D@HH:MM", "T-DD@HH:MM", etc.
; (Max length of output string is 10)
;
N H,DIF,INT
Q:'$L($G(DA)) ""
S H=$$DATEFMT^UTDT(DA,"@HH:II:SS")
Q:+DA=+$H $P(H,"@",2) ; HH:II:SS
;Day difference
I +$H>+DA S DIF=+$H-(+DA),INT="T-"
I +$H'>+DA S DIF=(+DA)-(+$H),INT="T+"
Q:$L(DIF)=1 $E(INT_DIF_H,1,9) ; T-D@HH:MM
Q:$L(DIF)=2 $E(INT_DIF_H,1,10) ; T-DD@HH:MM
Q $E(INT_DIF_H,1,10) ; T-DDD@HH:M, ...
;
FT1(T,FMT) ;Returns formatted date-time
;INPUT:
; T - number of seconds
; FMT - format of output
; 1 - Exps: a.- 23 (sec is the default unit);b.- 25m 50s
; c.- 22h 23m; d.- 98d 14h
; Non-significant time is discarded.
; Max output length is 7 characters.
; Largest output: 99d 23h.
; 2 - Exps: a.- 3s; b.- 1.8m (i.e. 1m and 45s); c.- 2.5d
; Returns up to 1 decimal.
; Largest output: 99.9d
;OUTPUT:
; Function value - formatted output
;
;Quit if no input value
Q:'$L($G(T)) ""
;Quit if no valid format number
Q:";1;2"'[FMT ""
;
N D,H,M,S
S D=T\86400,H=(T#86400)\3600,M=(T#3600)\60,S=T#60
Q:FMT=1 $$FM1(D,H,M,S)
Q:FMT=2 $$FM2(T,D,H,M,S)
Q
;
FM1(D,H,M,S) ;Format type 1
I 'M,'H,'D Q S ;ex. 23 (sec is the default unit)
I 'H,'D Q M_"m "_S_"s" ;ex. 25m 50s
I 'D Q H_"h "_M_"m" ;ex. 22h 23m
I D<100 Q D_"d "_H_"h" ;ex. 98d 14h
Q "xxx" ;Overflow
;
FM2(T,D,H,M,S) ;Format type 2
;
;Overflow
I D>99 Q "xxx"
;Days, exp. 2.5d
I D S D=T/86400 S:$P(D,".",2) D=$J(D,"",1) S D=D_"d" Q D
;Hours, ex. 3.1h
I H S H=T/3600 S:$P(H,".",2) H=$J(H,"",1) S H=H_"h" Q H
;Minutes, ex. 1.8m
I M S M=T/60 S:$P(M,".",2) M=$J(M,"",1) S M=M_"m" Q M
;Seconds, exp. 1, 0.6
S:$P(S,".",2) S=$J(S,"",1)
Q S
;
TDIF(SAR,SOP,FMT) ;Return time differences (seconds) beween two dates
;INPUT:
; SAR - starting date time (in any format)
; SOP - stop date time (in any format) (def is NOW)
; FMT - format of output
; 0 - number of seconds (def)
; 1 - formatted output (w/o seconds)
; 2 - formatted output (with seconds)
;OUTPUT:
; function value - time difference
; number of seconds or formatted output
;
N TOT
N SESAR,SESOP,DTSAR,DTSOP,SEOV,SESOPTOT,SESARTOT ;JMB 6/5/95
;Quit if no start_date
Q:'$L($G(SAR)) ""
;Set default stop_date to NOW
S:'$L($G(SOP)) SOP=$H
;Convert dates to $H format
S SAR=$$CONV(SAR),SOP=$$CONV(SOP) Q:'SAR!'SOP ""
;Get starting time and ending time
S SESAR=+$P(SAR,",",2),SESOP=+$P(SOP,",",2)
;Get start_day and end_day
S DTSAR=+SAR,DTSOP=+SOP
;Initialize overflow_days_seconds and total_stop_date_seconds
S SEOV=0,SESOPTOT=0
;Set total_start_date_seconds
S SESARTOT=SESOP-SESAR
;If days are not the same calculate seconds for each date
I DTSAR'=DTSOP D
. ;Calculate total_start_date_seconds
. S SESARTOT=86400-SESAR
. ;Calcualte total_stop_date_seconds
. S SESOPTOT=SESOP
;Check if days are more than one day apart
I (DTSOP-DTSAR-1)>0 D
. ;Set overlfow_seconds
. S SEOV=(DTSOP-DTSAR-1)*86400
;Calculate total_seconds
S TOT=SESARTOT+SESOPTOT+SEOV
;Convert to text format
I $G(FMT) S TOT=$$FORMAT(TOT,$G(FMT))
Q TOT
;
CONV(DATE) ;Convert to $H format
;INPUT:
; DATE - in any format
;OUTPUT:
; function value - date in $H format or null
;
;Check for $H format
Q:DATE?5N.1",".5N DATE
;Check for text format
I DATE'?7N.1".".N S DATE=$$CDATA2F^UTDT(DATE,"TI")
;Check for Fileman internal format
I DATE?7N.1".".N S DATE=$$CDATF2H^UTDT(DATE)
I DATE<1 S DATE=""
Q DATE
;
FORMAT(T,SEC) ;Convert number of seconds to formatted time
;INPUT:
; T - number of seconds
; SEC - display seconds ( 0 - no (def) ; 2 - yes )
;OUTPUT:
; function - formatted time ( ex: 2 dy 1 hr 23 min 12 sec )
;
Q:'$L($G(T)) ""
Q:'T "0 sec"
N D,H,M,S,TX
S SEC=$S($G(SEC)>1:1,1:0),TX="",D=T\86400,H=(T#86400)\3600,M=(T#3600)\60,S=T#60
S:SEC TX=S_" sec "
S:M!'SEC TX=M_" min "_TX
S:H!D TX=H_" hr "_TX
S:D TX=D_" dy "_TX
Q TX
INHUTS ;JMB; 18 Sep 96 09:35;Monitoring utilities
+1 ;;3.01;BHL IHS Interfaces with GIS;;JUL 01, 2001
+2 ;COPYRIGHT 1991-2000 SAIC
+3 QUIT
+4 ;
QUIT() ;User presses any key
+1 ;OUTPUT
+2 ; function: 1 - time to exit
+3 ; 0 - continue
+4 IF INTASKED
QUIT 0
+5 NEW %,INEXIT
SET INEXIT=0
+6 READ %#1:0
IF $LENGTH(%)!$TEST
SET INEXIT=1
+7 QUIT INEXIT
+8 ;
FT0(DA) ;Returns formatted date-time
+1 ;INPUT:
+2 ; DA - Date to be formatted in $H format
+3 ;OUTPUT:
+4 ; Function value - Time difference in format:
+5 ; "HH:II:SS", "T-D@HH:MM", "T-DD@HH:MM", etc.
+6 ; (Max length of output string is 10)
+7 ;
+8 NEW H,DIF,INT
+9 IF '$LENGTH($GET(DA))
QUIT ""
+10 SET H=$$DATEFMT^UTDT(DA,"@HH:II:SS")
+11 ; HH:II:SS
IF +DA=+$HOROLOG
QUIT $PIECE(H,"@",2)
+12 ;Day difference
+13 IF +$HOROLOG>+DA
SET DIF=+$HOROLOG-(+DA)
SET INT="T-"
+14 IF +$HOROLOG'>+DA
SET DIF=(+DA)-(+$HOROLOG)
SET INT="T+"
+15 ; T-D@HH:MM
IF $LENGTH(DIF)=1
QUIT $EXTRACT(INT_DIF_H,1,9)
+16 ; T-DD@HH:MM
IF $LENGTH(DIF)=2
QUIT $EXTRACT(INT_DIF_H,1,10)
+17 ; T-DDD@HH:M, ...
QUIT $EXTRACT(INT_DIF_H,1,10)
+18 ;
FT1(T,FMT) ;Returns formatted date-time
+1 ;INPUT:
+2 ; T - number of seconds
+3 ; FMT - format of output
+4 ; 1 - Exps: a.- 23 (sec is the default unit);b.- 25m 50s
+5 ; c.- 22h 23m; d.- 98d 14h
+6 ; Non-significant time is discarded.
+7 ; Max output length is 7 characters.
+8 ; Largest output: 99d 23h.
+9 ; 2 - Exps: a.- 3s; b.- 1.8m (i.e. 1m and 45s); c.- 2.5d
+10 ; Returns up to 1 decimal.
+11 ; Largest output: 99.9d
+12 ;OUTPUT:
+13 ; Function value - formatted output
+14 ;
+15 ;Quit if no input value
+16 IF '$LENGTH($GET(T))
QUIT ""
+17 ;Quit if no valid format number
+18 IF ";1;2"'[FMT
QUIT ""
+19 ;
+20 NEW D,H,M,S
+21 SET D=T\86400
SET H=(T#86400)\3600
SET M=(T#3600)\60
SET S=T#60
+22 IF FMT=1
QUIT $$FM1(D,H,M,S)
+23 IF FMT=2
QUIT $$FM2(T,D,H,M,S)
+24 QUIT
+25 ;
FM1(D,H,M,S) ;Format type 1
+1 ;ex. 23 (sec is the default unit)
IF 'M
IF 'H
IF 'D
QUIT S
+2 ;ex. 25m 50s
IF 'H
IF 'D
QUIT M_"m "_S_"s"
+3 ;ex. 22h 23m
IF 'D
QUIT H_"h "_M_"m"
+4 ;ex. 98d 14h
IF D<100
QUIT D_"d "_H_"h"
+5 ;Overflow
QUIT "xxx"
+6 ;
FM2(T,D,H,M,S) ;Format type 2
+1 ;
+2 ;Overflow
+3 IF D>99
QUIT "xxx"
+4 ;Days, exp. 2.5d
+5 IF D
SET D=T/86400
IF $PIECE(D,".",2)
SET D=$JUSTIFY(D,"",1)
SET D=D_"d"
QUIT D
+6 ;Hours, ex. 3.1h
+7 IF H
SET H=T/3600
IF $PIECE(H,".",2)
SET H=$JUSTIFY(H,"",1)
SET H=H_"h"
QUIT H
+8 ;Minutes, ex. 1.8m
+9 IF M
SET M=T/60
IF $PIECE(M,".",2)
SET M=$JUSTIFY(M,"",1)
SET M=M_"m"
QUIT M
+10 ;Seconds, exp. 1, 0.6
+11 IF $PIECE(S,".",2)
SET S=$JUSTIFY(S,"",1)
+12 QUIT S
+13 ;
TDIF(SAR,SOP,FMT) ;Return time differences (seconds) beween two dates
+1 ;INPUT:
+2 ; SAR - starting date time (in any format)
+3 ; SOP - stop date time (in any format) (def is NOW)
+4 ; FMT - format of output
+5 ; 0 - number of seconds (def)
+6 ; 1 - formatted output (w/o seconds)
+7 ; 2 - formatted output (with seconds)
+8 ;OUTPUT:
+9 ; function value - time difference
+10 ; number of seconds or formatted output
+11 ;
+12 NEW TOT
+13 ;JMB 6/5/95
NEW SESAR,SESOP,DTSAR,DTSOP,SEOV,SESOPTOT,SESARTOT
+14 ;Quit if no start_date
+15 IF '$LENGTH($GET(SAR))
QUIT ""
+16 ;Set default stop_date to NOW
+17 IF '$LENGTH($GET(SOP))
SET SOP=$HOROLOG
+18 ;Convert dates to $H format
+19 SET SAR=$$CONV(SAR)
SET SOP=$$CONV(SOP)
IF 'SAR!'SOP
QUIT ""
+20 ;Get starting time and ending time
+21 SET SESAR=+$PIECE(SAR,",",2)
SET SESOP=+$PIECE(SOP,",",2)
+22 ;Get start_day and end_day
+23 SET DTSAR=+SAR
SET DTSOP=+SOP
+24 ;Initialize overflow_days_seconds and total_stop_date_seconds
+25 SET SEOV=0
SET SESOPTOT=0
+26 ;Set total_start_date_seconds
+27 SET SESARTOT=SESOP-SESAR
+28 ;If days are not the same calculate seconds for each date
+29 IF DTSAR'=DTSOP
Begin DoDot:1
+30 ;Calculate total_start_date_seconds
+31 SET SESARTOT=86400-SESAR
+32 ;Calcualte total_stop_date_seconds
+33 SET SESOPTOT=SESOP
End DoDot:1
+34 ;Check if days are more than one day apart
+35 IF (DTSOP-DTSAR-1)>0
Begin DoDot:1
+36 ;Set overlfow_seconds
+37 SET SEOV=(DTSOP-DTSAR-1)*86400
End DoDot:1
+38 ;Calculate total_seconds
+39 SET TOT=SESARTOT+SESOPTOT+SEOV
+40 ;Convert to text format
+41 IF $GET(FMT)
SET TOT=$$FORMAT(TOT,$GET(FMT))
+42 QUIT TOT
+43 ;
CONV(DATE) ;Convert to $H format
+1 ;INPUT:
+2 ; DATE - in any format
+3 ;OUTPUT:
+4 ; function value - date in $H format or null
+5 ;
+6 ;Check for $H format
+7 IF DATE?5N.1",".5N
QUIT DATE
+8 ;Check for text format
+9 IF DATE'?7N.1".".N
SET DATE=$$CDATA2F^UTDT(DATE,"TI")
+10 ;Check for Fileman internal format
+11 IF DATE?7N.1".".N
SET DATE=$$CDATF2H^UTDT(DATE)
+12 IF DATE<1
SET DATE=""
+13 QUIT DATE
+14 ;
FORMAT(T,SEC) ;Convert number of seconds to formatted time
+1 ;INPUT:
+2 ; T - number of seconds
+3 ; SEC - display seconds ( 0 - no (def) ; 2 - yes )
+4 ;OUTPUT:
+5 ; function - formatted time ( ex: 2 dy 1 hr 23 min 12 sec )
+6 ;
+7 IF '$LENGTH($GET(T))
QUIT ""
+8 IF 'T
QUIT "0 sec"
+9 NEW D,H,M,S,TX
+10 SET SEC=$SELECT($GET(SEC)>1:1,1:0)
SET TX=""
SET D=T\86400
SET H=(T#86400)\3600
SET M=(T#3600)\60
SET S=T#60
+11 IF SEC
SET TX=S_" sec "
+12 IF M!'SEC
SET TX=M_" min "_TX
+13 IF H!D
SET TX=H_" hr "_TX
+14 IF D
SET TX=D_" dy "_TX
+15 QUIT TX