' LEAP%(2.0)  Check Year for Leap Value                09/30/1992-03/01/2002
' --------------------------------------------------------------------------
' Copyright (C) 1992-2002 by Vladimir Veytsel                  www.davar.net

' Type ---------------------------------------------------------------------

'    Function

' Description --------------------------------------------------------------

'    Function is a predicate that returns the leap characteristic
'    of the specified year.

' Declaration --------------------------------------------------------------

'    DECLARE FUNCTION LEAP%(Year$)

' Parameter ----------------------------------------------------------------

'    Year$  - Year to be checked for leap value

' Value --------------------------------------------------------------------

'  - "True" (-1) if specified year is leap
'  - "False" (0) if specified year is non-leap

' Notes --------------------------------------------------------------------

'  - Year leap characteristic is determined according to Gregorian calendar
'    rules:
'    - On century border century number is multiple of 4;
'    - Otherwise year number (it's sufficient to check only last 2 digits)
'      is multiple of 4.

'  - If specified year length is 2 characters,
'       then CURRENT century is assumed (two digit of century get appended
'            to Year$ head).

'  - Specified year length should be either 2 or 4 characters and should be
'    digital.  These conditions should  be checked by the calling program,
'    lest LEAP function would substitute specified year for the CURRENT one,
'    thus returning the leap characteristic for the current year instead of
'    the specified.

' Examples -----------------------------------------------------------------

'    LEAP(""    )=Leap value for CURRENT year
'    LEAP("00"  )=-1
'    LEAP("1988")=-1
'    LEAP("1989")= 0
'    LEAP("1900")= 0
'    LEAP("2000")=-1

' External Function --------------------------------------------------------

     DECLARE FUNCTION DIGITAL%(Strng$,Delim$)

' Start Function -----------------------------------------------------------

     FUNCTION LEAP%(Year$) PUBLIC

' Preform Year Parameter (Adjust Length to 4 Characters) -------------------

     SELECT CASE (LEN(Year$))
            CASE (2) : Full.Year$=MID$(DATE$,7,2)+Year$
            CASE (4) : Full.Year$=Year$
            CASE ELSE: Full.Year$=RIGHT$(DATE$,4)
     END SELECT

     IF (NOT(DIGITAL%(Full.Year$,""))) THEN
        Full.Year$=RIGHT$(DATE$,4)
     END IF

' Form and Return Year Leap Value to the Point of Invocation ---------------

     Cent=VAL( LEFT$(Full.Year$,2))  ' Century
     Year=VAL(RIGHT$(Full.Year$,2))  ' Year within century

     LEAP%=(((Year= 0)AND        _
             ((Cent MOD 4)=0))OR _
            ((Year<>0)AND        _
             ((Year MOD 4)=0)))

' Finish Function ----------------------------------------------------------

     END FUNCTION
