' LEAP%(2.0)  Check Year for Leap Value                    09/30/1992-01/29/2010
' ------------------------------------------------------------------------------
' Copyright (C) 1992-2010 by Vladimir Veytsel                      www.davar.net

' Type -------------------------------------------------------------------------

'    Function

' Description ------------------------------------------------------------------

'    Function is a predicate that returns the leap characteristic of the 
'    specified 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 the 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 characteristic of the CURRENT year
'    LEAP%("00"  )=-1
'    LEAP%("1988")=-1
'    LEAP%("1989")= 0
'    LEAP%("1900")= 0
'    LEAP%("2000")=-1
'    LEAP%("ABCD")= Leap characteristic of the CURRENT year

' External Function ------------------------------------------------------------

     #INCLUDE ONCE "DIGITAL"

' Start Function ---------------------------------------------------------------

     DEFINT A-Z  ' All defaulted variables are integer

     FUNCTION LEAP%(Year$)

' 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)  ' Changed for CURRENT year
     END SELECT

     IF (NOT(DIGITAL%(Full_Year$,""))) THEN
        Full_Year$=RIGHT$(DATE$,4)  ' Non-digital year changed for CURRENT year
     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