aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/datetime.c
diff options
context:
space:
mode:
authorThomas G. Lockhart <lockhart@fourpalms.org>1999-04-15 02:22:39 +0000
committerThomas G. Lockhart <lockhart@fourpalms.org>1999-04-15 02:22:39 +0000
commitb2b3d5d184455acdc3cd91d083a0d2403af6c847 (patch)
tree7a375bff9550c579966cd417f82cd902f4a7b27d /src/backend/utils/adt/datetime.c
parent64e74e30b51ba626edf4cd0147a3ff7f98469e69 (diff)
downloadpostgresql-b2b3d5d184455acdc3cd91d083a0d2403af6c847.tar.gz
postgresql-b2b3d5d184455acdc3cd91d083a0d2403af6c847.zip
Fix code to check legal dates *before* calling localtime() to get the
time zone. Previously, localtime() rotated a date with a day of month field which exceeded the actual range into the next months, masking the fact that a bad date had been specified. Regression tests pass.
Diffstat (limited to 'src/backend/utils/adt/datetime.c')
-rw-r--r--src/backend/utils/adt/datetime.c36
1 files changed, 3 insertions, 33 deletions
diff --git a/src/backend/utils/adt/datetime.c b/src/backend/utils/adt/datetime.c
index c0fcf54e055..bdc4b589d28 100644
--- a/src/backend/utils/adt/datetime.c
+++ b/src/backend/utils/adt/datetime.c
@@ -7,7 +7,7 @@
*
*
* IDENTIFICATION
- * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.30 1999/03/14 16:40:15 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.31 1999/04/15 02:22:37 thomas Exp $
*
*-------------------------------------------------------------------------
*/
@@ -27,19 +27,6 @@
static int date2tm(DateADT dateVal, int *tzp, struct tm * tm, double *fsec, char **tzn);
-#define UTIME_MINYEAR (1901)
-#define UTIME_MINMONTH (12)
-#define UTIME_MINDAY (14)
-#define UTIME_MAXYEAR (2038)
-#define UTIME_MAXMONTH (01)
-#define UTIME_MAXDAY (18)
-
-#define IS_VALID_UTIME(y,m,d) (((y > UTIME_MINYEAR) \
- || ((y == UTIME_MINYEAR) && ((m > UTIME_MINMONTH) \
- || ((m == UTIME_MINMONTH) && (d >= UTIME_MINDAY))))) \
- && ((y < UTIME_MAXYEAR) \
- || ((y == UTIME_MAXYEAR) && ((m < UTIME_MAXMONTH) \
- || ((m == UTIME_MAXMONTH) && (d <= UTIME_MAXDAY))))))
/*****************************************************************************
* Date ADT
@@ -71,7 +58,7 @@ date_in(char *str)
#endif
if ((ParseDateTime(str, lowstr, field, ftype, MAXDATEFIELDS, &nf) != 0)
|| (DecodeDateTime(field, ftype, nf, &dtype, tm, &fsec, &tzp) != 0))
- elog(ERROR, "Bad date external representation %s", str);
+ elog(ERROR, "Bad date external representation '%s'", str);
switch (dtype)
{
@@ -89,19 +76,9 @@ date_in(char *str)
break;
default:
- elog(ERROR, "Unrecognized date external representation %s", str);
+ elog(ERROR, "Unrecognized date external representation '%s'", str);
}
-#ifdef NOT_USED
- if (tm->tm_year < 0 || tm->tm_year > 32767)
- elog(ERROR, "date_in: year must be limited to values 0 through 32767 in '%s'", str);
- if (tm->tm_mon < 1 || tm->tm_mon > 12)
- elog(ERROR, "date_in: month must be limited to values 1 through 12 in '%s'", str);
-#endif
- if (tm->tm_mday < 1 || tm->tm_mday > day_tab[isleap(tm->tm_year)][tm->tm_mon - 1])
- elog(ERROR, "date_in: day must be limited to values 1 through %d in '%s'",
- day_tab[isleap(tm->tm_year)][tm->tm_mon - 1], str);
-
date = (date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - date2j(2000, 1, 1));
return date;
@@ -453,13 +430,6 @@ time_in(char *str)
|| (DecodeTimeOnly(field, ftype, nf, &dtype, tm, &fsec) != 0))
elog(ERROR, "Bad time external representation '%s'", str);
- if ((tm->tm_hour < 0) || (tm->tm_hour > 23))
- elog(ERROR, "Hour must be limited to values 0 through 23 in '%s'", str);
- if ((tm->tm_min < 0) || (tm->tm_min > 59))
- elog(ERROR, "Minute must be limited to values 0 through 59 in '%s'", str);
- if ((tm->tm_sec < 0) || ((tm->tm_sec + fsec) >= 60))
- elog(ERROR, "Second must be limited to values 0 through < 60 in '%s'", str);
-
time = palloc(sizeof(TimeADT));
*time = ((((tm->tm_hour * 60) + tm->tm_min) * 60) + tm->tm_sec + fsec);