small bug on 3-digit years in 9.2-dev
Started by Marc Cousinover 13 years ago2 messages
Hi,
While working on the "What's new in 9.2", I think I found a small bug:
SELECT to_date('519-07-02','YYY-MM-DD');
to_date
------------
0519-07-02
(1 row)
It comes, I think, from the year 519 case not being handled in the following
code. Patch attached
+ if (year < 70)
+ return year + 2000;
+ /* Force 70-99 into the 1900's */
+ else if (year >= 70 && year < 100)
+ return year + 1900;
+ /* Force 100-519 into the 2000's */
+ else if (year >= 100 && year < 519)
+ return year + 2000;
+ /* Force 520-999 into the 1000's */
+ else if (year >= 520 && year < 1000)
+ return year + 1000;
+ else
+ return year;
Regards
Attachments:
correct_dates.patchtext/x-patch; charset=UTF-8; name=correct_dates.patchDownload
diff --git a/src/backend/utils/adt/formatting.c b/src/backend/utils/adt/formatting.c
index 765c6aa..8eb7d5d 100644
--- a/src/backend/utils/adt/formatting.c
+++ b/src/backend/utils/adt/formatting.c
@@ -1997,7 +1997,7 @@ adjust_partial_year_to_2020(int year)
else if (year >= 70 && year < 100)
return year + 1900;
/* Force 100-519 into the 2000's */
- else if (year >= 100 && year < 519)
+ else if (year >= 100 && year <= 519)
return year + 2000;
/* Force 520-999 into the 1000's */
else if (year >= 520 && year < 1000)
Re: small bug on 3-digit years in 9.2-dev
Marc Cousin <cousinmarc@gmail.com> writes:
While working on the "What's new in 9.2", I think I found a small bug:
Yeah, that code certainly looks wrong, thanks for the report!
/* Force 100-519 into the 2000's */ - else if (year >= 100 && year < 519) + else if (year >= 100 && year <= 519)
I think "< 520" would be more in keeping with the adjacent coding.
regards, tom lane