This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 29749 - [fo31] Rounding of fractional seconds in format-time()
Summary: [fo31] Rounding of fractional seconds in format-time()
Status: CLOSED FIXED
Alias: None
Product: XPath / XQuery / XSLT
Classification: Unclassified
Component: Functions and Operators 3.1 (show other bugs)
Version: Candidate Recommendation
Hardware: PC All
: P2 normal
Target Milestone: ---
Assignee: Michael Kay
QA Contact: Mailing list for public feedback on specs from XSL and XML Query WGs
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-07-21 19:23 UTC by Michael Kay
Modified: 2016-12-16 19:55 UTC (History)
3 users (show)

See Also:


Attachments

Description Michael Kay 2016-07-21 19:23:08 UTC
Over ten years ago, as a result of bug #3018, the following sentence was added to the spec:

In the case of the fractional seconds component, the value is rounded to the specified size as if by applying the function round-half-to-even(fractional-seconds, max-width).

and it seems this has gone unchallenged since.

So what exactly is the output of

format-time(xs:time("12:01:01.9999", "[s99].[f99]"))

In particular, how does one round a fractional seconds value such as .9999 to a maximum width of two digits by following the round-half-to-even rule?
Comment 1 Michael Kay 2016-07-22 15:29:09 UTC
It's hard to come up with a fully satisfactory solution to this.

I think we should rule out all solutions that attempt to round 01.9999 "properly" to 02.0000, changing the seconds value, because it would be very disruptive for the formatting of one component to affect the output of another.

I think there are two possible choices:

(A) Abandon rounding and switch to truncation. Truncation always works and is consistent with the general approach of the function: if the value is 12:59:59 and you choose not to output the seconds, the output is 12:59, not 13:00. It's an incompatible change, but it's a change to something that can never have worked properly.

(B) Specify that if rounding the fractional seconds would cause the seconds value to change, we truncate instead. So 1.9999 "rounds" to 1.99.

I think my preference is to take the compatibility hit and go for (A).
Comment 2 Michael Kay 2016-07-22 16:54:40 UTC
>So what exactly is the output of

>format-time(xs:time("12:01:01.9999", "[s99].[f99]"))


For Saxon, in recent releases at any rate, the output has been "01.00". Not nice.
Comment 3 Michael Kay 2016-07-26 19:22:33 UTC
The WG decided on option (A) in comment (1): switch to truncating rather than rounding.
Comment 4 Michael Kay 2016-07-26 19:55:22 UTC
The spec and test cases have been updated.
Comment 5 Christian Gruen 2016-08-01 08:34:50 UTC
Wouldn’t it make sense to also apply the rule to fn:dateTime? If yes, I guess that the following testcases should be revised:

* format-dateTime-002g
* format-dateTime-002h
* format-dateTime-002i
* format-dateTime-003m
* format-dateTime-003n
* format-dateTime-003p
* format-dateTime-013s
* format-dateTime-013u
Comment 6 Michael Kay 2016-08-01 10:08:18 UTC
Yes the new rule obviously applies to fn:format-dateTime() as well, and there may well be other test cases that need updating.
Comment 7 Tim Mills 2016-08-05 15:37:12 UTC
I have taken the liberty of correcting the expected results for these tests.
Comment 8 Andrew Coleman 2016-09-02 10:47:10 UTC
Based on Tim's comment #7, I have marked this bug as resolved/fixed.  Please reopen if you believe any more work needs to be done.
Thanks.