<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29749</bug_id>
          
          <creation_ts>2016-07-21 19:23:08 +0000</creation_ts>
          <short_desc>[fo31] Rounding of fractional seconds in format-time()</short_desc>
          <delta_ts>2016-12-16 19:55:15 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Functions and Operators 3.1</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Michael Kay">mike</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          <cc>andrew_coleman</cc>
    
    <cc>christian.gruen</cc>
    
    <cc>tim</cc>
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>127029</commentid>
    <comment_count>0</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-07-21 19:23:08 +0000</bug_when>
    <thetext>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(&quot;12:01:01.9999&quot;, &quot;[s99].[f99]&quot;))

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?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127041</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-07-22 15:29:09 +0000</bug_when>
    <thetext>It&apos;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 &quot;properly&quot; 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&apos;s an incompatible change, but it&apos;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 &quot;rounds&quot; to 1.99.

I think my preference is to take the compatibility hit and go for (A).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127042</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-07-22 16:54:40 +0000</bug_when>
    <thetext>&gt;So what exactly is the output of

&gt;format-time(xs:time(&quot;12:01:01.9999&quot;, &quot;[s99].[f99]&quot;))


For Saxon, in recent releases at any rate, the output has been &quot;01.00&quot;. Not nice.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127054</commentid>
    <comment_count>3</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-07-26 19:22:33 +0000</bug_when>
    <thetext>The WG decided on option (A) in comment (1): switch to truncating rather than rounding.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127056</commentid>
    <comment_count>4</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-07-26 19:55:22 +0000</bug_when>
    <thetext>The spec and test cases have been updated.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127096</commentid>
    <comment_count>5</comment_count>
    <who name="Christian Gruen">christian.gruen</who>
    <bug_when>2016-08-01 08:34:50 +0000</bug_when>
    <thetext>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</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127098</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2016-08-01 10:08:18 +0000</bug_when>
    <thetext>Yes the new rule obviously applies to fn:format-dateTime() as well, and there may well be other test cases that need updating.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127104</commentid>
    <comment_count>7</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2016-08-05 15:37:12 +0000</bug_when>
    <thetext>I have taken the liberty of correcting the expected results for these tests.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127269</commentid>
    <comment_count>8</comment_count>
    <who name="Andrew Coleman">andrew_coleman</who>
    <bug_when>2016-09-02 10:47:10 +0000</bug_when>
    <thetext>Based on Tim&apos;s comment #7, I have marked this bug as resolved/fixed.  Please reopen if you believe any more work needs to be done.
Thanks.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>