source: FOIAVistA/tag/r/ONCOLOGY-ONC/ONCDTUTL.m@ 1424

Last change on this file since 1424 was 628, checked in by George Lilly, 15 years ago

initial load of FOIAVistA 6/30/08 version

File size: 2.3 KB
Line 
1ONCDTUTL ;Hines OIFO/SG - CALENDAR UTILITIES ; 9/13/06 2:35pm
2 ;;2.11;ONCOLOGY;**46**;Mar 07, 1995;Build 39
3 ;
4 ; $$DIM, DTDIFF, and $$ISLEAP are M translations of functions from
5 ; the Orpheus package (http://sourceforge.net/projects/tporpheus/).
6 ;
7 ; ONCDTUTL OvcDate.pas
8 ; -------- -----------
9 ; DTDIFF DateDiff
10 ; $$DIM DaysInMonth
11 ; $$ISLEAP IsLeapYear
12 ;
13 Q
14 ;
15 ;***** DTDIFF^ONCDTUTL USAGE EXAMPLE
16DEMO ;
17 D DEMO1(3061201,62)
18 D DEMO1(3061231,62)
19 D DEMO1(3000415,-700)
20 D DEMO1(3051020,0)
21 W !
22 Q
23 ;
24DEMO1(DATE1,ND) ;
25 N DATE2,DAYS,MONTHS,YEARS
26 S DATE2=$$FMADD^XLFDT(DATE1,ND)
27 D DTDIFF^ONCDTUTL(DATE1,DATE2,.DAYS,.MONTHS,.YEARS)
28 W !,$$FMTE^XLFDT(DATE1)_" - "_$$FMTE^XLFDT(DATE2)
29 W ?35,"Days: "_$J(DAYS,2)," Months: "_$J(MONTHS,2)," Years: "_YEARS
30 Q
31 ;
32 ;***** RETURNS NUMBER OF DAYS IN THE MONTH
33 ;
34 ; M Month
35 ; Y Year
36 ;
37DIM(M,Y) ;
38 Q:(M=1)!(M=3)!(M=5)!(M=7)!(M=8)!(M=10)!(M=12) 31
39 Q:(M=4)!(M=6)!(M=9)!(M=11) 30
40 Q:M=2 $S($$ISLEAP(Y):29,1:28)
41 Q 0
42 ;
43 ;***** CALCULATES DIFFERENCE BETWEEN TWO DATES
44 ;
45 ; DATE1 First date (FileMan)
46 ; DATE2 Second date (FileMan)
47 ;
48 ; .DAYS Number of days is returned via this parameter
49 ; .MONTHS Number of months is returned via this parameter
50 ; .YEARS Number of years is returned via this parameter
51 ;
52DTDIFF(DATE1,DATE2,DAYS,MONTHS,YEARS) ;
53 N DAY1,DAY2,DT1,DT2,MONTH1,MONTH2,TMP,YEAR1,YEAR2
54 ;--- We want DATE2 > DATE1; convert to YYYY/MM/DD
55 I DATE1>DATE2 D
56 . S DT1=$$FMTE^XLFDT(DATE2,"7D")
57 . S DT2=$$FMTE^XLFDT(DATE1,"7D")
58 E D
59 . S DT1=$$FMTE^XLFDT(DATE1,"7D")
60 . S DT2=$$FMTE^XLFDT(DATE2,"7D")
61 ;--- Convert dates to day, month, year
62 S YEAR1=$P(DT1,"/"),MONTH1=$P(DT1,"/",2),DAY1=$P(DT1,"/",3)
63 S YEAR2=$P(DT2,"/"),MONTH2=$P(DT2,"/",2),DAY2=$P(DT2,"/",3)
64 ;--- Days first
65 S:DAY1=$$DIM(MONTH1,YEAR1) DAY1=0,MONTH1=MONTH1+1
66 S:DAY2=$$DIM(MONTH2,YEAR2) DAY2=0,MONTH2=MONTH2+1
67 I DAY2<DAY1 D
68 . S MONTH2=MONTH2-1
69 . S:'MONTH2 MONTH2=12,YEAR2=YEAR2-1
70 . S DAYS=DAY2+$$DIM(MONTH1,YEAR1)-DAY1
71 E S DAYS=DAY2-DAY1
72 ;--- Now months and years
73 S:MONTH2<MONTH1 MONTH2=MONTH2+12,YEAR2=YEAR2-1
74 S MONTHS=MONTH2-MONTH1,YEARS=YEAR2-YEAR1
75 Q
76 ;
77 ;***** INDICATES LEAP YEAR
78 ;
79 ; YEAR Year (4 digits)
80 ;
81 ; Return Values:
82 ; 0 Regular year
83 ; 1 Leap year
84 ;
85ISLEAP(YEAR) ;
86 Q (YEAR#4=0)&(YEAR#4000'=0)&((YEAR#100'=0)!(YEAR#400=0))
Note: See TracBrowser for help on using the repository browser.