Re: BUG #14313: justify interval bug

From: Greg Stark <stark(at)mit(dot)edu>
To: Vik Fearing <vik(at)2ndquadrant(dot)fr>
Cc: coolman(dot)peto(at)centrum(dot)cz, PostgreSQL Bugs <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14313: justify interval bug
Date: 2016-09-05 18:29:03
Message-ID: CAM-w4HPQ5_RgEwJD6D6FF_Q147G20HV+0E8scCph4K3ziE-6eg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Mon, Sep 5, 2016 at 6:59 PM, Vik Fearing <vik(at)2ndquadrant(dot)fr> wrote:
> Your timestamp subtraction results in 7305 days. The justify_interval
> function, not knowing anything about where those days came from, will
> use 30 days per month, giving you the result you see.

Part of the story that's not apparent here is that intervals track
months and days
separately but don't track years separately. So the justified interval
internally is actually 243 months, 15 days, and 0 seconds. The "20
years" is just part of the output format.

The reason years aren't tracked separately is that they're always 12
months. So if you want an event in your calendar that occurs every
year on the same date you can add an interval like '12 months' to it
and it'll always add exactly a year and land on the same date
regardless of the number of days in the year.

--
greg

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Peterko 2016-09-05 18:54:56 Re: [BUGS] BUG #14313: justify interval bug
Previous Message Vik Fearing 2016-09-05 17:59:56 Re: BUG #14313: justify interval bug