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

GRE2JUL$  PowerBASIC  Function

         

GRE2JUL$ function evaluates to the date in Julian format (YY-DDD or CCYY-DDD) 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, "" (empty string) is returned instead of Julian date value.  Date field delimiters are expected to be in the fixed positions 3 and 5; values of delimiters are insignificant.  If parameter is empty, Julian date value is returned for the current date.

Julian date no doubt belongs completely to the mainframe past, and hardly is any longer used as a separate date format even in modern mainframes.  However, its usage simplifies significantly all date calculations into which it inevitably gets incorporated.  I prefer to use Julian format explicitly in order to make date conversion logic clear.

Direct dependencies:

LEAP% Check year for leap value function (predicate)
VALDGRE% Check date for valid Gregorian value function (predicate)

Indirect dependency:

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



 GRE2JUL$  Source  Program                       Debugging program                   Debugging logout

      ' GRE2JUL$(0.0)  Convert Gregorian Date to Julian Format   04/05/1988-02/04/2010
      ' ------------------------------------------------------------------------------
      ' Copyright (C) 1988-2010 by Vladimir Veytsel                      www.davar.net

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

      '    Function

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

      '    GRE2JUL$ function converts Gregorian date into Julian date format.

      ' Declaration ------------------------------------------------------------------

      '    DECLARE FUNCTION GRE2JUL$(Greg_Date$)

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

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

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

      '    IU 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 YY-DDD or CCYY-DDD (date in Julian format) is returned
      '            to the point of function invocation
      '            (where DDD is a day number within a year),
      '       ELSE "" (empty string) 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 date in Julian
      '    format CCYY-DDD is returned for the CURRENT date (default).

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

      '    GRE2JUL$(""          )=Current date in Julian format
      '    GRE2JUL$("02-29-1987")=""
      '    GRE2JUL$("01-01-87"  )="87-001"
      '    GRE2JUL$("01-31-87"  )="87-031"
      '    GRE2JUL$("02-28-87"  )="87-059"
      '    GRE2JUL$("03-31-87"  )="87-090"
      '    GRE2JUL$("04-30-87"  )="87-120"
      '    GRE2JUL$("05-31-87"  )="87-151"
      '    GRE2JUL$("06-30-87"  )="87-181"
      '    GRE2JUL$("07-31-87"  )="87-212"
      '    GRE2JUL$("08-31-87"  )="87-243"
      '    GRE2JUL$("09-30-87"  )="87-273"
      '    GRE2JUL$("10-31-87"  )="87-304"
      '    GRE2JUL$("11-30-87"  )="87-334"
      '    GRE2JUL$("12-31-87"  )="87-365"

      '    GRE2JUL$("01-01-1988")="1988-001"
      '    GRE2JUL$("01-31-1988")="1988-031"
      '    GRE2JUL$("02-29-1988")="1988-060"
      '    GRE2JUL$("03-31-1988")="1988-091"
      '    GRE2JUL$("04-30-1988")="1988-121"
      '    GRE2JUL$("05-31-1988")="1988-152"
      '    GRE2JUL$("06-30-1988")="1988-182"
      '    GRE2JUL$("07-31-1988")="1988-213"
      '    GRE2JUL$("08-31-1988")="1988-244"
      '    GRE2JUL$("09-30-1988")="1988-274"
      '    GRE2JUL$("10-31-1988")="1988-305"
      '    GRE2JUL$("11-30-1988")="1988-335"
      '    GRE2JUL$("12-31-1988")="1988-366"

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

           #INCLUDE ONCE "LEAP"
           #INCLUDE ONCE "VALDGRE"

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

           DEFINT A-Z  ' All defaulted variables are integer

           FUNCTION GRE2JUL$(Greg_Date$)

      ' Check Date Validity and Handle Default Empty Date (Current) ------------------

           IF (LEN(Greg_Date$)=0) THEN
              DT$=DATE$
           ELSEIF (VALDGRE%(Greg_Date$)) THEN
              DT$=Greg_Date$
           ELSE
              GRE2JUL$=""
              EXIT FUNCTION
           END IF

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

           Month=VAL(LEFT$(DT$,2))
           Day  =VAL( MID$(DT$,4,2))
           Year$=     MID$(DT$,7)

      ' Compute Julian Day Number ----------------------------------------------------

           DDD=Day+ _
               VAL(MID$("000,031,059,090,120,151,181,212,243,273,304,334",4*Month-3,3))+ _
               (Month>2)*(LEAP%(Year$))

      ' Form and Return Julian Date Value to the Point of Invocation -----------------

           GRE2JUL$=Year$+"-"+RIGHT$("00"+LTRIM$(STR$(DDD)),3)

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

           END FUNCTION
  
         

 GRE2JUL$  Debugging  Program                     Source program                   Debugging logout

      ' GRE2JUL$(0.0)  Convert Gregorian Date to Julian Format   04/05/1988-02/04/2004
      ' ------------------------------------------------------------------------------

        #INCLUDE "GRE2JUL"

        FUNCTION PBMAIN

        PRINT "GRE2JUL$(0.0)  Convert Gregorian Date to Julian Format  ";DATE$;
        PRINT "  ";LEFT$(TIME$,5)
        PRINT STRING$(73,"-")
        PRINT

        PRINT "GRE2JUL$(''          )='"; _
               GRE2JUL$(""          );"'  - Today ";DATE$
        PRINT "GRE2JUL$('02-29-1987')='"; _
               GRE2JUL$("02-29-1987");"'"
        PRINT "GRE2JUL$('01-01-87'  )='"; _
               GRE2JUL$("01-01-87"  );"'"
        PRINT "GRE2JUL$('01-31-87'  )='"; _
               GRE2JUL$("01-31-87"  );"'"
        PRINT "GRE2JUL$('02-28-87'  )='"; _
               GRE2JUL$("02-28-87"  );"'"
        PRINT "GRE2JUL$('03-31-87'  )='"; _
               GRE2JUL$("03-31-87"  );"'"
        PRINT "GRE2JUL$('04-30-87'  )='"; _
               GRE2JUL$("04-30-87"  );"'"
        PRINT "GRE2JUL$('05-31-87'  )='"; _
               GRE2JUL$("05-31-87"  );"'"
        PRINT "GRE2JUL$('06-30-87'  )='"; _
               GRE2JUL$("06-30-87"  );"'"
        PRINT "GRE2JUL$('07-31-87'  )='"; _
               GRE2JUL$("07-31-87"  );"'"
        PRINT "GRE2JUL$('08-31-87'  )='"; _
               GRE2JUL$("08-31-87"  );"'"
        PRINT "GRE2JUL$('09-30-87'  )='"; _
               GRE2JUL$("09-30-87"  );"'"
        PRINT "GRE2JUL$('10-31-87'  )='"; _
               GRE2JUL$("10-31-87"  );"'"
        PRINT "GRE2JUL$('11-30-87'  )='"; _
               GRE2JUL$("11-30-87"  );"'"
        PRINT "GRE2JUL$('12-31-87'  )='"; _
               GRE2JUL$("12-31-87"  );"'"
        PRINT "GRE2JUL$('01-01-1988')='"; _
               GRE2JUL$("01-01-1988");"'"
        PRINT "GRE2JUL$('01-31-1988')='"; _
               GRE2JUL$("01-31-1988");"'"
        PRINT "GRE2JUL$('02-29-1988')='"; _
               GRE2JUL$("02-29-1988");"'"
        PRINT "GRE2JUL$('03-31-1988')='"; _
               GRE2JUL$("03-31-1988");"'"
        PRINT "GRE2JUL$('04-30-1988')='"; _
               GRE2JUL$("04-30-1988");"'"
        PRINT "GRE2JUL$('05-31-1988')='"; _
               GRE2JUL$("05-31-1988");"'"
        PRINT "GRE2JUL$('06-30-1988')='"; _
               GRE2JUL$("06-30-1988");"'"
        PRINT "GRE2JUL$('07-31-1988')='"; _
               GRE2JUL$("07-31-1988");"'"
        PRINT "GRE2JUL$('08-31-1988')='"; _
               GRE2JUL$("08-31-1988");"'"
        PRINT "GRE2JUL$('09-30-1988')='"; _
               GRE2JUL$("09-30-1988");"'"
        PRINT "GRE2JUL$('10-31-1988')='"; _
               GRE2JUL$("10-31-1988");"'"
        PRINT "GRE2JUL$('11-30-1988')='"; _
               GRE2JUL$("11-30-1988");"'"
        PRINT "GRE2JUL$('12-31-1988')='"; _
               GRE2JUL$("12-31-1988");"'"

        END FUNCTION
  
         

 GRE2JUL$  Debugging  Logout                         Source program                 Debugging program


   GRE2JUL$(0.0)  Convert Gregorian Date to Julian Format  02-04-2010  16:19
   -------------------------------------------------------------------------

   GRE2JUL$(''          )='2010-035'  - Today 02-04-2010
   GRE2JUL$('02-29-1987')=''
   GRE2JUL$('01-01-87'  )='87-001'
   GRE2JUL$('01-31-87'  )='87-031'
   GRE2JUL$('02-28-87'  )='87-059'
   GRE2JUL$('03-31-87'  )='87-090'
   GRE2JUL$('04-30-87'  )='87-120'
   GRE2JUL$('05-31-87'  )='87-151'
   GRE2JUL$('06-30-87'  )='87-181'
   GRE2JUL$('07-31-87'  )='87-212'
   GRE2JUL$('08-31-87'  )='87-243'
   GRE2JUL$('09-30-87'  )='87-273'
   GRE2JUL$('10-31-87'  )='87-304'
   GRE2JUL$('11-30-87'  )='87-334'
   GRE2JUL$('12-31-87'  )='87-365'
   GRE2JUL$('01-01-1988')='1988-001'
   GRE2JUL$('01-31-1988')='1988-031'
   GRE2JUL$('02-29-1988')='1988-060'
   GRE2JUL$('03-31-1988')='1988-091'
   GRE2JUL$('04-30-1988')='1988-121'
   GRE2JUL$('05-31-1988')='1988-152'
   GRE2JUL$('06-30-1988')='1988-182'
   GRE2JUL$('07-31-1988')='1988-213'
   GRE2JUL$('08-31-1988')='1988-244'
   GRE2JUL$('09-30-1988')='1988-274'
   GRE2JUL$('10-31-1988')='1988-305'
   GRE2JUL$('11-30-1988')='1988-335'
   GRE2JUL$('12-31-1988')='1988-366'
        

         

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