' VALDGRE%(0.0) Check Date for Valid Gregorian Value 04/28/1997-03/25/2002 ' -------------------------------------------------------------------------- ' Copyright (C) 1997-2002 by Vladimir Veytsel www.davar.net ' Type --------------------------------------------------------------------- ' Function (predicate) ' Description -------------------------------------------------------------- ' VALDGRE% function is a predicate that returns validity characteristic ' of the specified date in Gregorian calendar system. ' Declaration -------------------------------------------------------------- ' DECLARE FUNCTION VALDGRE%(Spec.Date$) ' Parameter ---------------------------------------------------------------- ' Spec.Date$ - Specified date in the form of MM-DD-YY or MM-DD-CCYY ' Value -------------------------------------------------------------------- ' If specified date is either EMPTY or valid, i.e: ' it has length either of 8 or 10 characters and ' it is DIGITAL (with the exception of date field delimiters) and ' month value lies within 1-12 and ' day number lies within range valid for the specified month ' (considering specified year leap characteristic when ' evaluating day range for February), ' then -1 (true) is returned to the point of function invocation, ' else 0 (false) is returned to the point of function invocation. ' Notes -------------------------------------------------------------------- ' - Delimiters of parameter date fields are irrelevant and can be any ' symbols. Date fields are extracted from fixed positions. ' - EMPTY date is considered to be a valid date, since in date programs ' this is an indication to use CURRENT date (default). ' Examples ----------------------------------------------------------------- ' VALDGRE%("" )=-1 ' VALDGRE%("11-11-1" )= 0 ' VALDGRE%("11-11-111" )= 0 ' VALDGRE%("11-11-11111")= 0 ' VALDGRE%("*1-11-11" )= 0 ' VALDGRE%("11-*1-11" )= 0 ' VALDGRE%("11-11-*1" )= 0 ' VALDGRE%("00-01-00" )= 0 ' VALDGRE%("13-01-00" )= 0 ' VALDGRE%("01-00-00" )= 0 ' VALDGRE%("01-32-00" )= 0 ' VALDGRE%("02-29-1900" )= 0 ' VALDGRE%("02-30-2000" )= 0 ' VALDGRE%("02-27-1900" )=-1 ' VALDGRE%("02-28-2000" )=-1 ' VALDGRE%("01-01-2001" )=-1 ' VALDGRE%("06-15-2002" )=-1 ' VALDGRE%("12-15-9999" )=-1 ' External Functions ------------------------------------------------------- DECLARE FUNCTION DIGITAL%(Strng$,Delim$) DECLARE FUNCTION LEAP% (Year$) ' Start Function ----------------------------------------------------------- DEFINT A-Z ' All defaulted variables are integer FUNCTION VALDGRE%(Spec.Date$) PUBLIC ' Check Specified Date for Empty Value ------------------------------------- IF (LEN(Spec.Date$)=0) THEN VALDGRE%=-1 EXIT FUNCTION END IF ' Check Specified Date for Valid Length (8 or 10 Characters) --------------- IF ((LEN(Spec.Date$)<> 8) AND _ (LEN(Spec.Date$)<>10)) THEN VALDGRE%=0 EXIT FUNCTION END IF ' Check Specified Date for Digital Value ----------------------------------- IF (DIGITAL%(LEFT$(Spec.Date$,2) + _ MID$(Spec.Date$,4,2) + _ MID$(Spec.Date$,7),"")) THEN Month=VAL(LEFT$(Spec.Date$,2)) Day =VAL( MID$(Spec.Date$,4,2)) Year$= MID$(Spec.Date$,7) ELSE VALDGRE%=0 EXIT FUNCTION END IF ' Check Month and Day for Lying within Proper Borders ---------------------- IF ((Month>0) AND _ (Month<13)) THEN VALDGRE%=((Day>0)AND _ (Day<(VAL(MID$("322932313231323231323132",Month*2-1,2))+ _ (Month=2)*LEAP%(Year$)))) ELSE VALDGRE%=0 END IF ' Finish.Function ---------------------------------------------------------- END FUNCTION