From 62783067c2d729c3b2c6e4248455cf77536bde30 Mon Sep 17 00:00:00 2001 From: Klaus Straubinger Date: Fri, 11 Mar 2016 10:12:29 +0100 Subject: [PATCH] [OLINGO-902] changes due to OASIS issue ODATA-917 (date handling) Signed-off-by: Christian Amend --- .../fit/tecsvc/client/FilterSystemQueryITCase.java | 4 ++-- .../server/core/uri/parser/ExpressionParser.java | 4 +--- .../expression/operation/BinaryOperator.java | 13 +++++++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java index 40dbfd143..9e3a4f57c 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/FilterSystemQueryITCase.java @@ -806,7 +806,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase { @Test public void dateAddDuration() { ODataRetrieveResponse response = - sendRequest(ES_ALL_PRIM, "PropertyDateTimeOffset ge 2012-12-01 add duration'P1DT7H16M23S'"); + sendRequest(ES_ALL_PRIM, "PropertyDate eq 2012-12-01 add duration'P1DT27H16M23S'"); assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); @@ -836,7 +836,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase { @Test public void dateSubDuration() { ODataRetrieveResponse response = - sendRequest(ES_ALL_PRIM, "PropertyDateTimeOffset ge 2012-12-03 sub duration'P0DT16H43M37S'"); + sendRequest(ES_ALL_PRIM, "PropertyDate eq 2012-12-03 sub duration'P0DT16H43M37S'"); assertEquals(1, response.getBody().getEntities().size()); final ClientEntity clientEntity = response.getBody().getEntities().get(0); diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java index a0ec676c1..ee83a53af 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java @@ -1201,13 +1201,11 @@ public class ExpressionParser { } } if ((isType(leftType, EdmPrimitiveTypeKind.DateTimeOffset) + || isType(leftType, EdmPrimitiveTypeKind.Date) || isType(leftType, EdmPrimitiveTypeKind.Duration)) && isType(rightType, EdmPrimitiveTypeKind.Duration)) { return leftType; } - if (isType(leftType, EdmPrimitiveTypeKind.Date) && isType(rightType, EdmPrimitiveTypeKind.Duration)) { - return odata.createPrimitiveTypeInstance(EdmPrimitiveTypeKind.DateTimeOffset); - } if (isSub && (isType(leftType, EdmPrimitiveTypeKind.DateTimeOffset) && isType(rightType, EdmPrimitiveTypeKind.DateTimeOffset) diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java index a870f1aaa..57f2196a8 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/operation/BinaryOperator.java @@ -36,6 +36,7 @@ import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.primitive.EdmNull; public class BinaryOperator { + private static final int MILLISECONDS_PER_DAY = 24 * 60 * 60 * 1000; private static final int FACTOR_SECOND_INT = 1000; private static final BigDecimal FACTOR_SECOND = BigDecimal.valueOf(FACTOR_SECOND_INT); private static final BigInteger EDM_SBYTE_MIN = BigInteger.valueOf(Byte.MIN_VALUE); @@ -260,15 +261,19 @@ public class BinaryOperator { result = new TypedOperand(new BigDecimal(millis).divide(FACTOR_SECOND), primDuration); } else if (right.is(primDuration) && operator == BinaryOperatorKind.ADD) { + // Add only whole days. long millis = left.getTypedValue(Calendar.class).getTimeInMillis() - + (right.getTypedValue(BigDecimal.class).longValue() * FACTOR_SECOND_INT); + + ((right.getTypedValue(BigDecimal.class).longValue() * FACTOR_SECOND_INT) + / MILLISECONDS_PER_DAY) * MILLISECONDS_PER_DAY; - result = new TypedOperand(new Timestamp(millis), primDateTimeOffset); + result = new TypedOperand(new Timestamp(millis), primDate); } else if (right.is(primDuration) && operator == BinaryOperatorKind.SUB) { + // Subtract only whole days. long millis = left.getTypedValue(Calendar.class).getTimeInMillis() - - (right.getTypedValue(BigDecimal.class).longValue() * FACTOR_SECOND_INT); + - ((right.getTypedValue(BigDecimal.class).longValue() * FACTOR_SECOND_INT) + / MILLISECONDS_PER_DAY) * MILLISECONDS_PER_DAY; - result = new TypedOperand(new Timestamp(millis), primDateTimeOffset); + result = new TypedOperand(new Timestamp(millis), primDate); } } else if (left.is(primDuration)) { if (right.is(primDuration) && operator == BinaryOperatorKind.ADD) {