Commit 7b7d8e95 authored by Peter Moulder's avatar Peter Moulder Committed by Arturo Espinosa

Currently, two-digit years are converted to four-digit years (ccyy) by

1999-12-28  Peter Moulder <reiter@netspace.net.au>

	* src/number-match.c: Currently, two-digit years are converted to
	four-digit years (ccyy) by assuming that cc is the same as in the
	current wall date.  The problem with that is that on 1999-12-31,
	entering any future dates in two-digit-year form will be
	misinterpreted; while on 2000-01-01, any past dates entered in
	two-digit form will be misinterpreted.  (I use the term
	"misinterpreted" with the assumption that one is much more likely
	to intend a date a few days away than 99 years away.)
parent b65f5041
1999-12-28 Peter Moulder <reiter@netspace.net.au>
* src/number-match.c: Currently, two-digit years are converted to
four-digit years (ccyy) by assuming that cc is the same as in the
current wall date. The problem with that is that on 1999-12-31,
entering any future dates in two-digit-year form will be
misinterpreted; while on 2000-01-01, any past dates entered in
two-digit form will be misinterpreted. (I use the term
"misinterpreted" with the assumption that one is much more likely
to intend a date a few days away than 99 years away.)
1999-12-27 Jody Goldberg <jgoldberg@home.com>
* configure.in : Re-enable the python plugin by default.
......
1999-12-28 Peter Moulder <reiter@netspace.net.au>
* src/number-match.c: Currently, two-digit years are converted to
four-digit years (ccyy) by assuming that cc is the same as in the
current wall date. The problem with that is that on 1999-12-31,
entering any future dates in two-digit-year form will be
misinterpreted; while on 2000-01-01, any past dates entered in
two-digit form will be misinterpreted. (I use the term
"misinterpreted" with the assumption that one is much more likely
to intend a date a few days away than 99 years away.)
1999-12-27 Jody Goldberg <jgoldberg@home.com>
* configure.in : Re-enable the python plugin by default.
......
......@@ -662,10 +662,61 @@ compute_value (const char *s, const regmatch_t *mp,
if (!(year == -1 && month == -1 && day == -1)){
if (year == -1){
if (year_short != -1){
if (tm->tm_year > 99)
year = 2000 + year_short;
else
year = 1900 + year_short;
/* Window of -75 thru +24 years. */
/* (TODO: See what current
* version of MS Excel uses.) */
/* Earliest allowable interpretation
* is 75 years ago. */
int earliest_ccyy
= tm->tm_year + 1900 - 75;
int earliest_cc = earliest_ccyy / 100;
g_return_val_if_fail(year_short >= 0 &&
year_short <= 99,
FALSE);
year = earliest_cc * 100 + year_short;
/*
* Our first guess at year has the same
* cc part as EARLIEST_CCYY, so is
* guaranteed to be in [earliest_ccyy -
* 99, earliest_ccyy + 99]. The yy
* part is of course year_short.
*/
if (year < earliest_ccyy)
year += 100;
/*
* year is now guaranteed to be in
* [earliest_ccyy, earliest_ccyy + 99],
* i.e. -75 thru +24 years from current
* year; and year % 100 == short_year.
*/
} else if (month != -1) {
/* Window of -6 thru +5 months. */
/* (TODO: See what current
* version of MS Excel uses.) */
int earliest_yyymm
= (tm->tm_year * 12 +
tm->tm_mon - 6);
year = earliest_yyymm / 12;
/* First estimate of yyy (i.e. years
* since 1900) is the yyy part of
* earliest_yyymm. year*12+month-1 is
* guaranteed to be in [earliest_yyymm
* - 11, earliest_yyymm + 11].
*/
year += (year * 12 + month <=
earliest_yyymm);
/* year*12+month-1 is now guaranteed
* to be in [earliest_yyymm,
* earliest_yyymm + 11], i.e.
* representing -6 thru +5 months
* from now.
*/
year += 1900;
/* Finally convert from years since
* 1900 (yyy) to a proper 4-digit
* year.
*/
} else
year = 1900 + tm->tm_year;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment