xml-commons-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mrgla...@apache.org
Subject svn commit: r701918 - /xml/commons/trunk/java/external/src/javax/xml/datatype/DatatypeFactory.java
Date Mon, 06 Oct 2008 02:51:08 GMT
Author: mrglavas
Date: Sun Oct  5 19:51:08 2008
New Revision: 701918

URL: http://svn.apache.org/viewvc?rev=701918&view=rev
Log:
Correct default implementation of createDurationDayTime(long).

Modified:
    xml/commons/trunk/java/external/src/javax/xml/datatype/DatatypeFactory.java

Modified: xml/commons/trunk/java/external/src/javax/xml/datatype/DatatypeFactory.java
URL: http://svn.apache.org/viewvc/xml/commons/trunk/java/external/src/javax/xml/datatype/DatatypeFactory.java?rev=701918&r1=701917&r2=701918&view=diff
==============================================================================
--- xml/commons/trunk/java/external/src/javax/xml/datatype/DatatypeFactory.java (original)
+++ xml/commons/trunk/java/external/src/javax/xml/datatype/DatatypeFactory.java Sun Oct  5
19:51:08 2008
@@ -353,8 +353,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);
     }
 
     /**



Mime
View raw message