home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / endmonth.prg < prev    next >
Text File  |  1993-10-18  |  2KB  |  86 lines

  1. /*
  2.  * File......: ENDMONTH.PRG
  3.  * Author....: Martin Colloby
  4.  * BBS.......: The Dark Knight Returns
  5.  * Net/Node..: 050/069
  6.  * User Name.: Martin Colloby
  7.  * Date......: 18/4/93
  8.  * Revision..: 1.1
  9.  *
  10.  * This is an original work by Martin Colloby and is placed in the public
  11.  * domain.
  12.  *
  13.  * Modification history:
  14.  * ---------------------
  15.  *
  16.  * $Log$
  17.  *  1.0 Original Release
  18.  *  1.1 - 19/10/93 - Changed calls from CTOD to GT_STOD
  19.  */
  20.  
  21.  
  22. /*  $DOC$
  23.  *  $FUNCNAME$
  24.  *      GT_ENDOFMONTH()
  25.  *  $CATEGORY$
  26.  *      Date
  27.  *  $ONELINER$
  28.  *      Find the last weekday of a month
  29.  *  $SYNTAX$
  30.  *      GT_EndOfMonth( dDate )
  31.  *  $ARGUMENTS$
  32.  *      dDate - Date to be considered
  33.  *  $RETURNS$
  34.  *      The last weekday of the month
  35.  *  $DESCRIPTION$
  36.  *      Calculates the last day of the month, and if that is not a weekday,
  37.  *      rolls back until it finds a weekday.
  38.  *  $EXAMPLES$
  39.  *
  40.  *  $SEEALSO$
  41.  *
  42.  *  $INCLUDE$
  43.  *
  44.  *  $END$
  45.  */
  46. *
  47. FUNCTION GT_EndOfMonth( dDate )
  48.  
  49. /*****************************************************************************
  50.  Purpose - Find the last weekday of the given month
  51.  Returns - Calculated date
  52.  Author  - Martin Colloby
  53.  Created - 4/9/90
  54. ******************************************************************************
  55.  Parameters - dDate      - Date to consider
  56.  Locals     - nDay       - Day of dDate
  57.               nMonth     - Month of dDate
  58.               nYear      - Year of dDate
  59.  Privates   - None
  60.  Locals     - None
  61.  Externals  - None
  62. *****************************************************************************/
  63.  
  64. LOCAL dRetDate
  65. LOCAL nDay   := 0
  66. LOCAL nMonth := 0
  67. LOCAL nYear  := 0
  68.  
  69. IF VALTYPE( dDate ) != "D"
  70.     GT_Warning( "Invalid date type passed to GT_EndOfMonth !" )
  71.     RETURN NIL
  72. ENDIF
  73.  
  74. * Initialise the date variables
  75. nMonth := MONTH( dDate )
  76. nYear  := YEAR( dDate )
  77.  
  78. nDay := GT_DaysInMonth( dDate )
  79.  
  80. * Build up new date
  81. dRetDate := GT_STOD( STR( nYear ) + STR( nMonth ) + STR( nDay ) )
  82.  
  83. * Return the nearest week date
  84. RETURN( GT_RollFwd( dRetDate ) )
  85. *
  86.