#281 Negative milliseconds in duration calculations

v8.2
closed
Michael Kay
5
2012-10-08
2004-12-31
Michael Kay
No

When a computation on durations (for example,
subtraction of durations) yields a negative duration,
the fractional seconds are treated as positive rather
than negative. For example, if the result of a
calculation is -12.6 seconds, it will be displayed as
-PT11.4S.

Applies to 8.2 and all previous releases. Test case
added: date099. Source code fixed. Source fix: in
net.sf.saxon.SecondsDurationValue, change method
fromMilliseconds (line 229) to read:

public static SecondsDurationValue

fromMilliseconds(long milliseconds) throws XPathException {
SecondsDurationValue sdv = new
SecondsDurationValue();
sdv.negative = (milliseconds<0);
milliseconds = Math.abs(milliseconds);
long seconds = milliseconds/1000;
sdv.days = (int)(seconds / (360024));
sdv.seconds = (int)(seconds % (3600
24));
sdv.milliseconds = (int)(milliseconds % 1000);
sdv.normalize();
return sdv;
}

Discussion