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

JUL2GRE$  PowerBASIC  Function

         

JUL2GRE$ function evaluates to the date in Gregorian format (MM-DD-YY or MM-DD-CCYY) that corresponds to the Julian date specified as its parameter.  Date should be specified in one of the formats YY-DDD or CCYY-DDD and should be a valid date in Julian calendar.  If parameter doesn't represent a valid date, "" (empty string) is returned instead of Gregorian date value.  Date field delimiter is expected to be in the fixed position 3 or 5; value of delimiter is insignificant.  If parameter is empty, Gregorian 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:

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



 JUL2GRE$  Source  Program                       Debugging program                     Debugging logout

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

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

      '    Function

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

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

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

      '    DECLARE FUNCTION JUL2GRE$(Jul_Date$)

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

      '    Jul_Date$  - Julian date in the form of YY-DDD or CCYY-DDD,
      '                 where DDD is a day number within a year.

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

      '    IF specified Julian date is valid, i.e.:
      '       it is non-empty and
      '       it has length either of 6 or 8 characters and
      '       it is DIGITAL (with the exception of date field delimiter) and
      '       day number lies within range of 1-365
      '       (or 1-366, considering specified year leap characteristic),
      '       THEN MM-DD-YY or 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.

      ' Notes ------------------------------------------------------------------------

      '  - Delimiter of parameter date fields is irrelevant and can be any symbol.
      '    Date fields are extracted from fixed positions.

      '  - EMPTY date is considered to be an INVALID one - Julian date is an internal
      '    format that doesn't require a default.

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

      '    JUL2GRE$(""        )=""
      '    JUL2GRE$("87-31"   )=""
      '    JUL2GRE$("1987-31" )=""
      '    JUL2GRE$("19*7-031")=""
      '    JUL2GRE$("1988-0#1")=""
      '    JUL2GRE$("87-000"  )=""
      '    JUL2GRE$("87-366"  )=""
      '    JUL2GRE$("1988-367")=""

      '    JUL2GRE$("87-031"  )="01-31-87"
      '    JUL2GRE$("87-059"  )="02-28-87"
      '    JUL2GRE$("87-090"  )="03-31-87"
      '    JUL2GRE$("87-120"  )="04-30-87"
      '    JUL2GRE$("87-151"  )="05-31-87"
      '    JUL2GRE$("87-181"  )="06-30-87"
      '    JUL2GRE$("87-212"  )="07-31-87"
      '    JUL2GRE$("87-243"  )="08-31-87"
      '    JUL2GRE$("87-273"  )="09-30-87"
      '    JUL2GRE$("87-304"  )="10-31-87"
      '    JUL2GRE$("87-334"  )="11-30-87"
      '    JUL2GRE$("87-365"  )="12-31-87"

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

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

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

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

           DEFINT A-Z  ' All defaulted variables are integer

           FUNCTION JUL2GRE$(Jul_Date$)

      ' Constant ---------------------------------------------------------------------

           Month_Days$="31,28,31,30,31,30,31,31,30,31,30,31"

      ' Check Specified Date for Valid Length (6 or 8 Characters) --------------------

           IF ((LEN(Jul_Date$)<>6)  AND _
               (LEN(Jul_Date$)<>8)) THEN
              JUL2GRE$=""
              EXIT FUNCTION
           END IF

      ' Check Specified Date for Digital Value ---------------------------------------

           IF (NOT(DIGITAL%(LEFT$(Jul_Date$,2-(LEN(Jul_Date$)=8))+ _
                           RIGHT$(Jul_Date$,3),""))) THEN
              JUL2GRE$=""
              EXIT FUNCTION
           END IF

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

           Year$=     LEFT$(Jul_Date$,2-2*(LEN(Jul_Date$)=8))
           Day  =VAL(RIGHT$(Jul_Date$,3))

      ' Check Day for Lying within Proper Borders ------------------------------------

           IF (NOT((Day>0) AND _
                   (Day<366-LEAP%(Year$)))) THEN
              JUL2GRE$=""
              EXIT FUNCTION
           END IF

      ' Adjust Number of February Days for the Leap Year -----------------------------

           IF (LEAP%(Year$)) THEN MID$(Month_Days$,5,1)="9"

      ' Compute Gregorian Month Number and Day ---------------------------------------

           DD=Day
           FOR MM=1 TO 12
               MM_Days=VAL(MID$(Month_Days$,3*MM-2,2))
               IF (DD<=MM_Days) THEN EXIT FOR
               DD=DD-MM_Days
           NEXT MM

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

           JUL2GRE$=RIGHT$("0"+LTRIM$(STR$(MM)),2)+"-"+ _
                    RIGHT$("0"+LTRIM$(STR$(DD)),2)+"-"+Year$

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

           END FUNCTION
  
         

 JUL2GRE$  Debugging  Program                       Source program                   Debugging logout

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

        #INCLUDE "JUL2GRE"

        FUNCTION PBMAIN

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

        PRINT "JUL2GRE$(''        )='"; _
               JUL2GRE$(""        );"'"
        PRINT "JUL2GRE$('87-31'   )='"; _
               JUL2GRE$("87-31"   );"'"
        PRINT "JUL2GRE$('1987-31' )='"; _
               JUL2GRE$("1987-31" );"'"
        PRINT "JUL2GRE$('19*7-031')='"; _
               JUL2GRE$("19*7-031");"'"
        PRINT "JUL2GRE$('1988-0#1')='"; _
               JUL2GRE$("1988-0#1");"'"
        PRINT "JUL2GRE$('87-000'  )='"; _
               JUL2GRE$("87-000"  );"'"
        PRINT "JUL2GRE$('87-366'  )='"; _
               JUL2GRE$("87-366"  );"'"
        PRINT "JUL2GRE$('1988-367')='"; _
               JUL2GRE$("1988-367");"'"
        PRINT "JUL2GRE$('87-031'  )='"; _
               JUL2GRE$("87-031"  );"'"
        PRINT "JUL2GRE$('87-059'  )='"; _
               JUL2GRE$("87-059"  );"'"
        PRINT "JUL2GRE$('87-090'  )='"; _
               JUL2GRE$("87-090"  );"'"
        PRINT "JUL2GRE$('87-120'  )='"; _
               JUL2GRE$("87-120"  );"'"
        PRINT "JUL2GRE$('87-151'  )='"; _
               JUL2GRE$("87-151"  );"'"
        PRINT "JUL2GRE$('87-181'  )='"; _
               JUL2GRE$("87-181"  );"'"
        PRINT "JUL2GRE$('87-212'  )='"; _
               JUL2GRE$("87-212"  );"'"
        PRINT "JUL2GRE$('87-243'  )='"; _
               JUL2GRE$("87-243"  );"'"
        PRINT "JUL2GRE$('87-273'  )='"; _
               JUL2GRE$("87-273"  );"'"
        PRINT "JUL2GRE$('87-304'  )='"; _
               JUL2GRE$("87-304"  );"'"
        PRINT "JUL2GRE$('87-334'  )='"; _
               JUL2GRE$("87-334"  );"'"
        PRINT "JUL2GRE$('87-365'  )='"; _
               JUL2GRE$("87-365"  );"'"
        PRINT "JUL2GRE$('1988-031')='"; _
               JUL2GRE$("1988-031");"'"
        PRINT "JUL2GRE$('1988-060')='"; _
               JUL2GRE$("1988-060");"'"
        PRINT "JUL2GRE$('1988-091')='"; _
               JUL2GRE$("1988-091");"'"
        PRINT "JUL2GRE$('1988-121')='"; _
               JUL2GRE$("1988-121");"'"
        PRINT "JUL2GRE$('1988-152')='"; _
               JUL2GRE$("1988-152");"'"
        PRINT "JUL2GRE$('1988-182')='"; _
               JUL2GRE$("1988-182");"'"
        PRINT "JUL2GRE$('1988-213')='"; _
               JUL2GRE$("1988-213");"'"
        PRINT "JUL2GRE$('1988-244')='"; _
               JUL2GRE$("1988-244");"'"
        PRINT "JUL2GRE$('1988-274')='"; _
               JUL2GRE$("1988-274");"'"
        PRINT "JUL2GRE$('1988-305')='"; _
               JUL2GRE$("1988-305");"'"
        PRINT "JUL2GRE$('1988-335')='"; _
               JUL2GRE$("1988-335");"'"
        PRINT "JUL2GRE$('1988-366')='"; _
               JUL2GRE$("1988-366");"'"

        END FUNCTION
  
         

 JUL2GRE$  Debugging  Logout                       Source program                   Debugging program


   JUL2GRE$(0.0)  Convert Julian Date to Gregorian Format  09-18-2016  21:24
   -------------------------------------------------------------------------

   JUL2GRE$(''        )=''
   JUL2GRE$('87-31'   )=''
   JUL2GRE$('1987-31' )=''
   JUL2GRE$('19*7-031')=''
   JUL2GRE$('1988-0#1')=''
   JUL2GRE$('87-000'  )=''
   JUL2GRE$('87-366'  )=''
   JUL2GRE$('1988-367')=''
   JUL2GRE$('87-031'  )='01-31-87'
   JUL2GRE$('87-059'  )='02-28-87'
   JUL2GRE$('87-090'  )='03-31-87'
   JUL2GRE$('87-120'  )='04-30-87'
   JUL2GRE$('87-151'  )='05-31-87'
   JUL2GRE$('87-181'  )='06-30-87'
   JUL2GRE$('87-212'  )='07-31-87'
   JUL2GRE$('87-243'  )='08-31-87'
   JUL2GRE$('87-273'  )='09-30-87'
   JUL2GRE$('87-304'  )='10-31-87'
   JUL2GRE$('87-334'  )='11-30-87'
   JUL2GRE$('87-365'  )='12-31-87'
   JUL2GRE$('1988-031')='01-31-1988'
   JUL2GRE$('1988-060')='02-29-1988'
   JUL2GRE$('1988-091')='03-31-1988'
   JUL2GRE$('1988-121')='04-30-1988'
   JUL2GRE$('1988-152')='05-31-1988'
   JUL2GRE$('1988-182')='06-30-1988'
   JUL2GRE$('1988-213')='07-31-1988'
   JUL2GRE$('1988-244')='08-31-1988'
   JUL2GRE$('1988-274')='09-30-1988'
   JUL2GRE$('1988-305')='10-31-1988'
   JUL2GRE$('1988-335')='11-30-1988'
   JUL2GRE$('1988-366')='12-31-1988'
        

         

View [and save] JUL2GRE.BAS text       View [and save] ZJUL2GRE.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