Skip to content

Commit 2a6faa5

Browse files
author
Thomas G. Lockhart
committed
This patch fixes some problems in date handling for atypical dates.
Here is a summary: Be more careful to check input string lengths as well as values when deciding whether a field is a year field. Assume *anything* longer than 2 digits (if it isn't a special-case doy) is a valid year. This should fix the "Y1K" and "Y10K" problems pointed out by Massimo recently. Check usage of BC to require a positive-valued year; before just used it to flip the sign of the year without checking. This led to problems near year zero. Allow a 5 digit "concatenated date" of 2 digit year plus day of year. Do 2->4 digit year correction for 6 and 5 digit "concatenated dates". Somehow forgot this originally. Guess not many folks use it... Move common macros to dt.h.
1 parent a0071f1 commit 2a6faa5

File tree

2 files changed

+176
-58
lines changed

2 files changed

+176
-58
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.25.2.1 1998/12/31 16:34:47 thomas Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.25.2.2 1999/02/13 05:59:34 thomas Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -27,12 +27,13 @@
2727

2828
static int date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn);
2929

30-
30+
#if 0
3131
static int day_tab[2][12] = {
3232
{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
3333
{31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}};
3434

3535
#define isleap(y) (((y % 4) == 0 && (y % 100) != 0) || (y % 400) == 0)
36+
#endif
3637

3738
#define UTIME_MINYEAR (1901)
3839
#define UTIME_MINMONTH (12)
@@ -99,10 +100,12 @@ date_in(char *str)
99100
elog(ERROR, "Unrecognized date external representation %s", str);
100101
}
101102

103+
#if 0
102104
if (tm->tm_year < 0 || tm->tm_year > 32767)
103105
elog(ERROR, "date_in: year must be limited to values 0 through 32767 in '%s'", str);
104106
if (tm->tm_mon < 1 || tm->tm_mon > 12)
105107
elog(ERROR, "date_in: month must be limited to values 1 through 12 in '%s'", str);
108+
#endif
106109
if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
107110
elog(ERROR, "date_in: day must be limited to values 1 through %d in '%s'",
108111
day_tab[isleap(tm->tm_year)][tm->tm_mon - 1], str);

0 commit comments

Comments
 (0)