From: | Mikhail Titov <mlt(at)gmx(dot)us> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Chapman Flack <chap(at)anastigmatix(dot)net>, pgsql-hackers(at)lists(dot)postgresql(dot)org |
Subject: | Re: [PATCH] Leading minus for negative time interval in ISO 8601 |
Date: | 2020-06-10 04:18:20 |
Message-ID: | 9q0ftb37dv7.fsf@gmx.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Jun 3, 2020 at 11:25 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> ...
> Maybe we should just take the position that negative intervals aren't
> standardized, and if you want to transport them using ISO format then
> you first need to lobby ISO to fix that.
Apparently ISO did "fix" this. I managed to get a copy of ISO
8601-2:2019(E) and I insist on reconsidering the patch. Here is an
excerpt from page 12 of the standard:
,----[ 4.4.1.9 Duration ]
| A duration in the reverse direction, called a "negative duration" in
| this document, can be expressed using the following representation based
| on the [duration] representation specified in ISO 8601-1:2019, 5.5.2. In
| this case, all time scale components within the duration representation
| shall be positive.
|
| duration(m) = [!]["-"][positiveDuration]
|
| where [positiveDuration] is the representation of a positive duration.
|
| EXAMPLE 1 '-P1000' in date represents the duration of 100 days in the
| reverse direction. The duration formula 'P3650 - PlOOO' results in
| 'P2650'.
|
| EXAMPLE 2 '-P1Y30' in date represents the duration of one year and three
| days in the reverse direction. The duration formula 'PSY60 - P1Y30'
| results in 'P4Y30'.
`----
Note (mine) exclamation sign [!] means the following is optional. Here
is the definition for positiveDuration:
,----[ positiveDuration ]
| representation of [duration] specified in ISO 8601-1:2019, 5.4.2 that
| contains only time scale components that have positive values
`----
However on page 41 the standard says:
,----[ 11.2 Durational units ]
| Individual duration units are allowed to have negative values. The
| following representation denoted as [durationalUnits(m)] accept negative values per component.
|
| durationUnits(m) = [yearE(m)][monthE(m)][weekE(m)][dayE(m))["T"][hourE(m)][minuteE(m)]
| (secondE(m)]
`----
And, finally, there is that
,----[ 11.3.2 Composite representation ]
| The composite representation of a duration is a more flexible and
| relaxed specification for duration than that of .ISO 8601-1:2019,
| 5.5.2. It accepts all expressions of the duration representation given
| in ISO 8601-1:2019, 5.5.2 and is given as follows.
|
| [!]["-"]["P"][ durationUnits(m)]
|
| where [durationUnits(m)] contains time scale components for expressing
| (positive or negative) duration (see 11.2).
|
| Expressions in the two examples below are valid in ISO 8601-1.
|
| EXAMPLE 1 'P3D', duration of three days.
| EXAMPLE 2 'P180Y800D', duration of one-hundred-and-eighty years and eight-hundred days.
|
| Expressions in the following four examples below are not valid in ISO
| 8601-1, but are valid as specified in this clause.
|
| EXAMPLE 3 'P3W2D', duration of three weeks and two days, which is 23 days (equivalent to the expression
| 'P23D'). In ISO 8601-1, ["W"] is not permitted to occur along with any other component.
| EXAMPLE 4 'PSYlOW', duration of five years and ten weeks.
| EXAMPLE 5 'P-3M-3DT1HSM', duration of three months and three days in the reverse direction, with one hour
| and five minutes in the original direction.
| EXAMPLE 6 'P-ZM-1D', duration in the reverse direction of two months and one day.
|
| When a minus sign is provided as prefix to the duration designator
| ["P"], the minus sign can be internalized into individual time scale
| components within the duration expression by applying to every time
| scale component within.
|
| EXAMPLE 7 '-P2M1D' is equivalent to 'P-2M-1D'.
| EXAMPLE 8 '-P5DT10H' is equivalent to 'P-5DT-10H'.
|
| When a minus sign is applied to a time scale component whose value is
| already negative (pointing to the reverse direction), it means that
| the direction of duration should be once again reversed and should be
| turned into a positive value.
|
| EXAMPLE 9 '-P8M-1D', duration in reverse, "eight months minus one day", is equivalent to 'P-8M1D', "eight
| months ago with a day ahead".
| EXAMPLE 10 '-P-5WT-18H30M', duration in reverse, "go back five weeks, eighteen hours but thirty minutes
| ahead", is equivalent to 'P5WT18H-30M', "go ahead five weeks, eighteen hours, but thirty minutes back".
|
| NOTE The exact duration for some time scale components can be known only when placed on the actual
| time scale, see D.2.
`----
On a side note, it also defines (4.4.2) exponential values, but I guess
we can pass on those for now.
--
Mikhail
From | Date | Subject | |
---|---|---|---|
Next Message | Michael Paquier | 2020-06-10 04:23:37 | Re: [Patch] pg_rewind: options to use restore_command from recovery.conf or command line |
Previous Message | Justin Pryzby | 2020-06-10 03:57:18 | Re: proposal: possibility to read dumped table's name from file |