Re: [FO31errata] A problem in the definition of the op:subtract-dateTimes function

I agree that the reference to XSD appendix E isn't very clear. I suspect that's it's the "time-on-timeline" function that is intended: convert both dateTimes to xs:decimal values using time-on-timeline (which returns the number of seconds after some arbitrary origin), subtract the decimal values to get an interval in seconds (call it D), and then convert the result back to the xs:dayTimeDuration with months=0, seconds=D.

Since the result has to be an xs:dayTimeDuration, which is a duration in seconds, your method (2) really isn't going to work; so while I agree it's underspecified, I think that only one interpretation is viable.

Michael Kay
Saxonica

> On 6 Aug 2019, at 16:42, Boris Motik <boris.motik@cs.ox.ac.uk> wrote:
> 
> Hello,
> 
> Section 9.7.2 (https://www.w3.org/TR/xpath-functions-3/#func-subtract-dateTimes <https://www.w3.org/TR/xpath-functions-3/#func-subtract-dateTimes>) of the XPath and XQuery Functions and Operators 3.1 document defines the op:subtract-dateTimes function as follows:
> 
> The function returns the elapsed time between the date/time instant arg2 and the date/time instant arg1, computed according to the algorithm given in Appendix E of [XML Schema Part 2: Datatypes Second Edition], and expressed as a xs:dayTimeDuration.
> 
> Unfortunately, the XML Schema Datatypes specification does not seem to contain such an algorithm: both https://www.w3.org/TR/xmlschema-2/ <https://www.w3.org/TR/xmlschema-2/> and https://www.w3.org/TR/xmlschema11-2/ <https://www.w3.org/TR/xmlschema11-2/> contain only an algorithm for adding xs:duration to an xs:dateTime, but neither of them contains an algorithm for subtracting xs:dateTime objects. In fact, the latter document says the following:
> 
>  duration can provide addition and subtraction operations between duration values and between duration/dateTime value pairs, and can be the result of subtracting dateTime values.
> 
> Hence, this seems to me like an omission in the standard.
> 
> 
> I thought a bit about this issue and came to the conclusion that the resolution is nontrivial as there seem to be at least two possible ways of computing the difference.
> 
> 1. Two xs:dateTime objects represent fixed points in time, so one can compute the elapsed number of seconds between them. Thus, the difference could be represented as an xs:duration object whose month component is zero and the second component is the time difference.
> 
> 2. One could compute both the number of elapsed months and the number of elapsed seconds and construct an xs:duration object in that way.
> 
> The second solution seems applicable to date/time datatypes other than xs:dateTime (such as xs:time or xs:gMonthYear), whereas the first solution seems applicable only to xs:dateTime and xs:dateTimeStamp datatypes.
> 
> In any case, clarification on this point would be useful.
> 
> Regards,
> 
> Boris Motik

Received on Tuesday, 6 August 2019 16:17:02 UTC