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

  1. /*
  2.  * File......: WEEK.PRG
  3.  * Author....: Jo W. French dba Practical Computing
  4.  * CIS ID....: 74731,1751
  5.  * Date......: $Date:   28 Sep 1992 00:44:52  $
  6.  * Revision..: $Revision:   1.3  $
  7.  * Log file..: $Logfile:   C:/nanfor/src/week.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/week.prv  $
  16.  * 
  17.  *    Rev 1.3   28 Sep 1992 00:44:52   GLENN
  18.  * Jo French cleaned up and correct to bow().
  19.  * 
  20.  *    Rev 1.2   15 Aug 1991 23:05:26   GLENN
  21.  * Forest Belt proofread/edited/cleaned up doc
  22.  * 
  23.  *    Rev 1.1   14 Jun 1991 19:53:16   GLENN
  24.  * Minor edit to file header
  25.  * 
  26.  *    Rev 1.0   01 Apr 1991 01:02:30   GLENN
  27.  * Nanforum Toolkit
  28.  *
  29.  */
  30.  
  31. /*  $DOC$
  32.  *  $FUNCNAME$
  33.  *     FT_WEEK()
  34.  *  $CATEGORY$
  35.  *     Date/Time
  36.  *  $ONELINER$
  37.  *     Return calendar or fiscal week data
  38.  *  $SYNTAX$
  39.  *     FT_WEEK( [ <dGivenDate> ], [ <nWeekNum> ] ) -> aDateinfo
  40.  *  $ARGUMENTS$
  41.  *     <dGivenDate> is any valid date in any date format.  Defaults
  42.  *     to current system date if not supplied.
  43.  *
  44.  *     <nWeekNum> is a number from 1 to 53 signifying a week.
  45.  *     Defaults to current week if not supplied.
  46.  *  $RETURNS$
  47.  *     A three element array containing the following data:
  48.  *
  49.  *        aDateInfo[1] - The year and week as a character string "YYYYWW"
  50.  *        aDateInfo[2] - The beginning date of the week
  51.  *        aDateInfo[3] - The ending date of the week
  52.  *  $DESCRIPTION$
  53.  *     FT_WEEK() returns an array containing data about the week
  54.  *     containing the given date.
  55.  *
  56.  *     Normally the return data will be based on a year beginning
  57.  *     on January 1st with weeks beginning on Sunday.
  58.  *
  59.  *     The beginning of year date and/or beginning of week day can be
  60.  *     changed by using FT_DATECNFG(), which will affect all subsequent
  61.  *     calls to FT_WEEK() until another call to FT_DATECNFG().
  62.  *
  63.  *     The beginning of year date and beginning of week day may be reset
  64.  *     to January 1 and Sunday by calling FT_DATECNFG() with no
  65.  *     parameters.
  66.  *  $EXAMPLES$
  67.  *     // get info about week containing 9/15/90
  68.  *     aDateInfo := FT_WEEK( CTOD("09/15/90") )
  69.  *     ? aDateInfo[1]   //  199037       (37th week)
  70.  *     ? aDateInfo[2]   //  09/09/90     beginning of week 37
  71.  *     ? aDateInfo[3]   //  09/15/90     end of week 37
  72.  *
  73.  *     // get info about week 25 in year containing 9/15/90
  74.  *     aDateInfo := FT_WEEK( CTOD("09/15/90"), 25 )
  75.  *     ? aDateInfo[1]   //  199025
  76.  *     ? aDateInfo[2]   //  06/17/90   beginning of week 25
  77.  *     ? aDateInfo[3]   //  06/23/90   end of week 25
  78.  *
  79.  *     // get info about week 25 in current year( 1991 )
  80.  *     aDateInfo := FT_WEEK( , 25 )
  81.  *     ? aDateInfo[1]   //  199025
  82.  *     ? aDateInfo[2]   //  06/16/91   beginning of week 25
  83.  *     ? aDateInfo[3]   //  06/22/91   end of week 25
  84.  *  $SEEALSO$
  85.  *     FT_DATECNFG() FT_MONTH() FT_QTR() FT_YEAR() FT_DAYTOBOW()
  86.  *  $END$
  87. */
  88.  
  89. FUNCTION FT_WEEK( dGivenDate, nWeekNum )
  90. LOCAL lIsWeek, nTemp, aRetVal, dTemp
  91.  
  92.   IF ! (VALTYPE(dGivenDate) $ 'ND')
  93.      dGivenDate := DATE()
  94.   ELSEIF VALTYPE(dGivenDate) == 'N'
  95.      nWeekNum   := dGivenDate
  96.      dGivenDate := DATE()
  97.   ENDIF
  98.  
  99.   aRetVal    := FT_YEAR(dGivenDate)
  100.   dTemp      := aRetVal[2]
  101.   aRetVal[2] -= FT_DAYTOBOW( aRetVal[2] )
  102.  
  103.   lIsWeek := ( VALTYPE(nWeekNum) == 'N' )
  104.   IF lIsWeek
  105.      nTemp := INT( (aRetVal[3] - aRetVal[2]) / 7 ) + 1
  106.      IF(nWeekNum < 1 .OR. nWeekNum > nTemp , nWeekNum := nTemp, )
  107.      dGivenDate := aRetVal[2] + (nWeekNum - 1) * 7
  108.   ENDIF
  109.  
  110.   dGivenDate += ( 6 - FT_DAYTOBOW(dGivenDate) )       // end of week
  111.  
  112.   aRetVal[1] += PADL(LTRIM(STR(INT( (dGivenDate - ;
  113.                 aRetVal[2]) / 7 ) + 1, 2)), 2, '0')
  114.   aRetVal[2] := MAX( dGivenDate - 6, dTemp )
  115.   aRetVal[3] := MIN( dGivenDate, aRetVal[3] )
  116.  
  117. RETURN aRetVal
  118.  
  119.