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

VALDGRE%  PowerBASIC  Function

         

VALDGRE% function is a predicate (logical function evaluating to "true" or "false") that evaluates to "true" (-1), if its parameter represents the valid date in Gregorian calendar, or to "false" (0), 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:

DIGITAL% Check character string for digital value function (predicate)
LEAP% Check year for leap value function (predicate)



 VALDGRE%  Source  Program                     Debugging program                  Debugging logout

      ' VALDGRE%(0.0)  Check Date for Valid Gregorian Value      04/28/1997-02/02/2010
      ' ------------------------------------------------------------------------------
      ' Copyright (C) 1997-2010 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.

      ' 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 -----------------------------------------------------------

           #INCLUDE ONCE "DIGITAL"
           #INCLUDE ONCE "LEAP"

      ' Start Function ---------------------------------------------------------------

           DEFINT A-Z  ' All defaulted variables are integer

           FUNCTION VALDGRE%(Spec_Date$)

      ' 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-02/02/2010
      ' ------------------------------------------------------------------------------

        #INCLUDE "VALDGRE"

        FUNCTION PBMAIN

        PRINT "VALDGRE%(0.0)  Check Date for Valid Gregorian Value  ";DATE$;
        PRINT "  ";LEFT$(TIME$,5)
        PRINT STRING$(70,"-")
        PRINT

        PRINT "VALDGRE%(''           )="; VALDGRE%(""); "'  - Today "; DATE$

        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" )

        END FUNCTION
  
         

 VALDGRE%  Debugging  Logout                     Source program                 Debugging program


   VALDGRE%(0.0)  Check Date for Valid Gregorian Value  09-18-2016  15:58
   ----------------------------------------------------------------------

   VALDGRE%(''           )=-1 '  - Today 09-18-2016
   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
        

         

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 © 19972010 by
Go to:  Davar site entry | Site contents | Site index | Personal Computer | PowerBASIC | Text top