You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ra...@apache.org on 2016/02/10 20:09:47 UTC

[3/3] olingo-odata4 git commit: OLINGO-864: Refining the Edm.Date and Edm.Time behavior not to assume GMT but use default timezone of the JVM

OLINGO-864: Refining the Edm.Date and Edm.Time behavior not to assume GMT but use default timezone of the JVM


Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/7b26cc6e
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/7b26cc6e
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/7b26cc6e

Branch: refs/heads/OLINGO-864
Commit: 7b26cc6ee7515b4f2657fe9756862882ead7f26d
Parents: b317b90 f63bba7
Author: Ramesh Reddy <ra...@jboss.org>
Authored: Wed Feb 3 11:49:52 2016 -0600
Committer: Ramesh Reddy <ra...@jboss.org>
Committed: Wed Feb 10 13:04:42 2016 -0600

----------------------------------------------------------------------
 .../client/AbstractParamTecSvcITCase.java       | 14 +++++
 .../commons/core/edm/primitivetype/EdmDate.java |  5 +-
 .../edm/primitivetype/EdmDateTimeOffset.java    | 62 ++++++++++++--------
 .../core/edm/primitivetype/EdmTimeOfDay.java    | 20 ++-----
 .../core/edm/primitivetype/EdmDateTest.java     |  1 -
 .../primitivetype/EdmDateTimeOffsetTest.java    |  9 ++-
 .../edm/primitivetype/EdmTimeOfDayTest.java     | 23 ++++++--
 .../olingo/server/tecsvc/data/DataCreator.java  | 10 +++-
 .../server/tecsvc/data/DataProviderTest.java    | 14 +++++
 .../json/ODataJsonSerializerTest.java           | 13 ++++
 10 files changed, 116 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7b26cc6e/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
----------------------------------------------------------------------
diff --cc fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
index d6e35a3,a4d8a67..dc2b940
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
@@@ -63,4 -67,14 +67,14 @@@ public abstract class AbstractParamTecS
      assertTrue(n instanceof Number);
      assertEquals(value, ((Number) n).intValue());
    }
+   
+   @Before
+   public void setup() {
 -    DataProvider.setDefaultTimeZone("GMT");
++    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+   }
+   
+   @After
+   public void teardown() {
 -    DataProvider.setDefaultTimeZone(TimeZone.getDefault().getID());
++    TimeZone.setDefault(TimeZone.getDefault());
+   }  
  }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7b26cc6e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java
----------------------------------------------------------------------
diff --cc lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java
index 3eddca0,8588a5c..b0903ed
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDate.java
@@@ -48,7 -47,7 +47,7 @@@ public final class EdmDate extends Sing
        final Boolean isNullable, final Integer maxLength, final Integer precision,
        final Integer scale, final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
  
-     final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
 -    final Calendar dateTimeValue = Calendar.getInstance(EdmDateTimeOffset.getDefaultTimeZone());
++    final Calendar dateTimeValue = Calendar.getInstance();
      dateTimeValue.clear();
  
      final Matcher matcher = PATTERN.matcher(value);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7b26cc6e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
----------------------------------------------------------------------
diff --cc lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
index a7f57d1,63c2c3c..990e1f5
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmDateTimeOffset.java
@@@ -203,21 -211,27 +211,27 @@@ public final class EdmDateTimeOffset ex
     * @return the value as {@link Calendar}
     * @throws EdmPrimitiveTypeException if the type of the value is not supported
     */
-   protected static <T> Calendar createDateTime(final T value) throws EdmPrimitiveTypeException {
+   protected static <T> Calendar createDateTime(final T value, boolean isLocal) throws EdmPrimitiveTypeException {
      Calendar dateTimeValue;
-     if(value instanceof Time) {
-       dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
-       dateTimeValue.setTimeInMillis(((Time) value).getTime());
-     } else if (value instanceof Date) {
-       // Although java.util.Date, as stated in its documentation,
-       // "is intended to reflect coordinated universal time (UTC)",
-       // its getName() method uses the default time zone. And so do we.
-       dateTimeValue = Calendar.getInstance();
+     if (value instanceof Date) {
+       TimeZone tz;
+       if (isLocal) {
 -        tz = getDefaultTimeZone();
++        tz = TimeZone.getDefault();
+       } else {
+     	tz = TimeZone.getTimeZone("GMT");  
+       }
+       dateTimeValue = Calendar.getInstance(tz);
        dateTimeValue.setTime((Date) value);
      } else if (value instanceof Calendar) {
        dateTimeValue = (Calendar) ((Calendar) value).clone();
      } else if (value instanceof Long) {
-       dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+       TimeZone tz;
+       if (isLocal) {
 -        tz = getDefaultTimeZone();
++        tz = TimeZone.getDefault();
+       } else {
+         tz = TimeZone.getTimeZone("GMT");  
+       }
+       dateTimeValue = Calendar.getInstance(tz);
        dateTimeValue.setTimeInMillis((Long) value);
      } else {
        throw new EdmPrimitiveTypeException("The value type " + value.getClass() + " is not supported.");

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7b26cc6e/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java
----------------------------------------------------------------------
diff --cc lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java
index 7595e51,06ba239..de0d8d6
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/primitivetype/EdmTimeOfDay.java
@@@ -52,7 -51,7 +51,7 @@@ public final class EdmTimeOfDay extend
        throw new EdmPrimitiveTypeException("The literal '" + value + "' has illegal content.");
      }
  
-     final Calendar dateTimeValue = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
 -    final Calendar dateTimeValue = Calendar.getInstance(EdmDateTimeOffset.getDefaultTimeZone());
++    final Calendar dateTimeValue = Calendar.getInstance();
      dateTimeValue.clear();
      dateTimeValue.set(Calendar.HOUR_OF_DAY, Byte.parseByte(matcher.group(1)));
      dateTimeValue.set(Calendar.MINUTE, Byte.parseByte(matcher.group(2)));

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7b26cc6e/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --cc lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index 5c60b38,5c60b38..3de7c37
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@@ -28,7 -28,7 +28,6 @@@ import java.util.Calendar
  import java.util.HashMap;
  import java.util.List;
  import java.util.Map;
--import java.util.TimeZone;
  import java.util.UUID;
  
  import org.apache.olingo.commons.api.Constants;
@@@ -1187,9 -1187,9 +1186,10 @@@ public class DataCreator 
  
    protected static Calendar getDateTime(final int year, final int month, final int day,
        final int hour, final int minute, final int second) {
--    Calendar dateTime = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
++    Calendar dateTime = Calendar.getInstance();
      dateTime.clear();
      dateTime.set(year, month - 1, day, hour, minute, second);
++    dateTime.set(Calendar.MILLISECOND, 0);
      return dateTime;
    }
  
@@@ -1201,8 -1201,8 +1201,12 @@@
    }
  
    protected static Calendar getTime(final int hour, final int minute, final int second) {
--    Calendar time = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
++    Calendar time = Calendar.getInstance();
      time.clear();
++    time.set(Calendar.YEAR, 1970);
++    time.set(Calendar.MONTH, Calendar.JANUARY);
++    time.set(Calendar.DAY_OF_MONTH, 1);
++    time.set(Calendar.MILLISECOND, 0);    
      time.set(Calendar.HOUR_OF_DAY, hour);
      time.set(Calendar.MINUTE, minute);
      time.set(Calendar.SECOND, second);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7b26cc6e/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
----------------------------------------------------------------------
diff --cc lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
index 6bd6463,b2bf587..dddafa2
--- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
+++ b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/DataProviderTest.java
@@@ -52,6 -55,16 +55,16 @@@ public class DataProviderTest 
    private final EdmEntitySet esMixPrimCollComp = entityContainer.getEntitySet("ESMixPrimCollComp");
    private final EdmEntitySet esMedia = entityContainer.getEntitySet("ESMedia");
  
+   @Before
+   public void setup() {
 -    DataProvider.setDefaultTimeZone("GMT");
++    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
+   }
+   
+   @After
+   public void teardown() {
 -    DataProvider.setDefaultTimeZone(TimeZone.getDefault().getID());
 -  }
++    TimeZone.setDefault(TimeZone.getDefault());
++  } 
+   
    @Test
    public void esAllPrimEntity() throws Exception {
      final DataProvider dataProvider = new DataProvider(oData, edm);

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7b26cc6e/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --cc lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index 7761b1d,7761b1d..8a7fca4
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@@ -22,6 -22,6 +22,7 @@@ import java.io.InputStream
  import java.net.URI;
  import java.util.Arrays;
  import java.util.Collections;
++import java.util.TimeZone;
  
  import org.apache.commons.io.IOUtils;
  import org.apache.olingo.commons.api.data.ComplexValue;
@@@ -62,7 -62,7 +63,9 @@@ import org.apache.olingo.server.tecsvc.
  import org.apache.olingo.server.tecsvc.data.DataProvider;
  import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
  import org.hamcrest.CoreMatchers;
++import org.junit.After;
  import org.junit.Assert;
++import org.junit.Before;
  import org.junit.Test;
  import org.mockito.Mockito;
  
@@@ -78,6 -78,6 +81,16 @@@ public class ODataJsonSerializerTest 
        new ODataJsonSerializer(ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true"));
    private final UriHelper helper = odata.createUriHelper();
  
++  @Before
++  public void setup() {
++    TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
++  }
++  
++  @After
++  public void teardown() {
++    TimeZone.setDefault(TimeZone.getDefault());
++  }
++  
    @Test
    public void entitySimple() throws Exception {
      final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");