Template:Processing dates with two-digit year values

From m204wiki
Jump to navigation Jump to search

A date field with only two digits for the year value is capable of representing a range of up to one hundred years. When we compare a pair of two-digit year values, we are accustomed to thinking of the century as fixed, so that all dates are either 19xx or 20xx. However, a date field with two-digit year values can actually represent dates from two different centuries, provided that the range of dates does not exceed 100 years.

Using CENTSPAN

CENTSPAN provides a mechanism for unambiguously converting dates with two-digit year values into dates with four-digit year values. The CENTSPAN mechanism allows two-digit year values to span two centuries without confusion. CENTSPAN identifies the four-digit year value that is the start of a range of years represented by the two-digit year values.

CENTSPAN may be specified as an absolute unsigned four-digit value between 1753 and 9999, or it may be specified as a relative signed value between -99 and +99, inclusive. A relative CENTSPAN value is dynamically converted to an effective absolute value before it is used to perform a YY to YYYY conversion. The effective CENTSPAN value is formed by adding the relative CENTSPAN to the current four-digit year value at the time the relative value is converted.

A simple algorithm is used to convert a two-digit year value (YY) to a four-digit year value, using a four-digit absolute or effective CENTSPAN value (HHLL). If the two-digit year value is less than the low-order two digits of the CENTSPAN value, then the resulting century is one greater than the high-order two digits of the CENTSPAN value. Otherwise the resulting century is the same as the high-order two digits of the CENTSPAN value.

Using all one hundred available years for mapping two-digit year values can cause significant confusion and result in data integrity errors. This is because dates just above and just below the 100-year window are mapped to the other end of the window. From the previous example, the date "47" will be interpreted as 1947, when it could have conceivably been 2047. Simlarly, the date "46" will be interpreted as 2046, when it might have been 1946.

If CENTSPAN is set to a value that is too high, dates that are just prior to CENTSPAN will appear to occur 100 years hence. If CENTSPAN is set to a value that is too low, dates that fall just after CENTSPAN+99 will appear to have occurred 100 years earlier. A full one-hundred year window also can not detect attempts to represent more than one hundred years of values with a two-digit year.

Using SPANSIZE

To protect from the ambiguities that can occur at each end of the 100-year window defined by CENTSPAN, SPANSIZE is used to restrict the size of the window used for mapping two-digit year values. The effect is to create two guard bands', one just below the date window and one just above. An attempt to represent a date value that lands in a guard band produces an error.

Each guard band contains CENTSPAN - SPANSIZE years, hence a SPANSIZE of 100 removes the protection. The default SPANSIZE is a value that you can customize in your load module. If you do not customize it, the value of SPANSIZE is 90, which provides protection for two ten-year windows: one below the CENTSPAN setting and one starting at CENTSPAN+90. From the previous example:

An attempt to represent the values "37" through "46" is rejected. This protects the range 1937 through 1946 as well as the range 2037 through 2046. Note that an intended value of 2047, expressed as "47" will be accepted and interpreted as 1947. In general a smaller SPANSIZE provides the highest assurance of correct mappings. However, any setting of SPANSIZE less than 100 will probably detect the case where a range greater than one hundred years is being used.