15800 !******************************************************************* & ! & ! FNDVAL.B2S - Date Validation & ! & !******************************************************************* & ! & ! FN.VALID.DATE% (DD.MMM.YY$) & ! & ! Test for validity of a date in DEC Standard Format & ! (DD-MMM-YY). Returns true if valid, false if not. & ! Also "fills out" an incomplete date (before validation) & ! and returns the result in the variable VALID.DATE$ & ! & ! V A R I A B L E S U S E D & ! & ! NAME DESCRIPTION & ! ----------------- ------------------------------- & ! DD.MMM.YY$ Input date & ! DD$ Day & ! MMM$ Month abbreviation & ! YY$ Year & ! MM% Integer month (1-12) & ! DAY.LIM% Number of allowable days in month & ! VALID% Local validity flag & ! TODAY$ Today's date & ! THIS.MMM$ The current month & ! THIS.YY$ The current year & ! VALID.DATE$ Edited output date (if & ! FN.VALID.DATE% is TRUE) & ! FN.VALID.DATE% Logical output of function & ! TRUE if input is a valid date & ! & ! FN.DATE$ (0%) function to return today's date in & ! DD-MMM-YY format & !******************************************************************* & & 15810 DEF FN.VALID.DATE% (DD.MMM.YY$) & \ ON ERROR GO TO 15890 & \ VALID% = FALSE% & \ VALID.DATE$ = "" & \ TODAY$ = FN.DATE$(0%) & \ THIS.MMM$ = EDIT$ (SEG$(TODAY$,4%,6%),32%) & \ THIS.YY$ = SEG$ (TODAY$,8%,LEN(TODAY$)) & & \ DD.MMM.YY$ = EDIT$ (DD.MMM.YY$, 4%+8%+32%+128%) & \ DD.MMM.YY$ = "0" + DD.MMM.YY$ IF LEN(DD.MMM.YY$) = 1% & \ DD.MMM.YY$ = "0" + DD.MMM.YY$ IF POS (DD.MMM.YY$,"-", 1%) = 2% & \ DD.MMM.YY$ = DD.MMM.YY$ + "-" IF LEN(DD.MMM.YY$) = 2% & \ DD.MMM.YY$ = DD.MMM.YY$ + THIS.MMM$ IF LEN(DD.MMM.YY$) = 3% & \ DD.MMM.YY$ = DD.MMM.YY$ + "-" IF LEN(DD.MMM.YY$) = 6% & \ DD.MMM.YY$ = DD.MMM.YY$ + THIS.YY$ IF LEN(DD.MMM.YY$) = 7% & & \ GO TO 15899 IF LEN(DD.MMM.YY$) <> 9% & \ GO TO 15899 IF (SEG$(DD.MMM.YY$,3%,3%) <> "-" & OR SEG$(DD.MMM.YY$,7%,7%) <> "-") & \ DD$ = SEG$ (DD.MMM.YY$,1%,2%) & \ MMM$ = "," + SEG$(DD.MMM.YY$,4%,6%) + "," & \ YY$ = SEG$ (DD.MMM.YY$,8%,LEN(DD.MMM.YY$)) & \ MM% = & POS (",JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC,",MMM$,1%) & \ GO TO 15899 IF MM% = 0% & \ MM% = (MM% + 3%) / 4% ! Convert MMM$ to 1-12 & \ MM% = 2% * MM% - 1% ! Find offset for day limit & \ DAY.LIM% = VAL(SEG$("312831303130313130313031",MM%,(MM%+1%))) & \ YY% = VAL(YY$) & \ GO TO 15899 IF YY% < 1% & \ DAY.LIM% = 29% & IF (DAY.LIM% = 28% AND YY% = (YY% / 4%) * 4%) & \ GO TO 15899 & IF (VAL(DD$) > DAY.LIM% OR VAL(DD$) < 1%) & \ VALID% = TRUE% & \ VALID.DATE$ = DD.MMM.YY$ & \ GO TO 15899 & & ! Set error trapping to trap locally. Set VALID% flag to false & ! initially. Test input date for the right length, after allowing & ! for a one digit day. Check that the 3rd and 7th characters of the & ! string are dashes. Isolate day, month and year. Check for a & ! valid month abbreviation. Determine the number of allowable days & ! in the month (if year is divisible by 4, then it's a leap year and & ! Feb gets 29 days). Make sure year is numeric and positive. & 15890 RESUME 15899 & ! Reset error flag. & ! Program should only trap to here if year or day is not numeric. & 15899 FN.VALID.DATE% = VALID% & !- ON ERROR GO TO 19000 & \ FNEND & ! Set function value, reset normal error trapping, and return. &