Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitbc93919

Browse files
committed
Reject year zero during datetime input, except when it's a 2-digit year
(then it means 2000 AD). Formerly we silently interpreted this as 1 BC,which at best is unwarranted familiarity with the implementation.It's barely possible that some app somewhere expects the old behavior,though, so we won't back-patch this into existing release branches.
1 parent05506fc commitbc93919

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

‎src/backend/utils/adt/datetime.c

Lines changed: 15 additions & 9 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.186 2008/02/25 23:21:01 tgl Exp $
11+
* $PostgreSQL: pgsql/src/backend/utils/adt/datetime.c,v 1.187 2008/02/25 23:36:28 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2138,24 +2138,30 @@ ValidateDate(int fmask, bool is2digits, bool bc, struct pg_tm * tm)
21382138
{
21392139
if (fmask&DTK_M(YEAR))
21402140
{
2141-
/* there is no year zero in AD/BC notation; i.e. "1 BC" == year 0 */
21422141
if (bc)
21432142
{
2144-
if (tm->tm_year>0)
2145-
tm->tm_year=-(tm->tm_year-1);
2146-
else
2147-
ereport(ERROR,
2148-
(errcode(ERRCODE_INVALID_DATETIME_FORMAT),
2149-
errmsg("inconsistent use of year %04d and \"BC\"",
2150-
tm->tm_year)));
2143+
/* there is no year zero in AD/BC notation */
2144+
if (tm->tm_year <=0)
2145+
returnDTERR_FIELD_OVERFLOW;
2146+
/* internally, we represent 1 BC as year zero, 2 BC as -1, etc */
2147+
tm->tm_year=-(tm->tm_year-1);
21512148
}
21522149
elseif (is2digits)
21532150
{
2151+
/* allow 2-digit input for 1970-2069 AD; 00 is allowed */
2152+
if (tm->tm_year<0)/* just paranoia */
2153+
returnDTERR_FIELD_OVERFLOW;
21542154
if (tm->tm_year<70)
21552155
tm->tm_year+=2000;
21562156
elseif (tm->tm_year<100)
21572157
tm->tm_year+=1900;
21582158
}
2159+
else
2160+
{
2161+
/* there is no year zero in AD/BC notation */
2162+
if (tm->tm_year <=0)
2163+
returnDTERR_FIELD_OVERFLOW;
2164+
}
21592165
}
21602166

21612167
/* now that we have correct year, decode DOY */

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp