Skip to content

Commit 50ed78b

Browse files
committed
Allow 60 in seconds fields of timestamp, time, interval input values.
Per recent discussion on pgsql-general, this is appropriate for spec compliance, and has the nice side-effect of easing porting from old pg_dump files that exhibit the 59.999=>60.000 roundoff problem.
1 parent d1b4327 commit 50ed78b

File tree

2 files changed

+15
-14
lines changed

2 files changed

+15
-14
lines changed

src/backend/utils/adt/datetime.c

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.103 2003/04/04 04:50:44 tgl Exp $
11+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/datetime.c,v 1.104 2003/05/04 04:30:15 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2080,15 +2080,16 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
20802080
tm->tm_hour += 12;
20812081

20822082
#ifdef HAVE_INT64_TIMESTAMP
2083-
if (((tm->tm_hour < 0) || (tm->tm_hour > 23))
2084-
|| ((tm->tm_min < 0) || (tm->tm_min > 59))
2085-
|| ((tm->tm_sec < 0) || (tm->tm_sec > 60))
2083+
if ((tm->tm_hour < 0) || (tm->tm_hour > 23)
2084+
|| (tm->tm_min < 0) || (tm->tm_min > 59)
2085+
|| (tm->tm_sec < 0) || (tm->tm_sec > 60)
20862086
|| (*fsec < INT64CONST(0)) || (*fsec >= INT64CONST(1000000)))
20872087
return -1;
20882088
#else
2089-
if (((tm->tm_hour < 0) || (tm->tm_hour > 23))
2090-
|| ((tm->tm_min < 0) || (tm->tm_min > 59))
2091-
|| ((tm->tm_sec < 0) || ((tm->tm_sec + *fsec) >= 60)))
2089+
if ((tm->tm_hour < 0) || (tm->tm_hour > 23)
2090+
|| (tm->tm_min < 0) || (tm->tm_min > 59)
2091+
|| (tm->tm_sec < 0) || (tm->tm_sec > 60)
2092+
|| (*fsec < 0) || (*fsec >= 1))
20922093
return -1;
20932094
#endif
20942095

@@ -2313,14 +2314,14 @@ DecodeTime(char *str, int fmask, int *tmask, struct tm * tm, fsec_t *fsec)
23132314
#ifdef HAVE_INT64_TIMESTAMP
23142315
if ((tm->tm_hour < 0)
23152316
|| (tm->tm_min < 0) || (tm->tm_min > 59)
2316-
|| (tm->tm_sec < 0) || (tm->tm_sec > 59)
2317-
|| (*fsec >= INT64CONST(1000000)))
2317+
|| (tm->tm_sec < 0) || (tm->tm_sec > 60)
2318+
|| (*fsec < INT64CONST(0)) || (*fsec >= INT64CONST(1000000)))
23182319
return -1;
23192320
#else
23202321
if ((tm->tm_hour < 0)
23212322
|| (tm->tm_min < 0) || (tm->tm_min > 59)
2322-
|| (tm->tm_sec < 0) || (tm->tm_sec > 59)
2323-
|| (*fsec >= 1))
2323+
|| (tm->tm_sec < 0) || (tm->tm_sec > 60)
2324+
|| (*fsec < 0) || (*fsec >= 1))
23242325
return -1;
23252326
#endif
23262327

src/backend/utils/adt/nabstime.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.106 2003/04/04 04:50:44 tgl Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/nabstime.c,v 1.107 2003/05/04 04:30:15 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -320,9 +320,9 @@ tm2abstime(struct tm * tm, int tz)
320320
if (tm->tm_year < 1901 || tm->tm_year > 2038
321321
|| tm->tm_mon < 1 || tm->tm_mon > 12
322322
|| tm->tm_mday < 1 || tm->tm_mday > 31
323-
|| tm->tm_hour < 0 || tm->tm_hour >= 24
323+
|| tm->tm_hour < 0 || tm->tm_hour > 23
324324
|| tm->tm_min < 0 || tm->tm_min > 59
325-
|| tm->tm_sec < 0 || tm->tm_sec > 59)
325+
|| tm->tm_sec < 0 || tm->tm_sec > 60)
326326
return INVALID_ABSTIME;
327327

328328
day = date2j(tm->tm_year, tm->tm_mon, tm->tm_mday) - UNIX_EPOCH_JDATE;

0 commit comments

Comments
 (0)