pg.ddx.io  pgsql-committers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-committers@postgresql.org
Subject: pgsql: Fix j2day() to behave sanely for negative Julian dates.
Date: Thu, 17 Mar 2016 00:57:50 +0000
Message-ID: <E1agMG6-00004u-P6@gemulon.postgresql.org> (raw)
List-Unsubscribe:  <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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(-)


-- 
Sent via pgsql-committers mailing list (pgsql-committers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-committers


Message-ID: <E1agMG6-00004u-P6@gemulon.postgresql.org>
Permalink:  ../E1agMG6-00004u-P6@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1agMG6-00004u-P6@gemulon.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-committers@postgresql.org
  Cc: tgl@sss.pgh.pa.us
  Subject: Re: pgsql: Fix j2day() to behave sanely for negative Julian dates.
  In-Reply-To: <E1agMG6-00004u-P6@gemulon.postgresql.org>
  References: <E1agMG6-00004u-P6@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox