ONCDTUTL ;Hines OIFO/SG - CALENDAR UTILITIES ; 9/13/06 2:35pm
;;2.2;ONCOLOGY;**1**;Jul 31, 2013;Build 8
;
; $$DIM, DTDIFF, and $$ISLEAP are M translations of functions from
; the Orpheus package (http://sourceforge.net/projects/tporpheus/).
;
; ONCDTUTL OvcDate.pas
; -------- -----------
; DTDIFF DateDiff
; $$DIM DaysInMonth
; $$ISLEAP IsLeapYear
;
Q
;
;***** DTDIFF^ONCDTUTL USAGE EXAMPLE
DEMO ;
D DEMO1(3061201,62)
D DEMO1(3061231,62)
D DEMO1(3000415,-700)
D DEMO1(3051020,0)
W !
Q
;
DEMO1(DATE1,ND) ;
N DATE2,DAYS,MONTHS,YEARS
S DATE2=$$FMADD^XLFDT(DATE1,ND)
D DTDIFF^ONCDTUTL(DATE1,DATE2,.DAYS,.MONTHS,.YEARS)
W !,$$FMTE^XLFDT(DATE1)_" - "_$$FMTE^XLFDT(DATE2)
W ?35,"Days: "_$J(DAYS,2)," Months: "_$J(MONTHS,2)," Years: "_YEARS
Q
;
;***** RETURNS NUMBER OF DAYS IN THE MONTH
;
; M Month
; Y Year
;
DIM(M,Y) ;
Q:(M=1)!(M=3)!(M=5)!(M=7)!(M=8)!(M=10)!(M=12) 31
Q:(M=4)!(M=6)!(M=9)!(M=11) 30
Q:M=2 $S($$ISLEAP(Y):29,1:28)
Q 0
;
;***** CALCULATES DIFFERENCE BETWEEN TWO DATES
;
; DATE1 First date (FileMan)
; DATE2 Second date (FileMan)
;
; .DAYS Number of days is returned via this parameter
; .MONTHS Number of months is returned via this parameter
; .YEARS Number of years is returned via this parameter
;
DTDIFF(DATE1,DATE2,DAYS,MONTHS,YEARS) ;
N DAY1,DAY2,DT1,DT2,MONTH1,MONTH2,TMP,YEAR1,YEAR2
;--- We want DATE2 > DATE1; convert to YYYY/MM/DD
I DATE1>DATE2 D
. S DT1=$$FMTE^XLFDT(DATE2,"7D")
. S DT2=$$FMTE^XLFDT(DATE1,"7D")
E D
. S DT1=$$FMTE^XLFDT(DATE1,"7D")
. S DT2=$$FMTE^XLFDT(DATE2,"7D")
;--- Convert dates to day, month, year
S YEAR1=$P(DT1,"/"),MONTH1=$P(DT1,"/",2),DAY1=$P(DT1,"/",3)
S YEAR2=$P(DT2,"/"),MONTH2=$P(DT2,"/",2),DAY2=$P(DT2,"/",3)
;--- Days first
S:DAY1=$$DIM(MONTH1,YEAR1) DAY1=0,MONTH1=MONTH1+1
S:DAY2=$$DIM(MONTH2,YEAR2) DAY2=0,MONTH2=MONTH2+1
I DAY2<DAY1 D
. S MONTH2=MONTH2-1
. S:'MONTH2 MONTH2=12,YEAR2=YEAR2-1
. S DAYS=DAY2+$$DIM(MONTH1,YEAR1)-DAY1
E S DAYS=DAY2-DAY1
;--- Now months and years
S:MONTH2<MONTH1 MONTH2=MONTH2+12,YEAR2=YEAR2-1
S MONTHS=MONTH2-MONTH1,YEARS=YEAR2-YEAR1
Q
;
;***** INDICATES LEAP YEAR
;
; YEAR Year (4 digits)
;
; Return Values:
; 0 Regular year
; 1 Leap year
;
ISLEAP(YEAR) ;
Q (YEAR#4=0)&(YEAR#4000'=0)&((YEAR#100'=0)!(YEAR#400=0))
--- Routine Detail --- with STRUCTURED ROUTINE LISTING ---[H[J[2J[HONCDTUTL 2489 printed Nov 22, 2024@17:32:51 Page 2
ONCDTUTL ;Hines OIFO/SG - CALENDAR UTILITIES ; 9/13/06 2:35pm
+1 ;;2.2;ONCOLOGY;**1**;Jul 31, 2013;Build 8
+2 ;
+3 ; $$DIM, DTDIFF, and $$ISLEAP are M translations of functions from
+4 ; the Orpheus package (http://sourceforge.net/projects/tporpheus/).
+5 ;
+6 ; ONCDTUTL OvcDate.pas
+7 ; -------- -----------
+8 ; DTDIFF DateDiff
+9 ; $$DIM DaysInMonth
+10 ; $$ISLEAP IsLeapYear
+11 ;
+12 QUIT
+13 ;
+14 ;***** DTDIFF^ONCDTUTL USAGE EXAMPLE
DEMO ;
+1 DO DEMO1(3061201,62)
+2 DO DEMO1(3061231,62)
+3 DO DEMO1(3000415,-700)
+4 DO DEMO1(3051020,0)
+5 WRITE !
+6 QUIT
+7 ;
DEMO1(DATE1,ND) ;
+1 NEW DATE2,DAYS,MONTHS,YEARS
+2 SET DATE2=$$FMADD^XLFDT(DATE1,ND)
+3 DO DTDIFF^ONCDTUTL(DATE1,DATE2,.DAYS,.MONTHS,.YEARS)
+4 WRITE !,$$FMTE^XLFDT(DATE1)_" - "_$$FMTE^XLFDT(DATE2)
+5 WRITE ?35,"Days: "_$JUSTIFY(DAYS,2)," Months: "_$JUSTIFY(MONTHS,2)," Years: "_YEARS
+6 QUIT
+7 ;
+8 ;***** RETURNS NUMBER OF DAYS IN THE MONTH
+9 ;
+10 ; M Month
+11 ; Y Year
+12 ;
DIM(M,Y) ;
+1 if (M=1)!(M=3)!(M=5)!(M=7)!(M=8)!(M=10)!(M=12)
QUIT 31
+2 if (M=4)!(M=6)!(M=9)!(M=11)
QUIT 30
+3 if M=2
QUIT $SELECT($$ISLEAP(Y):29,1:28)
+4 QUIT 0
+5 ;
+6 ;***** CALCULATES DIFFERENCE BETWEEN TWO DATES
+7 ;
+8 ; DATE1 First date (FileMan)
+9 ; DATE2 Second date (FileMan)
+10 ;
+11 ; .DAYS Number of days is returned via this parameter
+12 ; .MONTHS Number of months is returned via this parameter
+13 ; .YEARS Number of years is returned via this parameter
+14 ;
DTDIFF(DATE1,DATE2,DAYS,MONTHS,YEARS) ;
+1 NEW DAY1,DAY2,DT1,DT2,MONTH1,MONTH2,TMP,YEAR1,YEAR2
+2 ;--- We want DATE2 > DATE1; convert to YYYY/MM/DD
+3 IF DATE1>DATE2
Begin DoDot:1
+4 SET DT1=$$FMTE^XLFDT(DATE2,"7D")
+5 SET DT2=$$FMTE^XLFDT(DATE1,"7D")
End DoDot:1
+6 IF '$TEST
Begin DoDot:1
+7 SET DT1=$$FMTE^XLFDT(DATE1,"7D")
+8 SET DT2=$$FMTE^XLFDT(DATE2,"7D")
End DoDot:1
+9 ;--- Convert dates to day, month, year
+10 SET YEAR1=$PIECE(DT1,"/")
SET MONTH1=$PIECE(DT1,"/",2)
SET DAY1=$PIECE(DT1,"/",3)
+11 SET YEAR2=$PIECE(DT2,"/")
SET MONTH2=$PIECE(DT2,"/",2)
SET DAY2=$PIECE(DT2,"/",3)
+12 ;--- Days first
+13 if DAY1=$$DIM(MONTH1,YEAR1)
SET DAY1=0
SET MONTH1=MONTH1+1
+14 if DAY2=$$DIM(MONTH2,YEAR2)
SET DAY2=0
SET MONTH2=MONTH2+1
+15 IF DAY2<DAY1
Begin DoDot:1
+16 SET MONTH2=MONTH2-1
+17 if 'MONTH2
SET MONTH2=12
SET YEAR2=YEAR2-1
+18 SET DAYS=DAY2+$$DIM(MONTH1,YEAR1)-DAY1
End DoDot:1
+19 IF '$TEST
SET DAYS=DAY2-DAY1
+20 ;--- Now months and years
+21 if MONTH2<MONTH1
SET MONTH2=MONTH2+12
SET YEAR2=YEAR2-1
+22 SET MONTHS=MONTH2-MONTH1
SET YEARS=YEAR2-YEAR1
+23 QUIT
+24 ;
+25 ;***** INDICATES LEAP YEAR
+26 ;
+27 ; YEAR Year (4 digits)
+28 ;
+29 ; Return Values:
+30 ; 0 Regular year
+31 ; 1 Leap year
+32 ;
ISLEAP(YEAR) ;
+1 QUIT (YEAR#4=0)&(YEAR#4000'=0)&((YEAR#100'=0)!(YEAR#400=0))