calculating leap years

fgd3 at jc3b21.UUCP fgd3 at jc3b21.UUCP
Wed Oct 15 13:38:29 AEST 1986


In article <813 at ethos.UUCP>, ggw at ethos.UUCP (Gregory Woodbury) writes:
> In at least one industrial control system, there is going to be a discrepancy
> between the VAXen and their comm controllers.  I had modified the comm system
> date routines to handle the 2000 non-leap year...
> ------------------------------------------
> Gregory G. Woodbury				The usual disclaimers apply
> Red Wolfe Software and Services, Durham, NC
> {duke|mcnc|rti-sel}!ethos!ggw

     Let's get this straight.  The year 2000 will be a leap year.  The
years 1900 and 2100 are not leap years.  The rule is a year is a leap year
if it is evenly divisible by 4 and is not divisible by 100 EXCEPT FOR THOSE
CENTURY YEARS WHICH ARE DIVISIBLE BY 400.

     One of the reasons it is important to write date handling functions
correctly is there aren't enough people who understand the rule.  Let's
give them a correct function and let them copy it.  There is a very
readable date conversion function in K&R, first discussed on pages 103-105,
then again on pages 119-120.  The part that determines whether a year is a
leap year is

{
     int leap, year;
     leap = year%4 == 0 && year%100 !=0 || year%400 == 0;
}

     I hope that will save someone from getting bitten by a wrong
calculation.

Fabbian Dufoe
  350 Ling-A-Mor Terrace South
  St. Petersburg, Florida  33705
  813-823-2350

UUCP: ...akgua!akguc!codas!peora!ucf-cs!usfvax2!jc3b21!fgd3 



More information about the Comp.lang.c mailing list