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

DAY2GRE$  PowerBASIC  Function

         

DAY2GRE$ function evaluates to the date in Gregorian format (MM-DD-CCYY) that corresponds to the absolute date number specified as its parameter.  If parameter is 0 (zero), then "" (empty string) is returned instead of Gregorian date value.

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 DAY2GRE$ function is intended for a 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 dependencies:

JUL2GRE$ Convert Julian date into Gregorian date format function
LEAP% Check year for leap value function (predicate)

Indirect dependency:

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



 DAY2GRE$  Source  Program                     Debugging program                   Debugging logout

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

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

      '    Function

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

      '    DAY2GRE$ function converts absolute day number into Gregorian date.

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

      '    Day_Numb&  - Gregorian date in the form of MM-DD-YY or MM-DD-CCYY.

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

      '    IF specified absolute day number is greater than zero,
      '       THEN corresponding MM-DD-CCYY (date in Gregorian format) is returned
      '            to the point of function invocation
      '       ELSE "" (empty string) is returned to the point of invocation.

      ' 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 program is intended for the modern-time date
      '    calculations, those factors are insignificant.

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

      '    DAY2GRE$(     0)=""
      '    DAY2GRE$(     1)="01-01-0001"
      '    DAY2GRE$(   365)="12-31-0001"
      '    DAY2GRE$(   366)="01-01-0002"
      '    DAY2GRE$(   730)="12-31-0002"
      '    DAY2GRE$(   731)="01-01-0003"
      '    DAY2GRE$(  1095)="12-31-0003"
      '    DAY2GRE$(  1096)="01-01-0004"
      '    DAY2GRE$(  1460)="12-30-0004"
      '    DAY2GRE$(  1461)="12-31-0004"
      '    DAY2GRE$(  1462)="01-01-0005"
      '    DAY2GRE$(725371)="12-31-1986"
      '    DAY2GRE$(725372)="01-01-1987"
      '    DAY2GRE$(725736)="12-31-1987"
      '    DAY2GRE$(725737)="01-01-1988"
      '    DAY2GRE$(693595)="12-31-1899"
      '    DAY2GRE$(693596)="01-01-1900"
      '    DAY2GRE$(730119)="12-31-1999"
      '    DAY2GRE$(730120)="01-01-2000"

      ' External Functions -------------------------------------------------------

           #INCLUDE ONCE "JUL2GRE"
           #INCLUDE ONCE "LEAP"

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

           DEFINT A-Z  ' All defaulted variables are integer

           FUNCTION DAY2GRE$(Day_Numb&)

      ' Check Day Number Validity ------------------------------------------------

           IF (Day_Numb&<=0) THEN
              DAY2GRE$=""
              EXIT FUNCTION
           END IF

      ' Compute Components of Julian Date (Year and Day) -------------------------

           Year=1  ' First day of A.D. is 01-01-0001

           WHILE (Day_Numb&>365)
                 Day_Numb&=Day_Numb&-365+LEAP%(RIGHT$("000"+LTRIM$(STR$(Year)),4))
                 Year=Year+1
           WEND

      ' Adjust Date for 12/31 of Leap Year ---------------------------------------

           IF (Day_Numb&=0)AND _
              (LEAP%(RIGHT$("000"+LTRIM$(STR$(Year-1)),4))) THEN
              Day_Numb&=366
              Year=Year-1
           END IF

      ' Compose, Convert, and Return Gregorian Date to the Point of Invocation ---

           DAY2GRE$=JUL2GRE$(RIGHT$("000"+LTRIM$(STR$(Year     )),4)+"-"+ _
                             RIGHT$("00" +LTRIM$(STR$(Day_Numb&)),3))

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

           END FUNCTION
  
         

 DAY2GRE$  Debugging  Program                     Source program                   Debugging logout

      ' DAY2GRE$(0.0)  Convert Abs Day Number to Gregorian Date  02/01/1989-02/05/2010
      ' ------------------------------------------------------------------------------

        #INCLUDE "DAY2GRE"

        FUNCTION PBMAIN

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

        PRINT "DAY2GRE$(     0)='"; _
               DAY2GRE$(     0);"'"
        PRINT "DAY2GRE$(     1)='"; _
               DAY2GRE$(     1);"'"
        PRINT "DAY2GRE$(   365)='"; _
               DAY2GRE$(   365);"'"
        PRINT "DAY2GRE$(   366)='"; _
               DAY2GRE$(   366);"'"
        PRINT "DAY2GRE$(   730)='"; _
               DAY2GRE$(   730);"'"
        PRINT "DAY2GRE$(   731)='"; _
               DAY2GRE$(   731);"'"
        PRINT "DAY2GRE$(  1095)='"; _
               DAY2GRE$(  1095);"'"
        PRINT "DAY2GRE$(  1096)='"; _
               DAY2GRE$(  1096);"'"
        PRINT "DAY2GRE$(  1460)='"; _
               DAY2GRE$(  1460);"'"
        PRINT "DAY2GRE$(  1461)='"; _
               DAY2GRE$(  1461);"'"
        PRINT "DAY2GRE$(  1462)='"; _
               DAY2GRE$(  1462);"'"
        PRINT "DAY2GRE$(725371)='"; _
               DAY2GRE$(725371);"'"
        PRINT "DAY2GRE$(725372)='"; _
               DAY2GRE$(725372);"'"
        PRINT "DAY2GRE$(725736)='"; _
               DAY2GRE$(725736);"'"
        PRINT "DAY2GRE$(725737)='"; _
               DAY2GRE$(725737);"'"
        PRINT "DAY2GRE$(693595)='"; _
               DAY2GRE$(693595);"'"
        PRINT "DAY2GRE$(693596)='"; _
               DAY2GRE$(693596);"'"
        PRINT "DAY2GRE$(730119)='"; _
               DAY2GRE$(730119);"'"
        PRINT "DAY2GRE$(730120)='"; _
               DAY2GRE$(730120);"'"

        END FUNCTION
  
         

 DAY2GRE$  Debugging  Logout                       Source program                   Debugging program


   DAY2GRE$(0.0)  Convert Absolute Day Number to Gregorian Date  02-05-2010  08:00
   -------------------------------------------------------------------------------

   DAY2GRE$(     0)=''
   DAY2GRE$(     1)='01-01-0001'
   DAY2GRE$(   365)='12-31-0001'
   DAY2GRE$(   366)='01-01-0002'
   DAY2GRE$(   730)='12-31-0002'
   DAY2GRE$(   731)='01-01-0003'
   DAY2GRE$(  1095)='12-31-0003'
   DAY2GRE$(  1096)='01-01-0004'
   DAY2GRE$(  1460)='12-30-0004'
   DAY2GRE$(  1461)='12-31-0004'
   DAY2GRE$(  1462)='01-01-0005'
   DAY2GRE$(725371)='12-31-1986'
   DAY2GRE$(725372)='01-01-1987'
   DAY2GRE$(725736)='12-31-1987'
   DAY2GRE$(725737)='01-01-1988'
   DAY2GRE$(693595)='12-31-1899'
   DAY2GRE$(693596)='01-01-1900'
   DAY2GRE$(730119)='12-31-1999'
   DAY2GRE$(730120)='01-01-2000'
        

         

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