From: <br...@us...> - 2006-06-01 12:44:32
|
Revision: 3641 Author: brihaye Date: 2006-06-01 05:44:10 -0700 (Thu, 01 Jun 2006) ViewCVS: http://svn.sourceforge.net/exist/?rev=3641&view=rev Log Message: ----------- Quick duration conversions to make XQTS happier. Modified Paths: -------------- trunk/eXist-1.0/src/org/exist/xquery/value/DayTimeDurationValue.java trunk/eXist-1.0/src/org/exist/xquery/value/DurationValue.java trunk/eXist-1.0/src/org/exist/xquery/value/YearMonthDurationValue.java Modified: trunk/eXist-1.0/src/org/exist/xquery/value/DayTimeDurationValue.java =================================================================== --- trunk/eXist-1.0/src/org/exist/xquery/value/DayTimeDurationValue.java 2006-06-01 11:30:55 UTC (rev 3640) +++ trunk/eXist-1.0/src/org/exist/xquery/value/DayTimeDurationValue.java 2006-06-01 12:44:10 UTC (rev 3641) @@ -149,9 +149,9 @@ case Type.ITEM: case Type.ATOMIC: case Type.DAY_TIME_DURATION: - return this; - case Type.STRING: - return new StringValue(getStringValue()); + return new DayTimeDurationValue(getCanonicalDuration()); + case Type.STRING: + return new StringValue(getCanonicalDuration().toString()); case Type.DURATION: return new DurationValue(TimeUtils.getInstance().newDuration( duration.getSign() >= 0, null, null, @@ -167,7 +167,7 @@ //case Type.DECIMAL: //return new DecimalValue(monthsValueSigned().doubleValue()); case Type.UNTYPED_ATOMIC : - return new UntypedAtomicValue(getStringValue()); + return new UntypedAtomicValue(getCanonicalDuration().toString()); default: throw new XPathException("XPTY0004: cannot cast '" + Type.getTypeName(this.getItemType()) + "(\"" + getStringValue() + "\")' to " + Modified: trunk/eXist-1.0/src/org/exist/xquery/value/DurationValue.java =================================================================== --- trunk/eXist-1.0/src/org/exist/xquery/value/DurationValue.java 2006-06-01 11:30:55 UTC (rev 3640) +++ trunk/eXist-1.0/src/org/exist/xquery/value/DurationValue.java 2006-06-01 12:44:10 UTC (rev 3641) @@ -230,10 +230,14 @@ case Type.DURATION: return this; case Type.YEAR_MONTH_DURATION: - return new YearMonthDurationValue(TimeUtils.getInstance().newDurationYearMonth( - duration.getSign() >= 0, - (BigInteger) duration.getField(DatatypeConstants.YEARS), - (BigInteger) duration.getField(DatatypeConstants.MONTHS))); + if (duration.getField(DatatypeConstants.YEARS) != null && + duration.getField(DatatypeConstants.MONTHS) != null) + return new YearMonthDurationValue(TimeUtils.getInstance().newDurationYearMonth( + duration.getSign() >= 0, + (BigInteger) duration.getField(DatatypeConstants.YEARS), + (BigInteger) duration.getField(DatatypeConstants.MONTHS))); + else + return new YearMonthDurationValue(YearMonthDurationValue.CANONICAL_ZERO_DURATION); case Type.DAY_TIME_DURATION: return new DayTimeDurationValue(TimeUtils.getInstance().newDuration( duration.getSign() >= 0, Modified: trunk/eXist-1.0/src/org/exist/xquery/value/YearMonthDurationValue.java =================================================================== --- trunk/eXist-1.0/src/org/exist/xquery/value/YearMonthDurationValue.java 2006-06-01 11:30:55 UTC (rev 3640) +++ trunk/eXist-1.0/src/org/exist/xquery/value/YearMonthDurationValue.java 2006-06-01 12:44:10 UTC (rev 3641) @@ -42,13 +42,12 @@ YearMonthDurationValue(Duration duration) throws XPathException { super(duration); - if ( - duration.isSet(DatatypeConstants.DAYS) || - duration.isSet(DatatypeConstants.HOURS) || - duration.isSet(DatatypeConstants.MINUTES) || - duration.isSet(DatatypeConstants.SECONDS) - ) - throw new XPathException("the value '" + duration + "' is not an xdt:yearMonthDuration since it specified days, hours, minutes or seconds values"); + if (duration.isSet(DatatypeConstants.DAYS) || + duration.isSet(DatatypeConstants.HOURS) || + duration.isSet(DatatypeConstants.MINUTES) || + duration.isSet(DatatypeConstants.SECONDS)) + throw new XPathException("The value '" + duration + "' is not an " + Type.getTypeName(getType()) + + " since it specifies days, hours, minutes or seconds values"); } public YearMonthDurationValue(String str) throws XPathException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |