Y2K Site Map | Terms of Use | Problem | Steps | Certification | Briefings | Compliance | Solutions | BIOS | Test & Evaluation | Cost
The following Y2K material has been kept available by MITRE for historical purposes only and has not been updated unless noted.
![]() | Leap Year Calculation |
There is really no reason for deviating from normal programming approaches for performing leap year calculations. The simple expression:
if (year mod 4 != 0){use 28 for days in February}else if (year mod 400 == 0){use 29 for days in February}else if (year mod 100 == 0){use 28 for days in February}else{use 29 for days in February}
may be expressed in pseudo C, but anyone can probably understand it. How this arises in date calculations is in reporting for human readability or in using the input date as input to sorting or searching for particular information of interest. The problem being solved is that computers use numbers for dates, using what is called internal representation. This uses ordinals or positive integers for days since some base date, which is a property of the particular representation being used to store data and perform useful operations.
One common standard solution is to try to avoid conversions, for example by using four digit years in the internal representation. This is okay for some purposes, but not all. For example, human interface may have been intended to be user friendly and supply the century, so that the actual input has just two digit years. The other issue is that the rest of the date fields (e.g., two digits for the month and the day in the month) may not be very convenient for doing the necessary operations. The whole eight digits also may not be very convenient for long-term storage. This of course is the Y2K problem.
More convenient representations have particular characteristics that they do not have to mean what they seem. The use of a linear form (fixed base + ordinal offset) means that the data cannot be understood or interpreted without some knowledge of the conversions chosen to encode or represent it. One example of this kind of conversion that fits extremely well with the linear form is called a sliding window, for which conversions are discussed elsewhere.
Many other representations are possible, of which perhaps the most easily described is the use of Julian date, as discussed elsewhere. The advantage is that the day is already ordinal; the disadvantage is that the year still has to have some base value that is a property of the representation and thereby the endcoding via conversions. So the issue is not really different.
For More InformationIf you would like to know the rules for determining whether or not the current year is a leap year, see Calculating Leap Years Correctly on our Y2K Problem page. For additional information on leap years and how they came about, see the leap year explanation. For testing leap year abilities for PCs, see our Testing Leap Year page.
Information is provided by the MITRE Y2K Team Last modified: Thursday, 14-Feb-2008 09:21:05 EST
|