MAGUTL03 ;WOIFO/SG - DATE/TIME UTILITIES ; 3/9/09 12:53pm
;;3.0;IMAGING;**93**;Dec 02, 2009;Build 163
;; Per VHA Directive 2004-038, this routine should not be modified.
;; +---------------------------------------------------------------+
;; | Property of the US Government. |
;; | No permission to copy or redistribute this software is given. |
;; | Use of unreleased versions of this software requires the user |
;; | to execute a written test agreement with the VistA Imaging |
;; | Development Office of the Department of Veterans Affairs, |
;; | telephone (301) 734-0100. |
;; | |
;; | The Food and Drug Administration classifies this software as |
;; | a medical device. As such, it may not be changed in any way. |
;; | Modifications to this software may result in an adulterated |
;; | medical device under 21CFR820, the use of which is considered |
;; | to be a violation of US Federal Statutes. |
;; +---------------------------------------------------------------+
;;
;
; This routine uses the following ICRs:
;
; #10038 Read file #40.5 (supported)
;
Q
;
;##### ENSURES THAT THE DATE/TIME IS IN INTERNAL FORMAT
;
; X Date/time in internal (FileMan) or external format
;
; [%DT] Flags for the ^%DT (see the FileMan Programmer
; manual for details)
;
; Return Values
; =============
; -1 Invalid date
; >0 Date/time in internal FileMan format
;
DTI(X,%DT) ;
N Y
Q:X?7N.1(1"."1.N) X
S %DT=$TR($G(%DT),"AE") D ^%DT
Q Y
;
;##### "NORMALIZES" THE DATE RANGE
;
; .FROMDATE( Reference to a local variable that stores the
; beginning date of the date range. The time part of
; the value is ignored.
;
; After a successful call, this variable contains
; the internal FileMan value of the date. In case of
; error(s), the input value is returned.
;
; 0) Standard external date value is returned here.
; In case of error(s), this node is not defined.
;
; .TODATE( Reference to a local variable that stores the
; end date of the date range. The time part of
; the value is ignored.
;
; After a successful call, this variable contains
; the internal FileMan value of the date. In case of
; error(s), the input value is returned.
;
; 0) Standard external date value is returned here.
; In case of error(s), this node is not defined.
;
; Return Values
; =============
; <0 Error descriptor (see the $$ERROR^MAGUERR)
; 0 Success
;
; Notes
; =====
;
; If the FROMDATE is after the TODATE, then the dates are swapped.
;
DTRANGE(FROMDATE,TODATE) ;
N RC,TMP
;
;=== Validate the dates
S RC=0 D I RC<0 K FROMDATE(0),TODATE(0) Q RC
. ;--- Beginning of the date range
. I $G(FROMDATE)'="" D Q:RC<0
. . S TMP=$$DTI(FROMDATE,"TS")
. . I TMP<0 S RC=$$IPVE^MAGUERR("FROMDATE") Q
. . S FROMDATE=TMP\1,FROMDATE(0)=$$FMTE^XLFDT(FROMDATE)
. . Q
. E S FROMDATE=0,FROMDATE(0)=""
. ;--- End of the date range
. I $G(TODATE)'="" D Q:RC<0
. . S TMP=$$DTI(TODATE,"TS")
. . I TMP<0 S RC=$$IPVE^MAGUERR("TODATE") Q
. . S TODATE=TMP\1,TODATE(0)=$$FMTE^XLFDT(TODATE)
. . Q
. E S TODATE=9999999,TODATE(0)=""
. Q
;
;=== Swap the dates if necessary
K TMP
M:FROMDATE>TODATE TMP=FROMDATE,FROMDATE=TODATE,TODATE=TMP
;
;=== Success
Q 0
;
;##### CHECKS IF THE DATE IS A WORKING DAY
;
; DATE The date to be checked
;
; Return Values
; =============
; 0 Weekend or Holiday
; 1 Working day
;
WDCHK(DATE) ;
N DOW,MAGMSG
;--- Return zero if Saturday (6) or Sunday (0)
S DOW=$$DOW^XLFDT(DATE,1)
Q:DOW<0 $$IPVE^MAGUERR("DATE")
Q:'DOW!(DOW>5) 0
;--- Return 1 if cannot be found in the HOLIDAY file
Q $$FIND1^DIC(40.5,,"QX",DATE\1,"B",,"MAGMSG")'>0
;
;##### RETURNS THE NEXT WORKING DAY DATE
;
; DATE The source date
;
; The function returns the date of the next working day.
;
WDNEXT(DATE) ;
N DOW,MAGMSG
F D Q:$$FIND1^DIC(40.5,,"QX",DATE,"B",,"MAGMSG")'>0
. S DOW=$$DOW^XLFDT(DATE,1) S:'DOW DOW=7
. ;--- Get the next day and skip a weekend if necessary
. S DATE=$$FMADD^XLFDT(DATE,$S(DOW<5:1,1:8-DOW))
. Q
Q DATE
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HMAGUTL03 4634 printed Oct 16, 2024@18:09:46 Page 2
MAGUTL03 ;WOIFO/SG - DATE/TIME UTILITIES ; 3/9/09 12:53pm
+1 ;;3.0;IMAGING;**93**;Dec 02, 2009;Build 163
+2 ;; Per VHA Directive 2004-038, this routine should not be modified.
+3 ;; +---------------------------------------------------------------+
+4 ;; | Property of the US Government. |
+5 ;; | No permission to copy or redistribute this software is given. |
+6 ;; | Use of unreleased versions of this software requires the user |
+7 ;; | to execute a written test agreement with the VistA Imaging |
+8 ;; | Development Office of the Department of Veterans Affairs, |
+9 ;; | telephone (301) 734-0100. |
+10 ;; | |
+11 ;; | The Food and Drug Administration classifies this software as |
+12 ;; | a medical device. As such, it may not be changed in any way. |
+13 ;; | Modifications to this software may result in an adulterated |
+14 ;; | medical device under 21CFR820, the use of which is considered |
+15 ;; | to be a violation of US Federal Statutes. |
+16 ;; +---------------------------------------------------------------+
+17 ;;
+18 ;
+19 ; This routine uses the following ICRs:
+20 ;
+21 ; #10038 Read file #40.5 (supported)
+22 ;
+23 QUIT
+24 ;
+25 ;##### ENSURES THAT THE DATE/TIME IS IN INTERNAL FORMAT
+26 ;
+27 ; X Date/time in internal (FileMan) or external format
+28 ;
+29 ; [%DT] Flags for the ^%DT (see the FileMan Programmer
+30 ; manual for details)
+31 ;
+32 ; Return Values
+33 ; =============
+34 ; -1 Invalid date
+35 ; >0 Date/time in internal FileMan format
+36 ;
DTI(X,%DT) ;
+1 NEW Y
+2 if X?7N.1(1"."1.N)
QUIT X
+3 SET %DT=$TRANSLATE($GET(%DT),"AE")
DO ^%DT
+4 QUIT Y
+5 ;
+6 ;##### "NORMALIZES" THE DATE RANGE
+7 ;
+8 ; .FROMDATE( Reference to a local variable that stores the
+9 ; beginning date of the date range. The time part of
+10 ; the value is ignored.
+11 ;
+12 ; After a successful call, this variable contains
+13 ; the internal FileMan value of the date. In case of
+14 ; error(s), the input value is returned.
+15 ;
+16 ; 0) Standard external date value is returned here.
+17 ; In case of error(s), this node is not defined.
+18 ;
+19 ; .TODATE( Reference to a local variable that stores the
+20 ; end date of the date range. The time part of
+21 ; the value is ignored.
+22 ;
+23 ; After a successful call, this variable contains
+24 ; the internal FileMan value of the date. In case of
+25 ; error(s), the input value is returned.
+26 ;
+27 ; 0) Standard external date value is returned here.
+28 ; In case of error(s), this node is not defined.
+29 ;
+30 ; Return Values
+31 ; =============
+32 ; <0 Error descriptor (see the $$ERROR^MAGUERR)
+33 ; 0 Success
+34 ;
+35 ; Notes
+36 ; =====
+37 ;
+38 ; If the FROMDATE is after the TODATE, then the dates are swapped.
+39 ;
DTRANGE(FROMDATE,TODATE) ;
+1 NEW RC,TMP
+2 ;
+3 ;=== Validate the dates
+4 SET RC=0
Begin DoDot:1
+5 ;--- Beginning of the date range
+6 IF $GET(FROMDATE)'=""
Begin DoDot:2
+7 SET TMP=$$DTI(FROMDATE,"TS")
+8 IF TMP<0
SET RC=$$IPVE^MAGUERR("FROMDATE")
QUIT
+9 SET FROMDATE=TMP\1
SET FROMDATE(0)=$$FMTE^XLFDT(FROMDATE)
+10 QUIT
End DoDot:2
if RC<0
QUIT
+11 IF '$TEST
SET FROMDATE=0
SET FROMDATE(0)=""
+12 ;--- End of the date range
+13 IF $GET(TODATE)'=""
Begin DoDot:2
+14 SET TMP=$$DTI(TODATE,"TS")
+15 IF TMP<0
SET RC=$$IPVE^MAGUERR("TODATE")
QUIT
+16 SET TODATE=TMP\1
SET TODATE(0)=$$FMTE^XLFDT(TODATE)
+17 QUIT
End DoDot:2
if RC<0
QUIT
+18 IF '$TEST
SET TODATE=9999999
SET TODATE(0)=""
+19 QUIT
End DoDot:1
IF RC<0
KILL FROMDATE(0),TODATE(0)
QUIT RC
+20 ;
+21 ;=== Swap the dates if necessary
+22 KILL TMP
+23 if FROMDATE>TODATE
MERGE TMP=FROMDATE,FROMDATE=TODATE,TODATE=TMP
+24 ;
+25 ;=== Success
+26 QUIT 0
+27 ;
+28 ;##### CHECKS IF THE DATE IS A WORKING DAY
+29 ;
+30 ; DATE The date to be checked
+31 ;
+32 ; Return Values
+33 ; =============
+34 ; 0 Weekend or Holiday
+35 ; 1 Working day
+36 ;
WDCHK(DATE) ;
+1 NEW DOW,MAGMSG
+2 ;--- Return zero if Saturday (6) or Sunday (0)
+3 SET DOW=$$DOW^XLFDT(DATE,1)
+4 if DOW<0
QUIT $$IPVE^MAGUERR("DATE")
+5 if 'DOW!(DOW>5)
QUIT 0
+6 ;--- Return 1 if cannot be found in the HOLIDAY file
+7 QUIT $$FIND1^DIC(40.5,,"QX",DATE\1,"B",,"MAGMSG")'>0
+8 ;
+9 ;##### RETURNS THE NEXT WORKING DAY DATE
+10 ;
+11 ; DATE The source date
+12 ;
+13 ; The function returns the date of the next working day.
+14 ;
WDNEXT(DATE) ;
+1 NEW DOW,MAGMSG
+2 FOR
Begin DoDot:1
+3 SET DOW=$$DOW^XLFDT(DATE,1)
if 'DOW
SET DOW=7
+4 ;--- Get the next day and skip a weekend if necessary
+5 SET DATE=$$FMADD^XLFDT(DATE,$SELECT(DOW<5:1,1:8-DOW))
+6 QUIT
End DoDot:1
if $$FIND1^DIC(40.5,,"QX",DATE,"B",,"MAGMSG")'>0
QUIT
+7 QUIT DATE