You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2013/09/23 09:26:50 UTC
git commit: Fix for OLINGO-21
Updated Branches:
refs/heads/master 37a4cdeae -> 80c0e6cef
Fix for OLINGO-21
Project: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/commit/80c0e6ce
Tree: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/tree/80c0e6ce
Diff: http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/diff/80c0e6ce
Branch: refs/heads/master
Commit: 80c0e6cef4f0ee995ea6ac1cfc9ed9c5ffba6f93
Parents: 37a4cde
Author: Michael Bolz <mi...@apache.org>
Authored: Mon Sep 23 09:19:23 2013 +0200
Committer: Michael Bolz <mi...@apache.org>
Committed: Mon Sep 23 09:20:26 2013 +0200
----------------------------------------------------------------------
.../olingo/odata2/core/edm/EdmDateTime.java | 2 +-
.../odata2/core/edm/EdmSimpleTypeTest.java | 53 ++++++++++++++++++++
2 files changed, 54 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80c0e6ce/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTime.java
----------------------------------------------------------------------
diff --git a/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTime.java b/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTime.java
index 1e47e41..e33d217 100644
--- a/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTime.java
+++ b/odata-core/src/main/java/org/apache/olingo/odata2/core/edm/EdmDateTime.java
@@ -186,7 +186,7 @@ public class EdmDateTime extends AbstractSimpleType {
appendTwoDigits(result, dateTimeValue.get(Calendar.SECOND));
try {
- appendMilliseconds(result, timeInMillis, facets);
+ appendMilliseconds(result, dateTimeValue.get(Calendar.MILLISECOND), facets);
} catch (final IllegalArgumentException e) {
throw new EdmSimpleTypeException(EdmSimpleTypeException.VALUE_FACETS_NOT_MATCHED.addContent(value, facets), e);
}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata2/blob/80c0e6ce/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
----------------------------------------------------------------------
diff --git a/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java b/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
index 9e22706..1a7ba42 100644
--- a/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
+++ b/odata-core/src/test/java/org/apache/olingo/odata2/core/edm/EdmSimpleTypeTest.java
@@ -573,6 +573,59 @@ public class EdmSimpleTypeTest extends BaseTest {
EdmSimpleTypeException.VALUE_TYPE_NOT_SUPPORTED);
expectErrorInValueToString(instance, dateTime, null, null, EdmSimpleTypeException.LITERAL_KIND_MISSING);
}
+
+ /**
+ * Extended test for combination of precision with dates before 1970 (and for regression after 1970)
+ */
+ @Test
+ public void valueToStringDateTimeSpecial() throws Exception {
+
+ for (int precision = 0; precision < 3; precision++) {
+ try {
+ assertValueToStringDateTimeSpecial(1954, 7, 4, precision);
+ fail("Expected exception not thrown");
+ } catch(EdmSimpleTypeException e) { }
+
+ try {
+ assertValueToStringDateTimeSpecial(1999, 7, 4, precision);
+ fail("Expected exception not thrown");
+ } catch(EdmSimpleTypeException e) { }
+ }
+
+ for (int precision = 3; precision < 6; precision++) {
+ assertValueToStringDateTimeSpecial(1954, 7, 4, precision);
+ assertValueToStringDateTimeSpecial(1999, 7, 4, precision);
+ }
+ }
+
+ private void assertValueToStringDateTimeSpecial(int year, int month, int day, int precision) throws Exception {
+ final EdmSimpleType instance = EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance();
+ final StringBuilder regExToMatch = new StringBuilder();// = new StringBuilder("1954-08-04T\\d\\d:\\d\\d:\\d\\d");
+ regExToMatch.append(year).append("-");
+ if(month < 9) {
+ regExToMatch.append("0");
+ }
+ // add '1' to the month because java calendar month begin with '0'
+ regExToMatch.append(month+1).append("-");
+ if(day < 10) {
+ regExToMatch.append("0");
+ }
+ regExToMatch.append(day).append("T\\d\\d:\\d\\d:\\d\\d");
+
+ if(precision > 0) {
+ regExToMatch.append("\\.");
+ }
+ for (int i = 0; i < precision; i++) {
+ regExToMatch.append("\\d");
+ }
+ Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ date.set(year, month, day);
+
+ //
+ String formated = instance.valueToString(date, EdmLiteralKind.DEFAULT, getPrecisionScaleFacets(precision, null));
+ assertTrue("Formated date '" + formated + "' is wrong for precision '" + precision +
+ "'. (used regex = [" + regExToMatch.toString() + "])", formated.matches(regExToMatch.toString()));
+ }
@Test
public void valueToStringDateTimeOffset() throws Exception {