home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / progmisc / nfsrc21.zip / DAYOFYR.PRG < prev    next >
Text File  |  1992-09-28  |  4KB  |  123 lines

  1. /*
  2.  * File......: DAYOFYR.PRG
  3.  * Author....: Jo W. French dba Practical Computing
  4.  * CIS_ID....: 74731,1751
  5.  * Date......: $Date:   28 Sep 1992 00:35:20  $
  6.  * Revision..: $Revision:   1.3  $
  7.  * Log file..: $Logfile:   C:/nanfor/src/dayofyr.prv  $
  8.  * 
  9.  * The functions contained herein are the original work of Jo W. French
  10.  * and are placed in the public domain.
  11.  *
  12.  * Modification history:
  13.  * ---------------------
  14.  *
  15.  * $Log:   C:/nanfor/src/dayofyr.prv  $
  16.  * 
  17.  *    Rev 1.3   28 Sep 1992 00:35:20   GLENN
  18.  * Jo French clean up.
  19.  * 
  20.  *    Rev 1.2   15 Aug 1991 23:03:08   GLENN
  21.  * Forest Belt proofread/edited/cleaned up doc
  22.  * 
  23.  *    Rev 1.1   10 May 1991 23:59:38   GLENN
  24.  * Minor adjustment to header.
  25.  * 
  26.  *    Rev 1.0   01 Apr 1991 01:01:02   GLENN
  27.  * Nanforum Toolkit
  28.  *
  29.  */
  30.  
  31. /*  $DOC$
  32.  *  $FUNCNAME$
  33.  *     FT_DAYOFYR()
  34.  *  $CATEGORY$
  35.  *     Date/Time
  36.  *  $ONELINER$
  37.  *     Return calendar, fiscal or accounting day data
  38.  *  $SYNTAX$
  39.  *     FT_DAYOFYR( [ <dGivenDate> ], [ <nDayNum> ], [ <lIsAcct> ] ) 
  40.  *            -> aDateInfo
  41.  *  $ARGUMENTS$
  42.  *     <dGivenDate> is any valid date in any valid format.  Defaults
  43.  *     to current system date if not supplied.
  44.  *
  45.  *     <nDayNum> is a number from 1 to 371, signifying a day of a year.
  46.  *     Defaults to current day if not supplied.
  47.  *
  48.  *     <lIsAcct> is a logical which specifies the type of year to base
  49.  *     the return value on:  .F. = calendar or fiscal year,
  50.  *     .T. = accounting year.
  51.  *  $RETURNS$
  52.  *     A three element array containing the following data:
  53.  *
  54.  *        If <nDayNum> is specified:
  55.  *
  56.  *        aDateInfo[1] - The date of the specified day number
  57.  *        aDateInfo[2] - The beginning date of the year
  58.  *        aDateInfo[3] - The ending date of the year
  59.  *
  60.  *        If <nDayNum> is not specified:
  61.  *
  62.  *        aDateInfo[1] - The year and day as a character string "YYYYDDD"
  63.  *        aDateInfo[2] - The beginning date of the year
  64.  *        aDateInfo[3] - The ending date of the year
  65.  *  $DESCRIPTION$
  66.  *     FT_DAYOFYR() returns an array containing data about a day in the
  67.  *     calendar or fiscal year containing the given date.
  68.  *
  69.  *     The beginning of year date defaults to January 1st but may be
  70.  *     changed with FT_DATECNFG().
  71.  *  $EXAMPLES$
  72.  *     aDateInfo := FT_DAYOFYR( CTOD("03/31/91") )
  73.  *     ? aDateInfo[1]        // 1991090    (90th day of year 1991)
  74.  *     ? aDateInfo[2]        // 01/01/91
  75.  *     ? aDateInfo[3]        // 12/31/91
  76.  *
  77.  *     aDateInfo := FT_DAYOFYR( , 90 )    // assume current date is 3/31/91
  78.  *     ? aDateInfo[1]        // 03/31/91    (90th day of year)
  79.  *     ? aDateInfo[2]        // 01/01/91
  80.  *     ? aDateInfo[3]        // 12/31/91
  81.  *
  82.  *     aDateInfo := FT_DAYOFYR( , 90, .T. )
  83.  *     ? aDateInfo[1]        // 03/29/91    (90th day of accounting year)
  84.  *     ? aDateInfo[2]        // 12/30/90    (1st day of accounting year)
  85.  *     ? aDateInfo[3]        // 12/28/91    (last day of accounting year)
  86.  *  $SEEALSO$
  87.  *     FT_DATECNFG()
  88.  *  $END$
  89. */
  90.  
  91. FUNCTION FT_DAYOFYR( dGivenDate, nDayNum, lIsAcct)
  92.   LOCAL lIsDay, nTemp, aRetVal
  93.  
  94.   IF !(VALTYPE(dGivenDate) $ 'NDL')
  95.      dGivenDate := DATE()
  96.   ELSEIF VALTYPE(dGivenDate) == 'N'
  97.      nDayNum    := dGivenDate
  98.      dGivenDate := DATE()
  99.   ELSEIF VALTYPE(dGivenDate) == 'L'
  100.      lIsAcct    := dGivenDate
  101.      dGivenDate := DATE()
  102.   ENDIF
  103.  
  104.   lIsDay  := VALTYPE(nDayNum) == 'N'
  105.   lIsAcct := VALTYPE(lIsAcct) == 'L'
  106.  
  107.   IF lIsAcct
  108.      aRetVal := FT_ACCTYEAR(dGivenDate)
  109.   ELSE
  110.      aRetVal := FT_YEAR(dGivenDate)
  111.   ENDIF
  112.  
  113.   IF lIsDay
  114.      nTemp := aRetVal[3] - aRetVal[2] + 1
  115.      IF(nDayNum < 1 .OR. nDayNum > nTemp , nDayNum := nTemp, )
  116.      aRetVal[1] := aRetVal[2] + nDayNum - 1
  117.   ELSE
  118.      aRetVal[1] += PADL(LTRIM(STR( dGivenDate - aRetVal[2] + 1, 3)), 3, '0')
  119.   ENDIF
  120.  
  121. RETURN aRetVal
  122.  
  123.