Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text bottom

LEAP%  PowerBASIC  Function

         

LEAP% function is a predicate that evaluates to "true" (-1), if its parameter represents the leap year in Gregorian calendar, or to "false", if it doesn't.  If year specification is invalid (non-digital, or having length other than 2 or 4), leap characteristic is returned for the current year.

Direct dependency:

DIGITAL% Check character string for digital value (predicate)



 LEAP%  Source  Program                             Debugging program             Debugging logout

      ' 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
  
         

 LEAP%  Debugging  Program                          Source program               Debugging logout

      ' LEAP%(2.0)  Check Year for Leap Value                09/30/1992-03/01/2002
      ' --------------------------------------------------------------------------

        $INCLUDE "LEAP"
        $LINK    "MODULE.PBL"

        DECLARE FUNCTION LEAP%(Year$)

        CLS
        PRINT "LEAP%(2.0)  Check Year for Leap Value  ";DATE$;
        PRINT "  ";LEFT$(TIME$,5)
        PRINT STRING$(56,"-")
        PRINT

        PRINT "LEAP%(''    )="; _
               LEAP%(""    )
        PRINT "LEAP%('04'  )="; _
               LEAP%("04"  )
        PRINT "LEAP%('1988')="; _
               LEAP%("1988")
        PRINT "LEAP%('1989')="; _
               LEAP%("1989")
        PRINT "LEAP%('1900')="; _
               LEAP%("1900")
        PRINT "LEAP%('2000')="; _
               LEAP%("2000")
        PRINT "LEAP%('ABCD')="; _
               LEAP%("ABCD")

        PRINT
        PRINT "Execution completed - hit [Enter] to continue..."
  
         

 LEAP%  Debugging  Logout        Source program       Debugging program

         

   LEAP%(2.0)  Check Year for Leap Value  03-29-2002  18:59
   --------------------------------------------------------

   LEAP%(''    )= 0
   LEAP%('04'  )=-1
   LEAP%('1988')=-1
   LEAP%('1989')= 0
   LEAP%('1900')= 0
   LEAP%('2000')=-1
   LEAP%('ABCD')= 0

   Execution completed - hit [Enter] to continue...
        
      

         

View [and save] LEAP.BAS text       View [and save] ZLEAP.BAS text
(Use [Back] button or [Alt]+[CL] to return here from the viewed text)
Copyright © 19922002 by
Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top