88 *
99 *
1010 * IDENTIFICATION
11- * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.90 2003/08/08 00:10:31 tgl Exp $
11+ * $Header: /cvsroot/pgsql/src/backend/utils/adt/date.c,v 1.91 2003/08/27 23:29:27 tgl Exp $
1212 *
1313 *-------------------------------------------------------------------------
1414 */
@@ -62,20 +62,19 @@ date_in(PG_FUNCTION_ARGS)
6262int tzp ;
6363int dtype ;
6464int nf ;
65+ int dterr ;
6566char * field [MAXDATEFIELDS ];
6667int ftype [MAXDATEFIELDS ];
6768char lowstr [MAXDATELEN + 1 ];
6869
6970if (strlen (str ) >=sizeof (lowstr ))
70- ereport (ERROR ,
71- (errcode (ERRCODE_INVALID_DATETIME_FORMAT ),
72- errmsg ("invalid input syntax for date: \"%s\"" ,str )));
73-
74- if ((ParseDateTime (str ,lowstr ,field ,ftype ,MAXDATEFIELDS ,& nf )!= 0 )
75- || (DecodeDateTime (field ,ftype ,nf ,& dtype ,tm ,& fsec ,& tzp )!= 0 ))
76- ereport (ERROR ,
77- (errcode (ERRCODE_INVALID_DATETIME_FORMAT ),
78- errmsg ("invalid input syntax for date: \"%s\"" ,str )));
71+ dterr = DTERR_BAD_FORMAT ;
72+ else
73+ dterr = ParseDateTime (str ,lowstr ,field ,ftype ,MAXDATEFIELDS ,& nf );
74+ if (dterr == 0 )
75+ dterr = DecodeDateTime (field ,ftype ,nf ,& dtype ,tm ,& fsec ,& tzp );
76+ if (dterr != 0 )
77+ DateTimeParseError (dterr ,str ,"date" );
7978
8079switch (dtype )
8180{
@@ -95,9 +94,8 @@ date_in(PG_FUNCTION_ARGS)
9594break ;
9695
9796default :
98- ereport (ERROR ,
99- (errcode (ERRCODE_INVALID_DATETIME_FORMAT ),
100- errmsg ("invalid input syntax for date: \"%s\"" ,str )));
97+ DateTimeParseError (DTERR_BAD_FORMAT ,str ,"date" );
98+ break ;
10199}
102100
103101date = date2j (tm -> tm_year ,tm -> tm_mon ,tm -> tm_mday )- POSTGRES_EPOCH_JDATE ;
@@ -559,21 +557,20 @@ time_in(PG_FUNCTION_ARGS)
559557* tm = & tt ;
560558int tz ;
561559int nf ;
560+ int dterr ;
562561char lowstr [MAXDATELEN + 1 ];
563562char * field [MAXDATEFIELDS ];
564563int dtype ;
565564int ftype [MAXDATEFIELDS ];
566565
567566if (strlen (str ) >=sizeof (lowstr ))
568- ereport (ERROR ,
569- (errcode (ERRCODE_INVALID_DATETIME_FORMAT ),
570- errmsg ("invalid input syntax for time: \"%s\"" ,str )));
571-
572- if ((ParseDateTime (str ,lowstr ,field ,ftype ,MAXDATEFIELDS ,& nf )!= 0 )
573- || (DecodeTimeOnly (field ,ftype ,nf ,& dtype ,tm ,& fsec ,& tz )!= 0 ))
574- ereport (ERROR ,
575- (errcode (ERRCODE_INVALID_DATETIME_FORMAT ),
576- errmsg ("invalid input syntax for time: \"%s\"" ,str )));
567+ dterr = DTERR_BAD_FORMAT ;
568+ else
569+ dterr = ParseDateTime (str ,lowstr ,field ,ftype ,MAXDATEFIELDS ,& nf );
570+ if (dterr == 0 )
571+ dterr = DecodeTimeOnly (field ,ftype ,nf ,& dtype ,tm ,& fsec ,& tz );
572+ if (dterr != 0 )
573+ DateTimeParseError (dterr ,str ,"time" );
577574
578575tm2time (tm ,fsec ,& result );
579576AdjustTimeForTypmod (& result ,typmod );
@@ -1424,23 +1421,20 @@ timetz_in(PG_FUNCTION_ARGS)
14241421* tm = & tt ;
14251422int tz ;
14261423int nf ;
1424+ int dterr ;
14271425char lowstr [MAXDATELEN + 1 ];
14281426char * field [MAXDATEFIELDS ];
14291427int dtype ;
14301428int ftype [MAXDATEFIELDS ];
14311429
14321430if (strlen (str ) >=sizeof (lowstr ))
1433- ereport (ERROR ,
1434- (errcode (ERRCODE_INVALID_DATETIME_FORMAT ),
1435- errmsg ("invalid input syntax for time with time zone: \"%s\"" ,
1436- str )));
1437-
1438- if ((ParseDateTime (str ,lowstr ,field ,ftype ,MAXDATEFIELDS ,& nf )!= 0 )
1439- || (DecodeTimeOnly (field ,ftype ,nf ,& dtype ,tm ,& fsec ,& tz )!= 0 ))
1440- ereport (ERROR ,
1441- (errcode (ERRCODE_INVALID_DATETIME_FORMAT ),
1442- errmsg ("invalid input syntax for time with time zone: \"%s\"" ,
1443- str )));
1431+ dterr = DTERR_BAD_FORMAT ;
1432+ else
1433+ dterr = ParseDateTime (str ,lowstr ,field ,ftype ,MAXDATEFIELDS ,& nf );
1434+ if (dterr == 0 )
1435+ dterr = DecodeTimeOnly (field ,ftype ,nf ,& dtype ,tm ,& fsec ,& tz );
1436+ if (dterr != 0 )
1437+ DateTimeParseError (dterr ,str ,"time with time zone" );
14441438
14451439result = (TimeTzADT * )palloc (sizeof (TimeTzADT ));
14461440tm2timetz (tm ,fsec ,tz ,result );