Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1XmHaz-0005dU-JE for pgsql-bugs@arkaria.postgresql.org; Thu, 06 Nov 2014 07:35:05 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1XmHay-0001Jj-ST for pgsql-bugs@arkaria.postgresql.org; Thu, 06 Nov 2014 07:35:04 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1XmHay-0001JC-75 for pgsql-bugs@postgresql.org; Thu, 06 Nov 2014 07:35:04 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1XmHaq-0003uk-EF for pgsql-bugs@postgresql.org; Thu, 06 Nov 2014 07:35:03 +0000 Received: from bruce by momjian.us with local (Exim 4.72) (envelope-from ) id 1XmHal-00019F-Nd; Thu, 06 Nov 2014 02:34:51 -0500 Date: Thu, 6 Nov 2014 02:34:51 -0500 From: Bruce Momjian To: Tom Lane Cc: Magnus Hagander , hunsakerbn@familysearch.org, pgsql-bugs Subject: Re: BUG #11883: Year 1500 not treated as leap year when it was a leap year Message-ID: <20141106073451.GA4253@momjian.us> References: <20141105175607.26929.23188@wrigleys.postgresql.org> <20141105180225.GB10345@momjian.us> <15535.1415211201@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="BOKacYhQ+x31HxR3" Content-Disposition: inline In-Reply-To: <15535.1415211201@sss.pgh.pa.us> User-Agent: Mutt/1.5.20 (2009-06-14) X-Pg-Spam-Score: -2.5 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org --BOKacYhQ+x31HxR3 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Nov 5, 2014 at 01:13:21PM -0500, Tom Lane wrote: > Magnus Hagander writes: > > On Wed, Nov 5, 2014 at 7:02 PM, Bruce Momjian wrote: > >> Because 1500 % 100 == 0, I think 1500 was not a leap year. > > > I believe it was a leap year in the Julian calendar, maybe that's > > where the difference comes from? > > Indeed. We won't be changing our code though, because we document that > we follow Gregorian calendar rules even before that calendar was instituted > (ie, proleptic Gregorian calendar). You could argue for doing that > differently, but then what are you going to do for dates before the Julian > calendar was instituted? In any case, this behavior appears to be > required by the SQL standard, which repeatedly says that datetime values > are "constrained according to the Gregorian calendar". I have applied the attached C comment to document why we use the Gregorian calendar for pre-1582 years. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + Everyone has their own god. + --BOKacYhQ+x31HxR3 Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="leap.diff" diff --git a/src/include/utils/datetime.h b/src/include/utils/datetime.h new file mode 100644 index 9b53ee3..548758a *** a/src/include/utils/datetime.h --- b/src/include/utils/datetime.h *************** extern const char *const months[]; /* m *** 271,276 **** --- 271,281 ---- extern const char *const days[]; /* days (full names) */ extern const int day_tab[2][13]; + /* + * These are the rules for the Gregorian calendar, which was adopted in 1582. + * However, we use this calculation for all prior years as well because the + * SQL standard specifies use of the Gregorian calendar. + */ #define isleap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0)) --BOKacYhQ+x31HxR3 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs --BOKacYhQ+x31HxR3--