You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-cvs@xml.apache.org by mr...@apache.org on 2008/10/06 04:50:50 UTC
svn commit: r701917 -
/xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java
Author: mrglavas
Date: Sun Oct 5 19:50:50 2008
New Revision: 701917
URL: http://svn.apache.org/viewvc?rev=701917&view=rev
Log:
Correct default implementation of createDurationDayTime(long).
Modified:
xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java
Modified: xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java
URL: http://svn.apache.org/viewvc/xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java?rev=701917&r1=701916&r2=701917&view=diff
==============================================================================
--- xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java (original)
+++ xml/commons/branches/tck-jaxp-1_3_0/java/external/src/javax/xml/datatype/DatatypeFactory.java Sun Oct 5 19:50:50 2008
@@ -338,8 +338,56 @@
* XQuery 1.0 and XPath 2.0 Data Model, xdt:dayTimeDuration</a>
*/
public Duration newDurationDayTime(final long durationInMilliseconds) {
-
- return newDuration(durationInMilliseconds);
+ long _durationInMilliseconds = durationInMilliseconds;
+ if (_durationInMilliseconds == 0) {
+ return newDuration(true, DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED, 0, 0, 0, 0);
+ }
+ boolean tooLong = false;
+ final boolean isPositive;
+ if (_durationInMilliseconds < 0) {
+ isPositive = false;
+ if (_durationInMilliseconds == Long.MIN_VALUE) {
+ _durationInMilliseconds++;
+ tooLong = true;
+ }
+ _durationInMilliseconds *= -1;
+ }
+ else {
+ isPositive = true;
+ }
+
+ long val = _durationInMilliseconds;
+ int milliseconds = (int) (val % 60000L); // 60000 milliseconds per minute
+ if (tooLong) {
+ ++milliseconds;
+ }
+ if (milliseconds % 1000 == 0) {
+ int seconds = milliseconds / 1000;
+ val = val / 60000L;
+ int minutes = (int) (val % 60L); // 60 minutes per hour
+ val = val / 60L;
+ int hours = (int) (val % 24L); // 24 hours per day
+ long days = val / 24L;
+ if (days <= ((long) Integer.MAX_VALUE)) {
+ return newDuration(isPositive, DatatypeConstants.FIELD_UNDEFINED,
+ DatatypeConstants.FIELD_UNDEFINED, (int) days, hours, minutes, seconds);
+ }
+ else {
+ return newDuration(isPositive, null, null,
+ BigInteger.valueOf(days), BigInteger.valueOf(hours),
+ BigInteger.valueOf(minutes), BigDecimal.valueOf(milliseconds, 3));
+ }
+ }
+
+ BigDecimal seconds = BigDecimal.valueOf(milliseconds, 3);
+ val = val / 60000L;
+ BigInteger minutes = BigInteger.valueOf(val % 60L); // 60 minutes per hour
+ val = val / 60L;
+ BigInteger hours = BigInteger.valueOf(val % 24L); // 24 hours per day
+ val = val / 24L;
+ BigInteger days = BigInteger.valueOf(val);
+ return newDuration(isPositive, null, null, days, hours, minutes, seconds);
}
/**