Template:Processing dates with two-digit year values: Difference between revisions
(Created page with "<!-- transcluded by at least Sir2000 UL Tools and "Datetime string formats" --> A date field with only two digits for the year value is capable of representing a range of up t...") |
m (change graphic-file types and size) |
||
Line 7: | Line 7: | ||
===Using CENTSPAN=== | ===Using CENTSPAN=== | ||
<var>CENTSPAN</var> provides a mechanism for unambiguously converting dates with | <var>CENTSPAN</var> provides a mechanism for unambiguously converting dates with two-digit year values into dates with four-digit year values. | ||
two-digit year values into dates with four-digit year values. | The <var>CENTSPAN</var> mechanism allows two-digit year values to span two centuries without confusion. <var>CENTSPAN</var> identifies the four-digit year value that is the ''start'' of a range of years represented by the two-digit year values. | ||
The <var>CENTSPAN</var> mechanism allows two-digit year values to span two centuries without confusion. | |||
<var>CENTSPAN</var> identifies the four-digit year value that is the ''start'' | |||
of a range of years represented by the two-digit year values. | |||
<var>CENTSPAN</var> may be specified as an ''absolute'' unsigned four-digit | <var>CENTSPAN</var> may be specified as an ''absolute'' unsigned four-digit | ||
Line 19: | Line 16: | ||
The effective <var>CENTSPAN</var> value is formed by adding the relative <var>CENTSPAN</var> to the current four-digit year value at the time the relative value is converted. | The effective <var>CENTSPAN</var> value is formed by adding the relative <var>CENTSPAN</var> to the current four-digit year value at the time the relative value is converted. | ||
<p class="figure"> | <p class="figure"> | ||
[[File: | [[File:Centspan1.png|532px]] | ||
</p> | </p> | ||
Line 31: | Line 28: | ||
values can cause significant confusion and result in data integrity errors. | 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. | This is because dates just above and just below the 100-year window are mapped to the other end of the window. | ||
From | 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. | as 1947, when it could have conceivably been 2047. Simlarly, the date "46" will be interpreted as 2046, when it might have been 1946. | ||
<p class="figure"> | <p class="figure"> | ||
[[File: | [[File:Centspan2.png|330px]] | ||
</p> | </p> | ||
Line 45: | Line 42: | ||
<var>SPANSIZE</var> is used to restrict the size of the window used for mapping two-digit year values. | <var>SPANSIZE</var> 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 | The effect is to create two ''guard bands''', one just below the | ||
date window and one just above. | date window and one just above. An attempt to represent a date value that lands in a guard band produces an error. | ||
An attempt to represent a date value that lands in a guard band produces an error. | |||
Each guard band contains <code>CENTSPAN - SPANSIZE</code> years, hence a <var>SPANSIZE</var> of 100 removes the protection. | Each guard band contains <code>CENTSPAN - SPANSIZE</code> years, hence a <var>SPANSIZE</var> of 100 removes the protection. The default <var>SPANSIZE</var> is a value that you can customize in your load module. | ||
The default <var>SPANSIZE</var> is a value that you can customize in your load module. | If you do not customize it, the value of <var>SPANSIZE</var> is 90, which provides protection for two ten-year windows: one below the <var>CENTSPAN</var> setting and one starting at <code>CENTSPAN+90</code>. | ||
If you do not customize it, the value of <var>SPANSIZE</var> is 90, which provides protection | From the previous example: | ||
for two ten-year windows: one below the <var>CENTSPAN</var> setting and one starting at <code>CENTSPAN+90</code>. | |||
From | |||
<p class="figure"> | <p class="figure"> | ||
[[File: | [[File:Spansize.png|350px]] | ||
</p> | </p> | ||
An attempt to represent the values "37" through "46" is rejected. | 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. | 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 <var>SPANSIZE</var> provides the highest assurance of correct mappings. | ||
Note that an intended value of 2047, expressed as "47" will be accepted and interpreted as 1947. | However, any setting of <var>SPANSIZE</var> less than 100 will probably detect the case where a range greater than one hundred years is being used. | ||
In general a smaller <var>SPANSIZE</var> provides the highest assurance of correct mappings. | |||
However, any setting of <var>SPANSIZE</var> less than 100 will probably detect the | |||
case where a range greater than one hundred years is being used. |
Latest revision as of 21:53, 31 January 2018
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.