FSCTIME ;SLC/STAFF-NOIS Time Conversion ;1/11/98 18:53
;;1.1;NOIS;;Sep 06, 1998
TIME(X) ; from dd7103, dd7103.1, dd7103.2, dd7105.2
; format X else kill it
N OK,X1
I X?1"12".A S X=$S(X="12M":"MID",X="12N":"NOON",1:X)
I X?1.A S X=$S(X["MID":2400,X["NOON":1200,1:"")
I $E(X,$L(X))="M" S X=$E(X,1,$L(X)-1)
S X1=$E(X,$L(X)) I X1?1U,"AP"'[X1 K X Q
S X1=$P(X,":",2)
I X1'="",X1'?2N1.2U K X Q
I X'?4N,$S($L(+X)<3:+X,1:+X\100)>12 K X Q
S X=$P(X,":",1)_$P(X,":",2),X1=X
I X'?4N S OK=1 D I 'OK K X Q
.I X'?1.4N1.2U S OK=0
.S:X<13 X=X*100 I X1["A" S:X>1259 OK=0 Q:'OK S X=$S(X=1200:2400,X>1159:X-1200,1:X)
.I X1'["A",X<1200,X1["P"!(X<600) S X=X+1200 I X<1300 S OK=0
I X>2400!('X&(X'="0000"))!(X#100>59) K X Q
S X1=+X I 'X1!(X1=1200)!(X1=2400) S X=$S(X1=1200:"NOON",1:"MID") Q
S X1=$S(X1>1259:X1-1200,1:X1),X1=$E("000",0,4-$L(X1))_X1_$S(X=2400:"A",X>1159:"P",1:"A")
I "00^15^30^45"'[$E(X1,3,4) K X Q
S X=$E(X1,1,2)_":"_$E(X1,3,5)
Q
;
CNV ; Convert Start/Stop to minutes
; X=start_"^"_stop Output: Y=start(min)_"^"_stop(min)
S CNX=X,X=$P(CNX,"^",1),Y=0 D MIL S Y=Y\100*60+(Y#100),$P(CNX,"^",1)=Y
S X=$P(CNX,"^",2),Y=1 D MIL S Y=Y\100*60+(Y#100)
S Y=$P(CNX,"^",1)_"^"_Y K CNX Q
;
MIL(X) ; $$(AM/PM time) -> military time
; X=time Y: 0=Mid=0,1=Mid=2400 Output: Y=time in 2400
N Y
I X="NOON" Q "1200"
I X="MID" Q "2400"
S Y=$P(X,":",1)_$P(X,":",2),Y=+Y
I X["A" Q Y
I Y<1200 S Y=Y+1200
Q Y
;
CONVERT(TIME,FROMZONE,TOZONE) ; $$(time,from timezone,to timezone) -> time
N TOFFSET,FOFFSET,DIFF
I '$L(TIME)!('$L(FROMZONE))!('$L(TOZONE)) Q TIME
S TOFFSET=$P($G(^FSC("TIMEZONE",+$O(^FSC("TIMEZONE","B",TOZONE,0)),0)),U,2)
S FOFFSET=$P($G(^FSC("TIMEZONE",+$O(^FSC("TIMEZONE","B",FROMZONE,0)),0)),U,2)
I 'TOFFSET Q TIME
I 'FOFFSET Q TIME
S DIFF=FOFFSET-TOFFSET
S TIME=TIME-(DIFF*100)
I $L(TIME)=3 S TIME="0"_TIME
Q TIME
;
HLP ; Time Help
W !?5,"Time may be entered as 8A or 8a, 8:00A, 8:15A, 8:15AM or military"
W !?5,"time: 0800, 1300; or MID or 12M for midnight; NOON or 12N for noon."
W !?5,"Time must be in quarter hours; e.g., 8A or 8:15A or 8:30A or 8:45A.",!
Q
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HFSCTIME 2154 printed Dec 13, 2024@02:20:20 Page 2
FSCTIME ;SLC/STAFF-NOIS Time Conversion ;1/11/98 18:53
+1 ;;1.1;NOIS;;Sep 06, 1998
TIME(X) ; from dd7103, dd7103.1, dd7103.2, dd7105.2
+1 ; format X else kill it
+2 NEW OK,X1
+3 IF X?1"12".A
SET X=$SELECT(X="12M":"MID",X="12N":"NOON",1:X)
+4 IF X?1.A
SET X=$SELECT(X["MID":2400,X["NOON":1200,1:"")
+5 IF $EXTRACT(X,$LENGTH(X))="M"
SET X=$EXTRACT(X,1,$LENGTH(X)-1)
+6 SET X1=$EXTRACT(X,$LENGTH(X))
IF X1?1U
IF "AP"'[X1
KILL X
QUIT
+7 SET X1=$PIECE(X,":",2)
+8 IF X1'=""
IF X1'?2N1.2U
KILL X
QUIT
+9 IF X'?4N
IF $SELECT($LENGTH(+X)<3:+X,1:+X\100)>12
KILL X
QUIT
+10 SET X=$PIECE(X,":",1)_$PIECE(X,":",2)
SET X1=X
+11 IF X'?4N
SET OK=1
Begin DoDot:1
+12 IF X'?1.4N1.2U
SET OK=0
+13 if X<13
SET X=X*100
IF X1["A"
if X>1259
SET OK=0
if 'OK
QUIT
SET X=$SELECT(X=1200:2400,X>1159:X-1200,1:X)
+14 IF X1'["A"
IF X<1200
IF X1["P"!(X<600)
SET X=X+1200
IF X<1300
SET OK=0
End DoDot:1
IF 'OK
KILL X
QUIT
+15 IF X>2400!('X&(X'="0000"))!(X#100>59)
KILL X
QUIT
+16 SET X1=+X
IF 'X1!(X1=1200)!(X1=2400)
SET X=$SELECT(X1=1200:"NOON",1:"MID")
QUIT
+17 SET X1=$SELECT(X1>1259:X1-1200,1:X1)
SET X1=$EXTRACT("000",0,4-$LENGTH(X1))_X1_$SELECT(X=2400:"A",X>1159:"P",1:"A")
+18 IF "00^15^30^45"'[$EXTRACT(X1,3,4)
KILL X
QUIT
+19 SET X=$EXTRACT(X1,1,2)_":"_$EXTRACT(X1,3,5)
+20 QUIT
+21 ;
CNV ; Convert Start/Stop to minutes
+1 ; X=start_"^"_stop Output: Y=start(min)_"^"_stop(min)
+2 SET CNX=X
SET X=$PIECE(CNX,"^",1)
SET Y=0
DO MIL
SET Y=Y\100*60+(Y#100)
SET $PIECE(CNX,"^",1)=Y
+3 SET X=$PIECE(CNX,"^",2)
SET Y=1
DO MIL
SET Y=Y\100*60+(Y#100)
+4 SET Y=$PIECE(CNX,"^",1)_"^"_Y
KILL CNX
QUIT
+5 ;
MIL(X) ; $$(AM/PM time) -> military time
+1 ; X=time Y: 0=Mid=0,1=Mid=2400 Output: Y=time in 2400
+2 NEW Y
+3 IF X="NOON"
QUIT "1200"
+4 IF X="MID"
QUIT "2400"
+5 SET Y=$PIECE(X,":",1)_$PIECE(X,":",2)
SET Y=+Y
+6 IF X["A"
QUIT Y
+7 IF Y<1200
SET Y=Y+1200
+8 QUIT Y
+9 ;
CONVERT(TIME,FROMZONE,TOZONE) ; $$(time,from timezone,to timezone) -> time
+1 NEW TOFFSET,FOFFSET,DIFF
+2 IF '$LENGTH(TIME)!('$LENGTH(FROMZONE))!('$LENGTH(TOZONE))
QUIT TIME
+3 SET TOFFSET=$PIECE($GET(^FSC("TIMEZONE",+$ORDER(^FSC("TIMEZONE","B",TOZONE,0)),0)),U,2)
+4 SET FOFFSET=$PIECE($GET(^FSC("TIMEZONE",+$ORDER(^FSC("TIMEZONE","B",FROMZONE,0)),0)),U,2)
+5 IF 'TOFFSET
QUIT TIME
+6 IF 'FOFFSET
QUIT TIME
+7 SET DIFF=FOFFSET-TOFFSET
+8 SET TIME=TIME-(DIFF*100)
+9 IF $LENGTH(TIME)=3
SET TIME="0"_TIME
+10 QUIT TIME
+11 ;
HLP ; Time Help
+1 WRITE !?5,"Time may be entered as 8A or 8a, 8:00A, 8:15A, 8:15AM or military"
+2 WRITE !?5,"time: 0800, 1300; or MID or 12M for midnight; NOON or 12N for noon."
+3 WRITE !?5,"Time must be in quarter hours; e.g., 8A or 8:15A or 8:30A or 8:45A.",!
+4 QUIT