-
Notifications
You must be signed in to change notification settings - Fork 154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ISO 8601-2:2019 #819
Comments
Spec abstract is below. I bolded the parts that looked most interesting.
|
BTW, downloading the standard costs a few hundred dollars. (!!!!) |
I hope @sffc doesn't mind me reposting this from the chat, where he listed some highlights from his reading of the standard:
|
And here are my opinions on whether the above changes are relevant...
As long as we have negative durations, then we should probably check whether we can conform to their algorithm to resolve mixed signs.
It doesn't seem like we would be able to support this on years, months, weeks, or days, and still be consistent with what we have.
Does this seem like something that we want to support? Maybe it would be good to see if it gains traction as an interchange format first. It's something that could always be added as a follow-on proposal. (If we don't support this, then a lot of the other items become moot.)
We don't have separate types for centuries or decades, so I don't think this is actionable. Maybe ordinal days would be relevant, although we already didn't support the existing
We don't have Temporal.YearWeek, so I don't think this is actionable. 2019Y-10O might be relevant if we support the new syntax, but then again we already didn't support constructing a Temporal.Date from the existing year/ordinal day notation.
Would only be relevant if we supported the new syntax. I'm indifferent about it otherwise.
I thought the
Seems trivial to support, why not?
I don't think this is relevant to Temporal since we don't have things like Temporal.YearSeason and Temporal.YearQuarter.
Ditto.
Ditto, we don't have this concept either.
Intervals were already in the previous edition and we do not support them. (Although we have had one request that it would be useful, there are some practical concerns: #205) |
@sffc - could you post an excerpt of the algorithm here? I'd like to understand how the spec expects constrain-balancing to work if the starting point date and time zone isn't known. |
Section 4.4.1.9 defines the term "negative duration" as follows:
However, Section 11, entitled "Explicit duration and extensions", is an entire chapter dedicated to the subject of durations with mixed signs. It defines a new term for it, "composite durations". Here is an excerpt:
That section goes on to define the syntax, which is the same as the syntax for "normal" (ISO 8601-1 style) durations, except that it explicitly allows mixed signs, such as:
The next section, "11.3.3 Precedence representation", further defines syntax with multiple durations in a sequence. It calls them "precedence durations". Example:
The algorithms for arithmetic are introduced in Section 14 and explained in detail in Annex D. Here is an example of duration-duration arithmetic from Section 14.2:
EXAMPLE 6 doesn't look right to me, but that's what it says. Here is an example of datetime-duration arithmetic from Section 14.4, with a precedence durational unit, but not mixed signs:
Annex D is the part I think we're most interested in. It specifies the algorithm for datetime-duration arithmetic. It defines two new operations on datetime types: "Carry-over of overflow in time scale components" (section D.3.1) and "Truncation at time scale component boundaries" (section D.3.2). Those two operations are then used in the algorithms, of which there are three: ones for simple durations (ISO 8601-1 style, but with only one time scale component; section D.4.1), composite durations (ISO 8601-2 style; section D.4.2), and precedence durations (section D.4.3). Here is the algorithm for composite durations, from section D.4.2:
"Carry-over" is what we call "balance", and "truncation" is what we call "constrain". They have special rules for leap months, leap seconds, etc. I encourage you to obtain your own personal copy of ISO-8601-2 if you want more details. You can read the license agreement here: https://www.iso.org/terms-conditions-licence-agreement.html To my great disappointment, Annex D does not give any examples of how to resolve situations in which the time scale components become negative, even though my careful reading of the document strongly suggests that such a situation is possible. However, the spec references CalConnect CC 18011 multiple times when discussing these algorithms, so maybe that spec has some answers. |
Because I wasn't ready to pay $200 of my family's money for the ISO spec, I read CalConnect CC 18011 instead. ;-) Here's some notes:
Honestly I found this spec disappointing. It doesn't seem to offer resolution for any of the big open issues that we're trying to resolve with Temporal. |
Okay, so it sounds like CalConnect CC 18011 has pretty much the same scope as ISO-8601-2, with the same types of answered and unanswered questions. We have a liaison relationship with CalConnect in the works. Once that is established, then we can send our questions directly to the authors of that spec. |
I didn't realize until now that the 2019 edition split ISO 8601 into ISO 8601-1 and ISO 8601-2, where part 1 is "Basic rules" and part 2 is "Extensions". All the things above are from part 2, if I'm not mistaken, so it seems appropriate that we should be able to pick and choose which extensions we support. |
Hi guys, editor of ISO 8601-2 and CC 18011/18012 here, from CalConnect. ISO 8601-2 is effectively a combination of three specs: Library of Congress' EDTF, CalConnect's CC 18011 and 18012. All of these are open specs so you're not missing out much on the ISO copy. (caveat below...) Some replies:
Clause 14.2 of ISO 8601-2 (which is supposed to be CC 18011) deals specifically with temporal arithmetic including subtraction. I apologize here -- because 18011 was not updated to the latest text we contributed to 8601-2. We will update 18011 to reflect the missing changes. I can't just paste the images here due to copyright restrictions, but the text is from CalConnect.
Those examples were chosen to "hint" at the problem without naming it, because DST and timezones are out of scope of ISO 8601-2. In ISO 8601-1 and 8601-2 the only concept that exists is "time shift". This is intentional, because another project ISO 34200 (and the associated ISO 8601-3) is scoped to deal with that particular problem. Last bit about some potential confusion -- ISO 8601-1 and ISO 8601-2 support the concept of "profiles" -- no one needs to support all the representations used in these documents. In ISO 8601-2, there is an Annex that provides the EDTF profile built upon ISO 8601-2 primitives (happy to share that via the CalConnect liaison). |
Answering @sffc
I can't figure out why that was the case either. Probably was supposed to be
I just re-read 8601-2. Indeed, Annex D does not describe situations where time scale components become negative, but Clause 14 does provide examples of subtraction where they can be performed on the same units. Could you briefly describe the issues encountered with subtraction? In the document we were very concerned about the comparisons between nominal durations vs realized durations (e.g. with positive / negative leap second), and would love to know how you deal with them. |
Hello, @ronaldtse!
The algorithm essentially says to take your composite duration, apply it field-by-field to your time scale unit, and then resolve problems in the resulting intermediate time scale unit by performing carry-over and truncation as necessary. So, what happens with Also see #857 for some more cases and related questions. |
Section 14 shows examples of subtraction between two composite durations, but not between a time scale and a duration. Section 14.4, "Date time modified by duration", is the one I'm most interested in, and it only gives a few examples (none of which involve subtraction) and defers you to Annex D for more details. |
Since ISO 8601-2 Annex D omitted the algorithm and examples for dealing with underflow units, here's a draft supplement. As editor I apologize that this wasn't provided in the standard. This will be contributed back to CC 18011, and the ISO group may perhaps consider as an amendment. (CalConnect/cc-datetime-explicit#12) Please feel free to let us know what you think! (insert) ISO 8601-2:2019, 14.4In date-time arithmetic, some time scale units can be converted into one another through deterministic relationships, which are transitive. These freely convertible relationships include:
The following time scale unit conversions are not deterministic in abstract, the actual durations of these time scale units depend on contextual information:
These rules are considered as the "time scale unit conversion boundaries". The result of a date time arithmetic expression does not change with time scale unit conversion as long as the conversion boundaries are not violated. When the full context of a date time expression is provided, these boundaries can be relaxed accordingly. EXAMPLE 1 The date time expression '2023Y59O' can be freely converted into '2023Y2M28D', because the 59th ordinal day of a Gregorian year is always February 28th. EXAMPLE 2 The date time expression '2020Y60O' can be freely converted into '2020Y2M29D', because the 60th ordinal day of the Gregorian year 2020 is February 29th. EXAMPLE 3 The date time expression '2016Y12M31DT61S' can be freely converted into '2017Y1M1DT-1S', because a leap second was inserted into the last clock minute on 2016-12-31. (add) ISO 8601-2, D.3.3 Borrow to resolve underflow in time scale componentsThe composite duration form was meant to delay the resolution of date time duration until application because some time scale units require contextual information. In some cases, it is possible to convert a duration expression that contains a negative time scale component into an equivalent duration expression where the previously negative time scale component becomes positive. This process of conversion involves two operations:
NOTE: If exact duration is not necessary or is considered too complex to calculate, one could simplify to omit some boundaries to adopt "nominal duration", such as ignoring the leap second (i.e. ignore rule 3) and treat 1 minute = 60 seconds. EXAMPLE 4 The expression 'P1Y10M3D − P2Y5MT10M' results in 'P3Y15M3DT-10M'. The negative sign at '-10M' can be converted into a positive expression by "borrowing" from a time scale unit of a higher order. Since the "hour" time scale unit is 0, the next time scale unit to borrow from is the "day" unit. One "day" unit expands to 24H, resulting in 'P3Y15M2DT24H-10M'. One "hour" unit can expand into 60M, resulting in 'P3Y15M2DT23H(60-10)M', which ends up being 'P3Y15M2DT23H50M'. EXAMPLE 5 'P1Y-10M3D + P2Y-5M' results in 'P-1Y-15M3D'. The negative sign at '-1Y' cannot be resolved because there is no higher order unit to borrow from. The negative sign at '-15M' can be resolved by borrowing from the "year" unit. In order to pad the "month" unit to a positive number, the minimum number of years to borrow from "year" is 2, resulting in 'P-3Y(24-15)M3D', which equals 'P-3Y9M3D'. EXAMPLE 6 'PT1H60S - PT122M' results in 'PT1H-122M60S'. The negative sign at '-122M' can be resolved, because the conversion between "hour" and "minute" does not cross any conversion boundaries. In order to resolve the negative sign at '-122M', a total of 3 hours need to be borrowed, resulting in 'PT(1-3)H(180-122)M60S', which concludes as 'PT-2H58M60S'. This expression can also be represented as 'PT-62M60S', since "hour" and "minute" can be freely converted (-2H = -120M; -120M + 58M = -62M). EXAMPLE 7 'PT5H120S - PT1M' results in 'PT5H-1M120S'. The negative sign at '-1M' can be resolved by borrowing from the "hour" unit without crossing conversion boundaries. The borrowing of 1 hour to minutes results in 'PT4H(60-1)M120S', which concludes as 'PT4H59M120S'. The '59M120S' portion cannot be simplified as the "minute to seconds" conversion requires contextual information. (new) ISO 8601-2, D.4.6 Resolving negative time scale units in an expression ("underflows")The steps are as follows:
EXAMPLE 1 Calculation of '2022Y2M2D - P1Y10M3D':
EXAMPLE 2 Calculation of '2025Y59O - P20DT1H30M':
EXAMPLE 3 Calculation of 'T10H10M10S - PT5H30M20S':
|
Thanks for writing this up! I commented on it in CalConnect/cc-datetime-explicit#12. |
Is there anything remaining to do on this issue? @justingrant Does the Duration arithmetic that we have, correspond with CalConnect/cc-datetime-explicit#12 ? |
There seems to be nothing remaining to do on this issue. |
I just learned that a new iteration of the ISO 8601 standard that was released last year. https://www.iso.org/standard/70908.html
Are there any changes in the standard that are significant for Temporal?
The text was updated successfully, but these errors were encountered: