Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /****************************************************************************
  2. *
  3. *                            Open Watcom Project
  4. *
  5. *    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
  6. *
  7. *  ========================================================================
  8. *
  9. *    This file contains Original Code and/or Modifications of Original
  10. *    Code as defined in and that are subject to the Sybase Open Watcom
  11. *    Public License version 1.0 (the 'License'). You may not use this file
  12. *    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
  13. *    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
  14. *    provided with the Original Code and Modifications, and is also
  15. *    available at www.sybase.com/developer/opensource.
  16. *
  17. *    The Original Code and all software distributed under the License are
  18. *    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
  19. *    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
  20. *    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
  21. *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
  22. *    NON-INFRINGEMENT. Please see the License for the specific language
  23. *    governing rights and limitations under the License.
  24. *
  25. *  ========================================================================
  26. *
  27. * Description:  Check if a year is a leap year + associated arrays
  28. *
  29. ****************************************************************************/
  30.  
  31. #include "variety.h"
  32. #include <time.h>
  33. #include "rtdata.h"
  34. #include "timedata.h"
  35.  
  36. short const __based(__segname("_CONST")) __diyr[] = { /* days in normal year array */
  37.     0,                                                          /* Jan */
  38.     31,                                                         /* Feb */
  39.     31 + 28,                                                    /* Mar */
  40.     31 + 28 + 31,                                               /* Apr */
  41.     31 + 28 + 31 + 30,                                          /* May */
  42.     31 + 28 + 31 + 30 + 31,                                     /* Jun */
  43.     31 + 28 + 31 + 30 + 31 + 30,                                /* Jul */
  44.     31 + 28 + 31 + 30 + 31 + 30 + 31,                           /* Aug */
  45.     31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,                      /* Sep */
  46.     31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,                 /* Oct */
  47.     31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,            /* Nov */
  48.     31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,       /* Dec */
  49.     31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31   /* Jan, next year */
  50. };
  51.  
  52. short const __based(__segname("_CONST")) __dilyr[] = { /* days in leap year array */
  53.     0,                                                          /* Jan */
  54.     31,                                                         /* Feb */
  55.     31 + 29,                                                    /* Mar */
  56.     31 + 29 + 31,                                               /* Apr */
  57.     31 + 29 + 31 + 30,                                          /* May */
  58.     31 + 29 + 31 + 30 + 31,                                     /* Jun */
  59.     31 + 29 + 31 + 30 + 31 + 30,                                /* Jul */
  60.     31 + 29 + 31 + 30 + 31 + 30 + 31,                           /* Aug */
  61.     31 + 29 + 31 + 30 + 31 + 30 + 31 + 31,                      /* Sep */
  62.     31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30,                 /* Oct */
  63.     31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,            /* Nov */
  64.     31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,       /* Dec */
  65.     31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31   /* Jan, next year */
  66. };
  67.  
  68. int __leapyear( unsigned year )
  69. {
  70.     if( year & 3 )
  71.         return( 0 );
  72.     if( ( year % 100 ) != 0 )
  73.         return( 1 );
  74.     if( ( year % 400 ) == 0 )
  75.         return( 1 );
  76.     return( 0 );
  77. }
  78.