|
VALDGRE% PowerBASIC Function |
|
VALDGRE% function is a predicate that evaluates to "true" (-1), if its parameter represents the valid date in Gregorian calendar, or to "false", if it doesn't. Date field delimiters are expected to be in the fixed positions 3 and 5; values of delimiters are insignificant. Direct dependencies:
VALDGRE% Source Program Debugging program Debugging logout |
' 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
|
VALDGRE% Debugging Program Source program Debugging logout |
' VALDGRE%(0.0) Check Date for Valid Gregorian Value 04/28/1997-03/26/2002
' --------------------------------------------------------------------------
$INCLUDE "VALDGRE"
$LINK "MODULE.PBL"
DECLARE FUNCTION VALDGRE%(Spec.Date$)
CLS
PRINT "VALDGRE%(0.0) Check Date for Valid Gregorian Value ";DATE$;
PRINT " ";LEFT$(TIME$,5)
PRINT STRING$(70,"-")
PRINT
PRINT "VALDGRE%('' )="; _
VALDGRE%("" )
PRINT "VALDGRE%('11-11-1' )="; _
VALDGRE%("11-11-1" )
PRINT "VALDGRE%('11-11-111' )="; _
VALDGRE%("11-11-111" )
PRINT "VALDGRE%('11-11-11111')="; _
VALDGRE%("11-11-11111")
PRINT "VALDGRE%('*1-11-11' )="; _
VALDGRE%("*1-11-11" )
PRINT "VALDGRE%('11-*1-11' )="; _
VALDGRE%("11-*1-11" )
PRINT "VALDGRE%('11-11-*1' )="; _
VALDGRE%("11-11-*1" )
PRINT "VALDGRE%('00-01-00' )="; _
VALDGRE%("00-01-00" )
PRINT "VALDGRE%('13-01-00' )="; _
VALDGRE%("13-01-00" )
PRINT "VALDGRE%('01-00-00' )="; _
VALDGRE%("01-00-00" )
PRINT "VALDGRE%('01-32-00' )="; _
VALDGRE%("01-32-00" )
PRINT "VALDGRE%('02-29-1900' )="; _
VALDGRE%("02-29-1900" )
PRINT "VALDGRE%('02-30-2000' )="; _
VALDGRE%("02-30-2000" )
PRINT "VALDGRE%('02-27-1900' )="; _
VALDGRE%("02-27-1900" )
PRINT "VALDGRE%('02-28-2000' )="; _
VALDGRE%("02-28-2000" )
PRINT "VALDGRE%('01-01-2001' )="; _
VALDGRE%("01-01-2001" )
PRINT "VALDGRE%('06-15-2002' )="; _
VALDGRE%("06-15-2002" )
PRINT "VALDGRE%('12-15-9999' )="; _
VALDGRE%("12-15-9999" )
PRINT
PRINT "Execution completed - hit [Enter] to continue..."
|
VALDGRE% Debugging Logout Source program Debugging program |
VALDGRE%(0.0) Check Date for Valid Gregorian Value 03-26-2002 18:02
----------------------------------------------------------------------
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
Execution completed - hit [Enter] to continue...
|
|
View [and save] VALDGRE.BAS text View [and save] ZVALDGRE.BAS text (Use [Back] button or [Alt]+[CL] to return here from the viewed text) Copyright © 1997–2002 by Go to: Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top |