Re: BUG #14313: justify interval bug - Mailing list pgsql-bugs

From Greg Stark
Subject Re: BUG #14313: justify interval bug
Date
Msg-id CAM-w4HPQ5_RgEwJD6D6FF_Q147G20HV+0E8scCph4K3ziE-6eg@mail.gmail.com
Whole thread Raw
In response to Re: BUG #14313: justify interval bug  (Vik Fearing <vik@2ndquadrant.fr>)
List pgsql-bugs
On Mon, Sep 5, 2016 at 6:59 PM, Vik Fearing <vik@2ndquadrant.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

pgsql-bugs by date:

Previous
From: Vik Fearing
Date:
Subject: Re: BUG #14313: justify interval bug
Next
From: "Peterko"
Date:
Subject: Re: [BUGS] BUG #14313: justify interval bug