You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@vxquery.apache.org by pr...@apache.org on 2012/08/03 04:12:48 UTC
svn commit: r1368770 - in
/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast:
CastToDateOperation.java CastToTimeOperation.java
Author: prestonc
Date: Fri Aug 3 02:12:48 2012
New Revision: 1368770
URL: http://svn.apache.org/viewvc?rev=1368770&view=rev
Log:
Found many issues with date related functions primarily with how timezones were handled. Found two more files.
Modified:
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java
incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToTimeOperation.java
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java?rev=1368770&r1=1368769&r2=1368770&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToDateOperation.java Fri Aug 3 02:12:48 2012
@@ -40,6 +40,7 @@ public class CastToDateOperation extends
int index = 0;
long[] date = new long[5];
boolean positiveTimezone = false;
+ boolean negativeYear = false;
// Set defaults
date[3] = DateTime.TIMEZONE_HOUR_NULL;
@@ -47,18 +48,33 @@ public class CastToDateOperation extends
while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
if (Character.isDigit(c)) {
+ // Add the digit to the current numbered index.
date[index] = date[index] * 10 + Character.getNumericValue(c);
+ } else if (c == Character.valueOf('-') && index == 0 && date[index] == 0) {
+ // If the first dash does not have a number in front, its a negative year.
+ negativeYear = true;
} else if (c == Character.valueOf('-') || c == Character.valueOf(':')) {
+ // The basic case for going to the next number in the series.
++index;
+ date[index] = 0;
} else if (c == Character.valueOf('+')) {
- positiveTimezone = true;
+ // Moving to the next number and logging this is now a positive timezone offset.
++index;
+ date[index] = 0;
+ positiveTimezone = true;
+ } else if (c == Character.valueOf('Z')) {
+ // Set the timezone to UTC.
+ date[3] = 0;
+ date[4] = 0;
} else {
// Invalid date format.
throw new SystemException(ErrorCode.FORG0001);
}
}
- // Final touches on timezone.
+ // Final touches on year and timezone.
+ if (negativeYear) {
+ date[0] *= -1;
+ }
if (!positiveTimezone && date[3] != DateTime.TIMEZONE_HOUR_NULL) {
date[3] *= -1;
}
Modified: incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToTimeOperation.java
URL: http://svn.apache.org/viewvc/incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToTimeOperation.java?rev=1368770&r1=1368769&r2=1368770&view=diff
==============================================================================
--- incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToTimeOperation.java (original)
+++ incubator/vxquery/trunk/vxquery/vxquery-core/src/main/java/org/apache/vxquery/runtime/functions/cast/CastToTimeOperation.java Fri Aug 3 02:12:48 2012
@@ -21,7 +21,7 @@ public class CastToTimeOperation extends
dOut.write(ValueTag.XS_TIME_TAG);
dOut.write((byte) datetimep.getHour());
dOut.write((byte) datetimep.getMinute());
- dOut.writeLong(datetimep.getMilliSecond());
+ dOut.writeInt((int) datetimep.getMilliSecond());
dOut.write((byte) datetimep.getTimezoneHour());
dOut.write((byte) datetimep.getTimezoneMinute());
}
@@ -43,19 +43,29 @@ public class CastToTimeOperation extends
while ((c = charIterator.next()) != ICharacterIterator.EOS_CHAR) {
if (Character.isDigit(c)) {
+ // Add the digit to the current numbered index.
date[index] = date[index] * 10 + Character.getNumericValue(c);
if (pastDecimal) {
--decimalPlace;
}
} else if (c == Character.valueOf('-') || c == Character.valueOf(':')) {
+ // The basic case for going to the next number in the series.
++index;
pastDecimal = false;
+ date[index] = 0;
} else if (c == Character.valueOf('+')) {
+ // Moving to the next number and logging this is now a positive timezone offset.
+ ++index;
pastDecimal = false;
+ date[index] = 0;
positiveTimezone = true;
- ++index;
} else if (c == Character.valueOf('.')) {
+ // Only used by the seconds attribute.
pastDecimal = true;
+ } else if (c == Character.valueOf('Z')) {
+ // Set the timezone to UTC.
+ date[3] = 0;
+ date[4] = 0;
} else {
// Invalid date format.
throw new SystemException(ErrorCode.FORG0001);