1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-16 06:01:02 +03:00

Please find a small patch to fix the brain damage "century" and

"millennium" date part implementation in postgresql, both in the code
and the documentation, so that it conforms to the official definition.
If you do not agree with the official definition, please send your
complaint to "pope@vatican.org". I'm not responsible for them;-)

With the previous version, the centuries and millenniums had a wrong
number and started the wrong year. Moreover century number 0, which does
not exist in reality, lasted 200 years. Also, millennium number 0 lasted
2000 years.

If you want postgresql to have it's own definition of "century" and
"millennium" that does not conform to the one of the society, just give
them another name. I would suggest "pgCENTURY" and "pgMILLENNIUM";-)

IMO, if someone may use the options, it means that postgresql is used for
historical data, so it make sense to have an historical definition. Also,
I just want to divide the year by 100 or 1000, I can do that quite easily.

BACKWARD INCOMPATIBLE CHANGE

Fabien Coelho - coelho@cri.ensmp.fr
This commit is contained in:
Bruce Momjian
2004-04-10 18:02:59 +00:00
parent 296f485492
commit 1934055cbe
4 changed files with 176 additions and 14 deletions

View File

@ -8,7 +8,7 @@
*
*
* IDENTIFICATION
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.103 2004/03/30 15:53:18 momjian Exp $
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.104 2004/04/10 18:02:59 momjian Exp $
*
*-------------------------------------------------------------------------
*/
@ -3273,11 +3273,23 @@ timestamp_part(PG_FUNCTION_ARGS)
break;
case DTK_CENTURY:
result = (tm->tm_year / 100);
/* centuries AD, c>0: year in [ (c-1)*100+1 : c*100 ]
* centuries BC, c<0: year in [ c*100 : (c+1)*100-1 ]
* there is no number 0 century.
*/
if (tm->tm_year > 0)
result = ((tm->tm_year+99) / 100);
else
/* caution: C division may yave negative remainder */
result = - ((99 - (tm->tm_year-1))/100);
break;
case DTK_MILLENNIUM:
result = (tm->tm_year / 1000);
/* see comments above. */
if (tm->tm_year > 0)
result = ((tm->tm_year+999) / 1000);
else
result = - ((999 - (tm->tm_year-1))/1000);
break;
case DTK_JULIAN: