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

GRE2DAY&  PowerBASIC  Function

         

GRE2DAY& function evaluates to the absolute day number that corresponds to the Gregorian date specified as its parameter.  Date should be specified in one of the formats MM-DD-YY or MM-DD-CCYY and should be a valid date in Gregorian calendar.  If parameter doesn't represent a valid date, 0 (zero) is returned instead of absolute day number.  If century is omitted, the current century is assumed.  Date field delimiters are expected to be in the fixed positions 3 and 5; values of delimiters are insignificant.  If parameter is empty, absolute day number is returned for the current date.

Note:  Program doesn't take into account pre-Gregorian (Julian) calendar differences and date adjustment made on 09/14/1752 when England and its colonies switched from Julian calendar to currently used Gregorian. Since GRE2DAY& function is intended for the modern-time date calculations, those factors are insignificant adjustments would cancel one another in contemporary date differential arithmetic, support of which is a primary purpose of this program.

Direct dependency:

GRE2JUL$ Convert Gregorian date into Julian date format function

Indirect dependencies:

DIGITAL% Check character string for digital value function (predicate)
LEAP% Check year for leap value function (predicate)
VALDGRE% Check date for valid Gregorian value function (predicate)



 GRE2DAY&  Source  Program                       Debugging program                   Debugging logout

      ' GRE2DAY&(0.0)  Convert Gregorian Date to Day Number      02/01/1989-02/05/2010
      ' ------------------------------------------------------------------------------
      ' Copyright (C) 1989-2010 by Vladimir Veytsel                      www.davar.net

      ' Type -------------------------------------------------------------------------

      '    Function

      ' Description ------------------------------------------------------------------

      '    GRE2DAY& function converts Gregorian date into absolute day number.

      ' Parameter --------------------------------------------------------------------

      '    Greg_Date$  - Gregorian date in the form of MM-DD-YY or MM-DD-CCYY

      ' Value ------------------------------------------------------------------------

      '    IF specified Gregorian 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 absolute day number for specified Gregorian date is returned
      '            to the point of function invocation
      '       ELSE 0 (zero) is returned to the point of 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 one, and absolute A.D. day number
      '    is returned for the CURRENT date (default).

      '  - Program doesn't take into account pre-Gregorian (Julian) calendar
      '    differences and date adjustment made on 09/14/1752 - when England
      '    and its colonies switched from Julian calendar to currently used
      '    Gregorian.  Since program is intended for the modern-time date
      '    calculations, those factors are insignificant.

      ' Examples ---------------------------------------------------------------------

      '    GRE2DAY&("*"         )= 0
      '    GRE2DAY&(""          )= Absolute day number for the current date
      '    GRE2DAY&("01-01-0001")= 1
      '    GRE2DAY&("12-31-0001")= 365
      '    GRE2DAY&("01-01-0002")= 366
      '    GRE2DAY&("12-31-0002")= 730
      '    GRE2DAY&("01-01-0003")= 731
      '    GRE2DAY&("12-31-0003")= 1095
      '    GRE2DAY&("01-01-0004")= 1096
      '    GRE2DAY&("12-31-0004")= 1461
      '    GRE2DAY&("01-01-0005")= 1462
      '    GRE2DAY&("12-31-1986")= 725371
      '    GRE2DAY&("01-01-1987")= 725372
      '    GRE2DAY&("12-31-1987")= 725736
      '    GRE2DAY&("01-01-1988")= 725737
      '    GRE2DAY&("12-31-1899")= 693595
      '    GRE2DAY&("01-01-1900")= 693596
      '    GRE2DAY&("12-31-1999")= 730119
      '    GRE2DAY&("01-01-00"  )= 730120

      ' External Function ------------------------------------------------------------

           #INCLUDE ONCE "GRE2JUL"

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

           DEFINT A-Z  ' All defaulted variables are integer

           FUNCTION GRE2DAY&(Greg_Date$)

      ' Convert Gregorian Date to Julian Format --------------------------------------
      ' (Checks date validity and handles default empty date - current)

           Jul_Date$=GRE2JUL$(Greg_Date$)

           IF (LEN(Jul_Date$)=0) THEN
              GRE2DAY&=0
              EXIT FUNCTION
           END IF

      ' Add Current Century to Short Date (YY-DDD) -----------------------------------

           IF (LEN(Jul_Date$)=6) THEN
              Jul_Date$=MID$(DATE$,7,2)+Jul_Date$
           END IF

      ' Parse Date to Be Converted ---------------------------------------------------

           Day    =VAL(RIGHT$(Jul_Date$,3))
           Year   =VAL( LEFT$(Jul_Date$,4))-1  ' First day of A.D. is 01-01-0001
           Century=INT(Year/100)

      ' Compute and Return Absolute Day Number to the Point of Invocation ------------

           GRE2DAY&=Year*365+Day+INT(Year/4)-Century+INT(Century/4)

      ' Finish Function --------------------------------------------------------------

           END FUNCTION
  
         

 GRE2DAY&  Debugging  Program                   Source program                 Debugging logout

      ' GRE2DAY&(0.0)  Convert Gregorian Date to Day Number      02/01/1989-02/05/2010
      ' ------------------------------------------------------------------------------

        #INCLUDE "GRE2DAY"

        FUNCTION PBMAIN

        PRINT "GRE2DAY&(0.0)  Convert Gregorian Date to Absolute Day Number  ";DATE$;
        PRINT "  ";LEFT$(TIME$,5)
        PRINT STRING$(79,"-")
        PRINT

        PRINT "GRE2DAY&('*'         )="; _
               GRE2DAY&("*"         )
        PRINT "GRE2DAY&(''          )="; _
               GRE2DAY&(""          );"  - Today ";DATE$
        PRINT "GRE2DAY&('01-01-0001')="; _
               GRE2DAY&("01-01-0001")
        PRINT "GRE2DAY&('12-31-0001')="; _
               GRE2DAY&("12-31-0001")
        PRINT "GRE2DAY&('01-01-0002')="; _
               GRE2DAY&("01-01-0002")
        PRINT "GRE2DAY&('12-31-0002')="; _
               GRE2DAY&("12-31-0002")
        PRINT "GRE2DAY&('01-01-0003')="; _
               GRE2DAY&("01-01-0003")
        PRINT "GRE2DAY&('12-31-0003')="; _
               GRE2DAY&("12-31-0003")
        PRINT "GRE2DAY&('01-01-0004')="; _
               GRE2DAY&("01-01-0004")
        PRINT "GRE2DAY&('12-31-0004')="; _
               GRE2DAY&("12-31-0004")
        PRINT "GRE2DAY&('01-01-0005')="; _
               GRE2DAY&("01-01-0005")
        PRINT "GRE2DAY&('12-31-1986')="; _
               GRE2DAY&("12-31-1986")
        PRINT "GRE2DAY&('01-01-1987')="; _
               GRE2DAY&("01-01-1987")
        PRINT "GRE2DAY&('12-31-1987')="; _
               GRE2DAY&("12-31-1987")
        PRINT "GRE2DAY&('01-01-1988')="; _
               GRE2DAY&("01-01-1988")
        PRINT "GRE2DAY&('12-31-1899')="; _
               GRE2DAY&("12-31-1899")
        PRINT "GRE2DAY&('01-01-1900')="; _
               GRE2DAY&("01-01-1900")
        PRINT "GRE2DAY&('12-31-1999')="; _
               GRE2DAY&("12-31-1999")
        PRINT "GRE2DAY&('01-01-00'  )="; _
               GRE2DAY&("01-01-00"  );"  - Today's century"

        END FUNCTION
  
         

 GRE2DAY&  Debugging  Logout                     Source program                   Debugging program


   GRE2DAY&(0.0)  Convert Gregorian Date to Absolute Day Number  02-05-2010  18:15
   -------------------------------------------------------------------------------

   GRE2DAY&('*'         )= 0
   GRE2DAY&(''          )= 733808   - Today 02-05-2010
   GRE2DAY&('01-01-0001')= 1
   GRE2DAY&('12-31-0001')= 365
   GRE2DAY&('01-01-0002')= 366
   GRE2DAY&('12-31-0002')= 730
   GRE2DAY&('01-01-0003')= 731
   GRE2DAY&('12-31-0003')= 1095
   GRE2DAY&('01-01-0004')= 1096
   GRE2DAY&('12-31-0004')= 1461
   GRE2DAY&('01-01-0005')= 1462
   GRE2DAY&('12-31-1986')= 725371
   GRE2DAY&('01-01-1987')= 725372
   GRE2DAY&('12-31-1987')= 725736
   GRE2DAY&('01-01-1988')= 725737
   GRE2DAY&('12-31-1899')= 693595
   GRE2DAY&('01-01-1900')= 693596
   GRE2DAY&('12-31-1999')= 730119
        

         

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