|
LEAP% PowerBASIC Function |
|
LEAP% function is a predicate (logical function evaluating to "true" or "false") that evaluates to "true" (-1), if its parameter represents the leap year in Gregorian calendar, or to "false" (0), 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:
LEAP% Source Program Debugging program Debugging logout |
' 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
|
LEAP% Debugging Program Source program Debugging logout |
' LEAP%(2.0) Check Year for Leap Value 09/30/1992-01/29/2010
' ------------------------------------------------------------------------------
#INCLUDE "LEAP"
FUNCTION PBMAIN
PRINT "LEAP%(2.0) Check Year for Leap Value ";DATE$;
PRINT " ";LEFT$(TIME$,5)
PRINT STRING$(56,"-")
PRINT
PRINT "LEAP%('' )="; _
LEAP%("" );" - Leap characteristic of the CURRENT year"
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");" - Leap characteristic of the CURRENT year"
END FUNCTION
|
LEAP% Debugging Logout Source program Debugging program |
LEAP%(2.0) Check Year for Leap Value 09-06-2016 22:13
--------------------------------------------------------
LEAP%('' )=-1 - Leap characteristic of the CURRENT year
LEAP%('04' )=-1
LEAP%('1988')=-1
LEAP%('1989')= 0
LEAP%('1900')= 0
LEAP%('2000')=-1
LEAP%('ABCD')=-1 - Leap characteristic of the CURRENT year
|
|
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 © 1992–2010 by Go to: Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top |