pgsql: Fix j2day() to behave sanely for negative Julian dates.

Поиск
Список
Период
Сортировка
От Tom Lane
Тема pgsql: Fix j2day() to behave sanely for negative Julian dates.
Дата
Msg-id E1agMG6-00004u-P6@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix j2day() to behave sanely for negative Julian dates.

Somebody had apparently once figured that casting to unsigned int would
produce the right output for negative inputs, but that would only be
true if 2^32 were a multiple of 7, which of course it ain't.  We need
to use a signed division and then correct the sign of the remainder.

AFAICT, the only case where this would arise currently is when doing
ISO-week calculations for dates in 4714BC, where we'd compute a
negative Julian date representing 4714-01-04BC and then do some
arithmetic with it.  Since we don't even really document support for
such dates, this is not of much consequence.  But we may as well
get it right.

Per report from Vitaly Burovoy.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/5db51464311eb7fe4e90030c6a514ff61e9f1c00

Modified Files
--------------
src/backend/utils/adt/datetime.c | 13 ++++++-------
1 file changed, 6 insertions(+), 7 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: pgsql: Be more careful about out-of-range dates and timestamps.
Следующее
От: Tom Lane
Дата:
Сообщение: pgsql: Fix "pg_bench -C -M prepared".