Home   Package List   Routine Alphabetical List   Global Alphabetical List   FileMan Files List   FileMan Sub-Files List   Package Component Lists   Package-Namespace Mapping  
Routine: INHUTS

INHUTS.m

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