[OLINGO-902] changes due to OASIS issue ODATA-917 (date handling)

Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
Klaus Straubinger 2016-03-11 10:12:29 +01:00 committed by Christian Amend
parent 92fa7cd62e
commit 62783067c2
3 changed files with 12 additions and 9 deletions

View File

@ -806,7 +806,7 @@ public class FilterSystemQueryITCase extends AbstractParamTecSvcITCase {
@Test
public void dateAddDuration() {
ODataRetrieveResponse<ClientEntitySet> 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<ClientEntitySet> 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);

View File

@ -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)

View File

@ -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) {