home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / leapyear.prg < prev    next >
Text File  |  1994-08-29  |  2KB  |  93 lines

  1. /*
  2.  * File......: LEAPYEAR.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..: 2.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.  *  2.0 - Corrected bug in year type
  19.  *  2.1 - 19/10/93 - Changed calls from CTOD to GT_STOD
  20.  */
  21.  
  22.  
  23. /*  $DOC$
  24.  *  $FUNCNAME$
  25.  *      GT_LEAPYEAR()
  26.  *  $CATEGORY$
  27.  *      Date
  28.  *  $ONELINER$
  29.  *      Find out if a date is in a leap year
  30.  *  $SYNTAX$
  31.  *      GT_LeapYear( dDate )
  32.  *  $ARGUMENTS$
  33.  *      dDate - Date to consider - defaults to current date
  34.  *  $RETURNS$
  35.  *      .T. if the date is in a leap year
  36.  *      .F. otherwise
  37.  *  $DESCRIPTION$
  38.  *      Sees if the date that is one day after Feb 28th in the given year
  39.  *      is Feb 29th.  If it is, then we have a leap year.
  40.  *  $EXAMPLES$
  41.  *
  42.  *  $SEEALSO$
  43.  *
  44.  *  $INCLUDE$
  45.  *
  46.  *  $END$
  47.  */
  48. *
  49. #include "GT_LIB.CH"
  50.  
  51. FUNCTION GT_LeapYear( dDate )
  52.  
  53. /*****************************************************************************
  54.  Purpose - See if the given date falls within a leap year
  55.  Returns - True if in a leap year
  56.  Author  - Martin Colloby
  57.  Created - 4/9/90
  58. ******************************************************************************
  59.  Parameters - dDate      - Date to consider
  60.  Locals     - dDate1     - Test date
  61.               lReturn    - Flag to return
  62.               nYear      - Year of date
  63.  Privates   - None
  64.  Externals  - None
  65. *****************************************************************************/
  66.  
  67. LOCAL dDate1
  68. LOCAL lReturn := .F.
  69. LOCAL nYear   := 0
  70.  
  71. DEFAULT dDate TO DATE()
  72.  
  73. IF VALTYPE( dDate ) != "D"
  74.     GT_Warning( "Invalid date type passed to GT_LeapYear !" )
  75.     RETURN NIL
  76. ENDIF
  77.  
  78. * Find year of p_date
  79. nYear := YEAR( dDate )
  80.  
  81. * Set test date to 28/2/m_year of p_date
  82. dDate1 := GT_STOD( ALLTRIM( STR( nYear ) ) + "0228" )
  83.  
  84. * If the day after 28/2/m_year is 29/2/m_year then p_date is on a leap year
  85. IF dDate1++ == GT_STOD( ALLTRIM( STR( nYear ) ) + "0228" )
  86.     RETURN( .T. )
  87. ELSE
  88.     RETURN( .F. )
  89. ENDIF
  90.  
  91. RETURN NIL
  92. *
  93.