Difference between revisions of "ROUTINE %DT"

From VistApedia
Jump to: navigation, search
(Created page with " As most of us know, the VA KERNEL has a program %DT which originally came from VA FileMan, which David Whitten assumes was originally written by George Timson. In that code...")
 
Line 4: Line 4:
 
  I %I(2)>28,$E("303232332323",%I(1))+28<%I(2),%I(1)-2!(%I(2)-29)!(%I(3)#4)!('(%I(3)#100)&(%I(3)+1700#400)) G 1  
 
  I %I(2)>28,$E("303232332323",%I(1))+28<%I(2),%I(1)-2!(%I(2)-29)!(%I(3)#4)!('(%I(3)#100)&(%I(3)+1700#400)) G 1  
  
  basically, the local variable  % has subscripts for the various parts of the date being validated.
+
  The local variable % is an array that has the input to this routine.
 +
% has subscripts for the various parts of the date being validated.
 
  %(1) has the {number entered for the month}
 
  %(1) has the {number entered for the month}
 
  %(2) has the {number entered for the day in the month}
 
  %(2) has the {number entered for the day in the month}

Revision as of 15:13, 9 December 2019

As most of us know, the VA KERNEL has a program %DT which originally came from VA FileMan, which David Whitten assumes was originally written by George Timson.
In that code, there is a line that validates the number of days entered versus the maximum number of daysper month.  The code looks like this:
I %I(2)>28,$E("303232332323",%I(1))+28<%I(2),%I(1)-2!(%I(2)-29)!(%I(3)#4)!('(%I(3)#100)&(%I(3)+1700#400)) G 1 
The local variable % is an array that has the input to this routine.
% has subscripts for the various parts of the date being validated.
%(1) has the {number entered for the month}
%(2) has the {number entered for the day in the month}
%(3) has the {year entered for the date}.
Expanded, this means
IF {the number entered for the day in the month} is greater than 28
AND
TEST
SELECT { the number entered for the month}VALUES
CASE 1 : RETURN (3) ;;January
CASE 2 : RETURN (0) ;;February
CASE 3 : RETURN (3) ;;March
CASE 4 : RETURN (1) ;;April
CASE 5 : RETURN (3) ;;May
CASE 6 : RETURN (2) ;;June
CASE 7 : RETURN (3) ;;July
CASE 8 : RETURN (3) ;;August
CASE 9 : RETURN (2) ;;September
CASE 10 : RETURN (3) ;;October
CASE 11 : RETURN (2) ;;November
CASE 12 : RETURN (3) ;;December
DEFAULT : RETURN (0) ;; invalid month number
END SELECT
ADD SELECT RETURN TO 28 THEN COMPARE LESS THAN {number entered for the day in the month}
AND
TEST {number entered for the month} NUMERICALLY NOT EQUAL TO 2  ;;February
OR {number entered for the day in the month} NUMERICALLY NOT EQUAL TO 29
OR TEST
BOTH
{year entered for the date} MODULO 4  ;; true if 1,2,3
AND
{year entered for the date} MODULO 100 NUMERICALLY EQUALS 0
AND ADD {year entered for the date} TO 1700 THEN MODULO 400 NUMERICALLY NOT EQUALS 0)
GOTO 1 ;; because local variable % is an acceptable date