Skip to content

Commit a93bf45

Browse files
committed
Allow times of 24:00:00 to match rounding behavior:
regression=# select '23:59:59.9'::time(0); time ---------- 24:00:00 (1 row) This is bad because: regression=# select '24:00:00'::time(0); ERROR: date/time field value out of range: "24:00:00" The last example now works.
1 parent dbc214f commit a93bf45

File tree

4 files changed

+27
-18
lines changed

4 files changed

+27
-18
lines changed

doc/src/sgml/datatype.sgml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.160 2005/10/02 23:50:06 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/datatype.sgml,v 1.161 2005/10/14 11:47:56 momjian Exp $
33
-->
44

55
<chapter id="datatype">
@@ -1368,15 +1368,15 @@ SELECT b, char_length(b) FROM test2;
13681368
<entry>8 bytes</entry>
13691369
<entry>times of day only</entry>
13701370
<entry>00:00:00.00</entry>
1371-
<entry>23:59:59.99</entry>
1371+
<entry>24:00:00</entry>
13721372
<entry>1 microsecond / 14 digits</entry>
13731373
</row>
13741374
<row>
13751375
<entry><type>time [ (<replaceable>p</replaceable>) ] with time zone</type></entry>
13761376
<entry>12 bytes</entry>
13771377
<entry>times of day only, with time zone</entry>
13781378
<entry>00:00:00.00+12</entry>
1379-
<entry>23:59:59.99-12</entry>
1379+
<entry>24:00:00-12</entry>
13801380
<entry>1 microsecond / 14 digits</entry>
13811381
</row>
13821382
</tbody>

src/backend/utils/adt/datetime.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.158 2005/10/09 17:21:46 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.159 2005/10/14 11:47:57 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -1114,7 +1114,9 @@ DecodeDateTime(char **field, int *ftype, int nf,
11141114
* Check upper limit on hours; other limits checked in
11151115
* DecodeTime()
11161116
*/
1117-
if (tm->tm_hour > 23)
1117+
/* test for > 24:00:00 */
1118+
if (tm->tm_hour > 24 ||
1119+
(tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0)))
11181120
return DTERR_FIELD_OVERFLOW;
11191121
break;
11201122

@@ -2243,14 +2245,16 @@ DecodeTimeOnly(char **field, int *ftype, int nf,
22432245
else if (mer == PM && tm->tm_hour != 12)
22442246
tm->tm_hour += 12;
22452247

2248+
if (tm->tm_hour < 0 || tm->tm_min < 0 || tm->tm_min > 59 ||
2249+
tm->tm_sec < 0 || tm->tm_sec > 60 || tm->tm_hour > 24 ||
2250+
/* test for > 24:00:00 */
2251+
(tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0 ||
22462252
#ifdef HAVE_INT64_TIMESTAMP
2247-
if (tm->tm_hour < 0 || tm->tm_hour > 23 || tm->tm_min < 0 ||
2248-
tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 ||
2253+
*fsec > INT64CONST(0))) ||
22492254
*fsec < INT64CONST(0) || *fsec >= USECS_PER_SEC)
22502255
return DTERR_FIELD_OVERFLOW;
22512256
#else
2252-
if (tm->tm_hour < 0 || tm->tm_hour > 23 || tm->tm_min < 0 ||
2253-
tm->tm_min > 59 || tm->tm_sec < 0 || tm->tm_sec > 60 ||
2257+
*fsec > 0)) ||
22542258
*fsec < 0 || *fsec >= 1)
22552259
return DTERR_FIELD_OVERFLOW;
22562260
#endif

src/backend/utils/adt/nabstime.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.143 2005/09/24 22:54:38 tgl Exp $
13+
* $PostgreSQL: pgsql/src/backend/utils/adt/nabstime.c,v 1.144 2005/10/14 11:47:57 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -184,12 +184,14 @@ tm2abstime(struct pg_tm *tm, int tz)
184184
AbsoluteTime sec;
185185

186186
/* validate, before going out of range on some members */
187-
if (tm->tm_year < 1901 || tm->tm_year > 2038
188-
|| tm->tm_mon < 1 || tm->tm_mon > 12
189-
|| tm->tm_mday < 1 || tm->tm_mday > 31
190-
|| tm->tm_hour < 0 || tm->tm_hour > 23
191-
|| tm->tm_min < 0 || tm->tm_min > 59
192-
|| tm->tm_sec < 0 || tm->tm_sec > 60)
187+
if (tm->tm_year < 1901 || tm->tm_year > 2038 ||
188+
tm->tm_mon < 1 || tm->tm_mon > 12 ||
189+
tm->tm_mday < 1 || tm->tm_mday > 31 ||
190+
tm->tm_hour < 0 ||
191+
tm->tm_hour > 24 || /* test for > 24:00:00 */
192+
(tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0)) ||
193+
tm->tm_min < 0 || tm->tm_min > 59 ||
194+
tm->tm_sec < 0 || tm->tm_sec > 60)
193195
return INVALID_ABSTIME;
194196

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

src/interfaces/ecpg/pgtypeslib/dt_common.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,7 +2095,9 @@ DecodeDateTime(char **field, int *ftype, int nf,
20952095
* Check upper limit on hours; other limits checked in
20962096
* DecodeTime()
20972097
*/
2098-
if (tm->tm_hour > 23)
2098+
/* test for > 24:00:00 */
2099+
if (tm->tm_hour > 24 ||
2100+
(tm->tm_hour == 24 && (tm->tm_min > 0 || tm->tm_sec > 0)))
20992101
return -1;
21002102
break;
21012103

@@ -3161,7 +3163,8 @@ PGTYPEStimestamp_defmt_scan(char **str, char *fmt, timestamp *d,
31613163
err = 1;
31623164
*minute = 0;
31633165
}
3164-
if (*hour > 23)
3166+
if (*hour > 24 || /* test for > 24:00:00 */
3167+
(*hour == 24 && (*minute > 0 || *second > 0)))
31653168
{
31663169
err = 1;
31673170
*hour = 0;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy