PDA

View Full Version : Leap Year Testing



daly.michael@verizon.net
01-01-1995, 02:00 AM
Most people are satisfied with their "divide by 4" check to see if a year contains a February 19th. But lately, with the onslought of January 1, 2000, many people are hearing that they have to carry that check one step further and check to see if the year is a century marker. Actually, this is still one step short of complete leap year testing. The actual formula goes something like this: <pre> If Year is divisible by 4 and not divisible by 100 it is a leap year or is divisible by 100 and is divisible by 400 it is a leap year</pre> What it means is, years 400, 800, 1200, 1600, and 2000 ARE leap years, while all other centuries (1700, 1800, 1900, 2100) are not. Barring this constriction, divide by four to find a leap year. Below is a snippet of code from a leap year testing program. <pre> C IYR4 DIV 4 Dummy C MVR Dummy C If Dummy = 0 C IYR4 DIV 100 Dummy C MVR Dummy C If Dummy = 0 C IYR4 DIV 400 Dummy C MVR Dummy C If Dummy = 0 C Eval *IN92 = *On C Else C Eval *IN92 = *Off C EndIf C Else C Eval *IN92 = *On C EndIf C Else C Eval *IN92 = *Off C EndIf</pre> Michael Daly One day, we'll all be heroes.

T.Holt
10-06-1998, 12:46 PM
Some folks say there will be Y2K problems because so many programmers just divide by 4 to check for a leap year. It just so happens that that won't be a problem with 2000, for just the reason you mentioned. So maybe there won't be so many Y2K problems of this sort after all.<HR><font > color=blue> On Monday, October 05, 1998, 07:30 AM, Michael Daly wrote: Most people are satisfied with their "divide by 4" check to see if a year contains a February 29th.</font>

daly.michael@verizon.net
10-06-1998, 01:08 PM
On Tuesday, October 06, 1998, 12:46 PM, Ted Holt wrote: Some folks say there will be Y2K problems because so many programmers just divide by 4 to check for a leap year. It just so happens that that won't be a problem with 2000, for just the reason you mentioned. So maybe there won't be so many Y2K problems of this sort after all. Let's hope not! One day, we'll all be heroes.

Guest.Visitor
10-07-1998, 06:44 AM
Correct. When talking about leap year I usually point out that most programs I've seen get the "right answer" but for the wrong reason; and then go off and discuss the correct way to determine leap year...