bug fixing and more test cases for date type.

git-svn-id: https://asterixdb.googlecode.com/svn/branches/asterix_stabilization_temp_missing_tests@1286 eaa15691-b419-025a-1212-ee371bd00084
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
index 44fcf7c..d5d703d 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateConstructorDescriptor.java
@@ -86,8 +86,17 @@
 
                                 int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
 
-                                charAccessor.reset(serString, 3, stringLength);
-                                long chrononTimeInMs = ADateParserFactory.parseDatePart(charAccessor, true);
+                                int startOffset = 3;
+                                while (serString[startOffset] == ' ') {
+                                    startOffset++;
+                                }
+                                int endOffset = stringLength - 1 + 3;
+                                while (serString[endOffset] == ' ') {
+                                    endOffset--;
+                                }
+
+                                charAccessor.reset(serString, startOffset, endOffset - startOffset + 1);
+                                long chrononTimeInMs = ADateParserFactory.parseDatePart(charAccessor);
 
                                 short temp = 0;
                                 if (chrononTimeInMs < 0
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
index 6a5783b..104dc32 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/ADateTimeConstructorDescriptor.java
@@ -85,23 +85,39 @@
 
                                 int stringLength = (serString[1] & 0xff << 8) + (serString[2] & 0xff << 0);
 
-                                charAccessor.reset(serString, 3, stringLength);
+                                int startOffset = 3;
+                                int endOffset = stringLength - 1 + 3;
+
+                                // skip leading space
+                                while (serString[startOffset] == ' ') {
+                                    startOffset++;
+                                }
+
+                                // skip tailing space
+                                while (serString[endOffset] == ' ') {
+                                    endOffset--;
+                                }
+
+                                charAccessor.reset(serString, startOffset, endOffset - startOffset + 1);
 
                                 // +1 if it is negative (-)
                                 short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
 
-                                if (charAccessor.getCharAt(timeOffset + 10) != 'T'
-                                        && charAccessor.getCharAt(timeOffset + 8) != 'T') {
-                                    throw new AlgebricksException(errorMessage + ": missing T");
+                                timeOffset += 8;
+
+                                if (charAccessor.getCharAt(timeOffset) != 'T') {
+                                    timeOffset += 2;
+                                    if (charAccessor.getCharAt(timeOffset) != 'T') {
+                                        throw new AlgebricksException(errorMessage + ": missing T");
+                                    }
                                 }
 
-                                // if extended form 11, else 9
-                                timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11)
-                                        : (short) (9);
+                                charAccessor.reset(serString, startOffset, timeOffset);
 
-                                long chrononTimeInMs = ADateParserFactory.parseDatePart(charAccessor, false);
+                                long chrononTimeInMs = ADateParserFactory.parseDatePart(charAccessor);
 
-                                charAccessor.reset(serString, 3 + timeOffset, stringLength - timeOffset);
+                                charAccessor.reset(serString, startOffset + timeOffset + 1, endOffset
+                                        - (startOffset + timeOffset + 1) + 1);
 
                                 chrononTimeInMs += ATimeParserFactory.parseTimePart(charAccessor);
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
index e1a12f8..3ac64f3 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateConstructorDescriptor.java
@@ -101,15 +101,15 @@
 
                                 // start date
                                 charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
-                                long intervalStart = ADateParserFactory.parseDatePart(charAccessor, true)
+                                long intervalStart = ADateParserFactory.parseDatePart(charAccessor)
                                         / GregorianCalendarSystem.CHRONON_OF_DAY;
-                                // end date
 
+                                // end date
                                 stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
                                         + (argOut1.getByteArray()[2] & 0xff << 0);
 
                                 charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
-                                long intervalEnd = ADateParserFactory.parseDatePart(charAccessor, true)
+                                long intervalEnd = ADateParserFactory.parseDatePart(charAccessor)
                                         / GregorianCalendarSystem.CHRONON_OF_DAY;
 
                                 if (intervalEnd < intervalStart) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
index 72a8e37..35d1a02 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromDateTimeConstructorDescriptor.java
@@ -95,46 +95,46 @@
                                 nullSerde.serialize(ANull.NULL, out);
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
                                     && argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                                // start date
-
+                                // start datetime
                                 int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
                                         + (argOut0.getByteArray()[2] & 0xff << 0);
 
                                 charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
                                 // get offset for time part: +1 if it is negative (-)
                                 short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
-
-                                if (charAccessor.getCharAt(timeOffset + 10) != 'T'
-                                        && charAccessor.getCharAt(timeOffset + 8) != 'T') {
-                                    throw new AlgebricksException(errorMessage + ": missing T");
+                                timeOffset += 8;
+                                if (charAccessor.getCharAt(timeOffset) != 'T') {
+                                    timeOffset += 2;
+                                    if (charAccessor.getCharAt(timeOffset) != 'T') {
+                                        throw new AlgebricksException(errorMessage + ": missing T");
+                                    }
                                 }
 
-                                // if extended form 11, else 9
-                                timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11)
-                                        : (short) (9);
-                                long intervalStart = ADateParserFactory.parseDatePart(charAccessor, false);
-                                charAccessor.reset(argOut0.getByteArray(), 3 + timeOffset, stringLength - timeOffset);
+                                charAccessor.reset(argOut0.getByteArray(), 3, timeOffset);
+                                long intervalStart = ADateParserFactory.parseDatePart(charAccessor);
+                                charAccessor.reset(argOut0.getByteArray(), 3 + timeOffset + 1, stringLength
+                                        - timeOffset - 1);
                                 intervalStart += ATimeParserFactory.parseTimePart(charAccessor);
 
-                                // end date
-
+                                // end datetime
                                 stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
                                         + (argOut1.getByteArray()[2] & 0xff << 0);
 
                                 charAccessor.reset(argOut1.getByteArray(), 3, stringLength);
                                 // get offset for time part: +1 if it is negative (-)
                                 timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
-
-                                if (charAccessor.getCharAt(timeOffset + 10) != 'T'
-                                        && charAccessor.getCharAt(timeOffset + 8) != 'T') {
-                                    throw new AlgebricksException(errorMessage + ": missing T");
+                                timeOffset += 8;
+                                if (charAccessor.getCharAt(timeOffset) != 'T') {
+                                    timeOffset += 2;
+                                    if (charAccessor.getCharAt(timeOffset) != 'T') {
+                                        throw new AlgebricksException(errorMessage + ": missing T");
+                                    }
                                 }
 
-                                // if extended form 11, else 9
-                                timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11)
-                                        : (short) (9);
-                                long intervalEnd = ADateParserFactory.parseDatePart(charAccessor, false);
-                                charAccessor.reset(argOut1.getByteArray(), 3 + timeOffset, stringLength - timeOffset);
+                                charAccessor.reset(argOut1.getByteArray(), 3, timeOffset);
+                                long intervalEnd = ADateParserFactory.parseDatePart(charAccessor);
+                                charAccessor.reset(argOut1.getByteArray(), 3 + timeOffset + 1, stringLength
+                                        - timeOffset - 1);
                                 intervalEnd += ATimeParserFactory.parseTimePart(charAccessor);
 
                                 if (intervalEnd < intervalStart) {
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
index 3ce722a..73080c8 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalFromTimeConstructorDescriptor.java
@@ -96,7 +96,6 @@
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
                                     && argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
                                 // start date
-
                                 int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
                                         + (argOut0.getByteArray()[2] & 0xff << 0);
 
@@ -107,7 +106,6 @@
                                 }
 
                                 // end date
-
                                 stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
                                         + (argOut1.getByteArray()[2] & 0xff << 0);
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
index 23fdb07..6429daa 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateConstructorDescriptor.java
@@ -99,15 +99,15 @@
                                 nullSerde.serialize(ANull.NULL, out);
                             } else if (argOut0.getByteArray()[0] == SER_STRING_TYPE_TAG
                                     && argOut1.getByteArray()[0] == SER_STRING_TYPE_TAG) {
-                                // start date
 
+                                // start date
                                 int stringLength = (argOut0.getByteArray()[1] & 0xff << 8)
                                         + (argOut0.getByteArray()[2] & 0xff << 0);
 
                                 charAccessor.reset(argOut0.getByteArray(), 3, stringLength);
-                                long intervalStart = ADateParserFactory.parseDatePart(charAccessor, true);
-                                // duration
+                                long intervalStart = ADateParserFactory.parseDatePart(charAccessor);
 
+                                // duration
                                 stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
                                         + (argOut1.getByteArray()[2] & 0xff << 0);
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
index 91c45df..92469f0 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/evaluators/constructors/AIntervalStartFromDateTimeConstructorDescriptor.java
@@ -108,20 +108,20 @@
                                 // get offset for time part: +1 if it is negative (-)
                                 short timeOffset = (short) ((charAccessor.getCharAt(0) == '-') ? 1 : 0);
 
-                                if (charAccessor.getCharAt(timeOffset + 10) != 'T'
-                                        && charAccessor.getCharAt(timeOffset + 8) != 'T') {
-                                    throw new AlgebricksException(errorMessage + ": missing T");
+                                timeOffset += 8;
+
+                                if (charAccessor.getCharAt(timeOffset) != 'T') {
+                                    timeOffset += 2;
+                                    if (charAccessor.getCharAt(timeOffset) != 'T') {
+                                        throw new AlgebricksException(errorMessage + ": missing T");
+                                    }
                                 }
 
-                                // if extended form 11, else 9
-                                timeOffset += (charAccessor.getCharAt(timeOffset + 13) == ':') ? (short) (11)
-                                        : (short) (9);
-                                long intervalStart = ADateParserFactory.parseDatePart(charAccessor, false);
-                                charAccessor.reset(argOut0.getByteArray(), 3 + timeOffset, stringLength - timeOffset);
+                                long intervalStart = ADateParserFactory.parseDatePart(charAccessor);
+                                charAccessor.reset(argOut0.getByteArray(), 3 + timeOffset + 1, stringLength - timeOffset - 1);
                                 intervalStart += ATimeParserFactory.parseTimePart(charAccessor);
 
                                 // duration
-
                                 stringLength = (argOut1.getByteArray()[1] & 0xff << 8)
                                         + (argOut1.getByteArray()[2] & 0xff << 0);
 
diff --git a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
index 2e64ad4..b32110b 100644
--- a/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
+++ b/asterix-runtime/src/main/java/edu/uci/ics/asterix/runtime/operators/file/ADMDataParser.java
@@ -234,7 +234,7 @@
                 try {
                     if (checkType(ATypeTag.INTERVAL, objectType, out)) {
                         if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
-                            if (admLexer.next() == AdmLexer.TOKEN_STRING_CONS) {
+                            if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
                                 AIntervalSerializerDeserializer.parseDate(admLexer.getLastTokenImage(), out);
 
                                 if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
@@ -252,7 +252,7 @@
                 try {
                     if (checkType(ATypeTag.INTERVAL, objectType, out)) {
                         if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
-                            if (admLexer.next() == AdmLexer.TOKEN_STRING_CONS) {
+                            if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
                                 AIntervalSerializerDeserializer.parseTime(admLexer.getLastTokenImage(), out);
 
                                 if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
@@ -270,7 +270,7 @@
                 try {
                     if (checkType(ATypeTag.INTERVAL, objectType, out)) {
                         if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_OPEN) {
-                            if (admLexer.next() == AdmLexer.TOKEN_STRING_CONS) {
+                            if (admLexer.next() == AdmLexer.TOKEN_STRING_LITERAL) {
                                 AIntervalSerializerDeserializer.parseDatetime(admLexer.getLastTokenImage(), out);
 
                                 if (admLexer.next() == AdmLexer.TOKEN_CONSTRUCTOR_CLOSE) {
diff --git a/asterix-runtime/src/main/resources/adm.grammar b/asterix-runtime/src/main/resources/adm.grammar
index 56c7212..4d4158f 100644
--- a/asterix-runtime/src/main/resources/adm.grammar
+++ b/asterix-runtime/src/main/resources/adm.grammar
@@ -26,9 +26,9 @@
 RECTANGLE_CONS = string(rectangle)
 CIRCLE_CONS    = string(circle)
 TIME_CONS      = string(time)
-INTERVAL_TIME_CONS      = string(interval_time)
-INTERVAL_DATE_CONS      = string(interval_date)
-INTERVAL_DATETIME_CONS  = string(interval_datetime)
+INTERVAL_TIME_CONS      = string(interval-time)
+INTERVAL_DATE_CONS      = string(interval-date)
+INTERVAL_DATETIME_CONS  = string(interval-datetime)
 
 NULL_LITERAL   = string(null)
 TRUE_LITERAL   = string(true)