SDECDATE ; ALB/WTC,TAW,LAB - VISTA SCHEDULING - Date Utilities ;APR 07,2022
;;5.3;Scheduling;**694,805,814**;;Build 11
;;Per VHA Directive 2004-038, this routine should not be modified
;
Q ;
;
FMTONET(IN,SPACE) ;
;
; Convert FileMan format date/time to .NET compatible date
;
; IN = FileMan format date
; SPACE = Y if @ should be converted to a space
;
N OUT,X,Y,X1 ;
;
; If time is midnight, increment date by one and change time to "0000"
;
I $P(IN,".",2)="24" D G RETURN ;
. S X=$P(IN,".",1),X1=$$FMADD^DILIBF(X,1,0,0,1),X1=$P(X1,".",1) ;
. S OUT=$$FMTE^DILIBF(X1)_"@00:00" ;
;
; Other than midnight.
;
S OUT=$$FMTE^DILIBF(IN) ;
;
I $G(SPACE)="Y" S OUT=$TR(OUT,"@"," ") ;
;
RETURN ;
Q OUT ;
;
NETTOFM(IN,TIME,SECONDS) ;
;
; Convert .NET date/time to FileMan format.
;
; IN = date/time in external format
; TIME = time required (Y/N default=Y)
; SECONDS = seconds permitted (Y/N default=Y)
;
N OUT,X,Y,X1,TM ;
;
; If time is midnight, decrement date by one and change time to 24.
;
S TM=$P(IN,"@",2) ; May need to add additional checks for correct time depending on how .NET returns date/time.
;
S %DT="" ;
I $G(TIME)'="N" S %DT=%DT_"R" ;
I $G(TIME)'="N",$G(SECONDS)'="N" S %DT=%DT_"S" ;
;
I TM="00:00"!(TM="0000") D G RETURN ;
. S X=$P(IN,"@",1),%DT="" D ^%DT S X=$$FMADD^DILIBF(Y,-1,0,0,1),X1=$P(X,".",1) ;
. S OUT=X1_".24" ;
;
; Other than midnight
;
S X=IN D ^%DT S OUT=Y G RETURN
;
VALIDFMFORMAT(DATE) ;Is DATE a valind FileMan format
;Return 1=Yes
; 0=No
N X,Y,%DT
S %DT="T"
I $G(DATE)="" Q 0
I $$FR^XLFDT(DATE) Q 0
S X=DATE D ^%DT
I Y=-1 Q 0
Q 1
;
VALIDISO(DATE) ;Is DATE a valid ISO8601 format (e.g., 2022-01-12T13:21)
; Return
; 0 = not ISO8601 format
; 1 = ISO8601 format
N RESULT,SDDATE,SDTIME,SDOFFSET,KEEPSDTIME
S (RESULT)=0
I $G(DATE)="" Q 0
S SDDATE=$P(DATE,"T")
I SDDATE D
.;Validate date
.; YYYYMMDD, YYYY-MM-DD or YYYY-MM
.I SDDATE?6N Q ;YYYY-MM is not allowed
.S SDDATE=$TR(SDDATE,"-")
.I SDDATE?8N!(SDDATE?6N) S RESULT=1
;
S (SDTIME,KEEPSDTIME)=$P(DATE,"T",2)
I RESULT,SDTIME'="" D
.;Validate time (ignore seconds)
.; THH
.; THHMM or THH:MM
.; THHMMSS or THH:MM:SS
.S SDTIME=$$REMOVEOFFSET^SDAMUTDT(SDTIME)
.S SDTIME=$P(SDTIME,".") ;Ignore seconds
.S SDTIME=$TR(SDTIME,":")
.I SDTIME'?6N,SDTIME'?4N,SDTIME'?2N S RESULT=0 Q
.;Validate offset
.; Z
.; + or - followed by HH
.; + or - followed by HHMM or HH:MM
.I $E(DATE,$L(DATE))="Z" S RESULT=1 Q
.S SDTIME=$TR(KEEPSDTIME,":")
.S SDOFFSET=$P(SDTIME,"+",2)
.I SDOFFSET'="" D Q
..I SDOFFSET'?2N,SDOFFSET'?4N S RESULT=0
.S SDOFFSET=$P(SDTIME,"-",2)
.I SDOFFSET'="" D Q
..I SDOFFSET'?2N,SDOFFSET'?4N S RESULT=0
Q RESULT
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HSDECDATE 2831 printed Dec 13, 2024@02:51:53 Page 2
SDECDATE ; ALB/WTC,TAW,LAB - VISTA SCHEDULING - Date Utilities ;APR 07,2022
+1 ;;5.3;Scheduling;**694,805,814**;;Build 11
+2 ;;Per VHA Directive 2004-038, this routine should not be modified
+3 ;
+4 ;
QUIT
+5 ;
FMTONET(IN,SPACE) ;
+1 ;
+2 ; Convert FileMan format date/time to .NET compatible date
+3 ;
+4 ; IN = FileMan format date
+5 ; SPACE = Y if @ should be converted to a space
+6 ;
+7 ;
NEW OUT,X,Y,X1
+8 ;
+9 ; If time is midnight, increment date by one and change time to "0000"
+10 ;
+11 ;
IF $PIECE(IN,".",2)="24"
Begin DoDot:1
+12 ;
SET X=$PIECE(IN,".",1)
SET X1=$$FMADD^DILIBF(X,1,0,0,1)
SET X1=$PIECE(X1,".",1)
+13 ;
SET OUT=$$FMTE^DILIBF(X1)_"@00:00"
End DoDot:1
GOTO RETURN
+14 ;
+15 ; Other than midnight.
+16 ;
+17 ;
SET OUT=$$FMTE^DILIBF(IN)
+18 ;
+19 ;
IF $GET(SPACE)="Y"
SET OUT=$TRANSLATE(OUT,"@"," ")
+20 ;
RETURN ;
+1 ;
QUIT OUT
+2 ;
NETTOFM(IN,TIME,SECONDS) ;
+1 ;
+2 ; Convert .NET date/time to FileMan format.
+3 ;
+4 ; IN = date/time in external format
+5 ; TIME = time required (Y/N default=Y)
+6 ; SECONDS = seconds permitted (Y/N default=Y)
+7 ;
+8 ;
NEW OUT,X,Y,X1,TM
+9 ;
+10 ; If time is midnight, decrement date by one and change time to 24.
+11 ;
+12 ; May need to add additional checks for correct time depending on how .NET returns date/time.
SET TM=$PIECE(IN,"@",2)
+13 ;
+14 ;
SET %DT=""
+15 ;
IF $GET(TIME)'="N"
SET %DT=%DT_"R"
+16 ;
IF $GET(TIME)'="N"
IF $GET(SECONDS)'="N"
SET %DT=%DT_"S"
+17 ;
+18 ;
IF TM="00:00"!(TM="0000")
Begin DoDot:1
+19 ;
SET X=$PIECE(IN,"@",1)
SET %DT=""
DO ^%DT
SET X=$$FMADD^DILIBF(Y,-1,0,0,1)
SET X1=$PIECE(X,".",1)
+20 ;
SET OUT=X1_".24"
End DoDot:1
GOTO RETURN
+21 ;
+22 ; Other than midnight
+23 ;
+24 SET X=IN
DO ^%DT
SET OUT=Y
GOTO RETURN
+25 ;
VALIDFMFORMAT(DATE) ;Is DATE a valind FileMan format
+1 ;Return 1=Yes
+2 ; 0=No
+3 NEW X,Y,%DT
+4 SET %DT="T"
+5 IF $GET(DATE)=""
QUIT 0
+6 IF $$FR^XLFDT(DATE)
QUIT 0
+7 SET X=DATE
DO ^%DT
+8 IF Y=-1
QUIT 0
+9 QUIT 1
+10 ;
VALIDISO(DATE) ;Is DATE a valid ISO8601 format (e.g., 2022-01-12T13:21)
+1 ; Return
+2 ; 0 = not ISO8601 format
+3 ; 1 = ISO8601 format
+4 NEW RESULT,SDDATE,SDTIME,SDOFFSET,KEEPSDTIME
+5 SET (RESULT)=0
+6 IF $GET(DATE)=""
QUIT 0
+7 SET SDDATE=$PIECE(DATE,"T")
+8 IF SDDATE
Begin DoDot:1
+9 ;Validate date
+10 ; YYYYMMDD, YYYY-MM-DD or YYYY-MM
+11 ;YYYY-MM is not allowed
IF SDDATE?6N
QUIT
+12 SET SDDATE=$TRANSLATE(SDDATE,"-")
+13 IF SDDATE?8N!(SDDATE?6N)
SET RESULT=1
End DoDot:1
+14 ;
+15 SET (SDTIME,KEEPSDTIME)=$PIECE(DATE,"T",2)
+16 IF RESULT
IF SDTIME'=""
Begin DoDot:1
+17 ;Validate time (ignore seconds)
+18 ; THH
+19 ; THHMM or THH:MM
+20 ; THHMMSS or THH:MM:SS
+21 SET SDTIME=$$REMOVEOFFSET^SDAMUTDT(SDTIME)
+22 ;Ignore seconds
SET SDTIME=$PIECE(SDTIME,".")
+23 SET SDTIME=$TRANSLATE(SDTIME,":")
+24 IF SDTIME'?6N
IF SDTIME'?4N
IF SDTIME'?2N
SET RESULT=0
QUIT
+25 ;Validate offset
+26 ; Z
+27 ; + or - followed by HH
+28 ; + or - followed by HHMM or HH:MM
+29 IF $EXTRACT(DATE,$LENGTH(DATE))="Z"
SET RESULT=1
QUIT
+30 SET SDTIME=$TRANSLATE(KEEPSDTIME,":")
+31 SET SDOFFSET=$PIECE(SDTIME,"+",2)
+32 IF SDOFFSET'=""
Begin DoDot:2
+33 IF SDOFFSET'?2N
IF SDOFFSET'?4N
SET RESULT=0
End DoDot:2
QUIT
+34 SET SDOFFSET=$PIECE(SDTIME,"-",2)
+35 IF SDOFFSET'=""
Begin DoDot:2
+36 IF SDOFFSET'?2N
IF SDOFFSET'?4N
SET RESULT=0
End DoDot:2
QUIT
End DoDot:1
+37 QUIT RESULT