From commons-cvs-return-628-apmail-xml-commons-cvs-archive=xml.apache.org@xml.apache.org Mon Oct 06 02:51:29 2008 Return-Path: Delivered-To: apmail-xml-commons-cvs-archive@www.apache.org Received: (qmail 65766 invoked from network); 6 Oct 2008 02:51:29 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 6 Oct 2008 02:51:29 -0000 Received: (qmail 52958 invoked by uid 500); 6 Oct 2008 02:51:28 -0000 Delivered-To: apmail-xml-commons-cvs-archive@xml.apache.org Received: (qmail 52931 invoked by uid 500); 6 Oct 2008 02:51:28 -0000 Mailing-List: contact commons-cvs-help@xml.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list commons-cvs@xml.apache.org Received: (qmail 52922 invoked by uid 99); 6 Oct 2008 02:51:28 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 05 Oct 2008 19:51:28 -0700 X-ASF-Spam-Status: No, hits=-1998.7 required=10.0 tests=ALL_TRUSTED,DNS_FROM_DOB,DNS_FROM_SECURITYSAGE,RCVD_IN_DOB X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 06 Oct 2008 02:50:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id B710F2388961; Sun, 5 Oct 2008 19:51:08 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r701918 - /xml/commons/trunk/java/external/src/javax/xml/datatype/DatatypeFactory.java Date: Mon, 06 Oct 2008 02:51:08 -0000 To: commons-cvs@xml.apache.org From: mrglavas@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20081006025108.B710F2388961@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 */ 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); } /**