Decade indication - Mailing list pgsql-hackers

From Bruce Momjian
Subject Decade indication
Date
Msg-id 20191231163546.GA5864@momjian.us
Whole thread Raw
Responses Re: Decade indication  (Glyn Astill <glynastill@yahoo.co.uk>)
Re: Decade indication  (Andrew Dunstan <andrew.dunstan@2ndquadrant.com>)
Re: Decade indication  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
Does the next decade start on 2020-01-01 or 2021-01-01?  Postgres says
it start on the former date:

    SELECT EXTRACT(DECADE FROM '2019-01-01'::date);
     date_part
    -----------
           201
    
    SELECT EXTRACT(DECADE FROM '2020-01-01'::date);
     date_part
    -----------
           202

but the _century_ starts on 2001-01-01, not 2000-01-01:

    SELECT EXTRACT(CENTURY FROM '2000-01-01'::date);
     date_part
    -----------
            20
    
    SELECT EXTRACT(CENTURY FROM '2001-01-01'::date);
     date_part
    -----------
            21

That seems inconsistent to me.  /pgtop/src/backend/utils/adt/timestamp.c
has this C comment:

     * what is a decade wrt dates? let us assume that decade 199
     * is 1990 thru 1999... decade 0 starts on year 1 BC, and -1
     * is 11 BC thru 2 BC...

FYI, these two URLs suggest the inconsistency is OK:

    https://www.timeanddate.com/calendar/decade.html
    https://en.wikipedia.org/wiki/Decade

-- 
  Bruce Momjian  <bruce@momjian.us>        http://momjian.us
  EnterpriseDB                             http://enterprisedb.com

+ As you are, so once was I.  As I am, so you will be. +
+                      Ancient Roman grave inscription +



pgsql-hackers by date:

Previous
From: Isaac Morland
Date:
Subject: Re: color by default
Next
From: Jose Luis Tallon
Date:
Subject: Re: color by default