You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@olingo.apache.org by "Michael Bolz (JIRA)" <ji...@apache.org> on 2015/05/12 11:09:59 UTC
[jira] [Commented] (OLINGO-657) Milliseconds in DateTime data type
[ https://issues.apache.org/jira/browse/OLINGO-657?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14539557#comment-14539557 ]
Michael Bolz commented on OLINGO-657:
-------------------------------------
Hello [~Michele EnergySys],
I tried to re-produce your issue within the {{EdmSimpleTypeTest}} with following test method:
{code}
@Test
public void olingo657Test() throws Exception {
final EdmSimpleType instance = EdmSimpleTypeKind.DateTime.getEdmSimpleTypeInstance();
Calendar dateTime = Calendar.getInstance();
SimpleDateFormat millisecondsFormat = new SimpleDateFormat("SSS");
EdmFacets facets = null;
dateTime.clear();
dateTime.setTimeZone(TimeZone.getTimeZone("GMT+11:30"));
dateTime.set(2012, 2, 1, 11, 2, 3);
dateTime.add(Calendar.MILLISECOND, 140);
String valueToString = instance.valueToString(dateTime, EdmLiteralKind.DEFAULT, facets);
System.out.println(valueToString);
assertEquals("2012-02-29T23:32:03.14", valueToString);
Calendar ofString = instance.valueOfString(valueToString, EdmLiteralKind.DEFAULT, facets, Calendar.class);
System.out.println("Milliseconds: " + millisecondsFormat.format(ofString.getTime()));
assertEquals("140", millisecondsFormat.format(ofString.getTime()));
assertEquals(dateTime.getTimeInMillis(), ofString.getTimeInMillis());
String valueToLiteralString = instance.valueToString(dateTime, EdmLiteralKind.URI, facets);
System.out.println(valueToLiteralString);
assertEquals("datetime'2012-02-29T23:32:03.14'", valueToLiteralString);
Calendar ofLiteralString = instance.valueOfString(valueToLiteralString, EdmLiteralKind.URI, facets, Calendar.class);
System.out.println("Milliseconds: " + millisecondsFormat.format(ofLiteralString.getTime()));
assertEquals("140", millisecondsFormat.format(ofLiteralString.getTime()));
assertEquals(dateTime.getTimeInMillis(), ofLiteralString.getTimeInMillis());
}
{code}
Unfortunately when I run this test all work as expected.
Can you please check if this test method works for you?
Best regards,
Michael
> Milliseconds in DateTime data type
> ----------------------------------
>
> Key: OLINGO-657
> URL: https://issues.apache.org/jira/browse/OLINGO-657
> Project: Olingo
> Issue Type: Question
> Components: odata2-core
> Affects Versions: V2 2.0.3
> Reporter: M Carissimi
> Assignee: Michael Bolz
>
> Hello,
> we need to represent DateTime properties with milliseconds. I understand that OData V2 supports the use of this using the format datetime’yyyy-mm-ddThh:mm[:ss[.fffffff]]’.
> In our code, a start date time of 11/May/2015 12:15:10.140 (i.e. with milliseconds value of 140) is rendered as
> {code}
> <d:START_DATETIME m:type="Edm.DateTime">2015-05-11T12:15:10.14</d:START_DATETIME>
> {code}
> When we receive a request for an entry with key parameter START_DATETIME=datetime'2015-05-11T12:15:10.14', this is incorrectly parsed in Java because the format {{yyyy-MM-dd'T'hh:mm:ss.SSS}} returns the value *014* instead of *140* for milliseconds.
> Is there a way to ensure our entries use 3 digits for milliseconds so that we get:
> {code}<d:START_DATETIME m:type="Edm.DateTime">2015-05-11T12:15:10.14</d:START_DATETIME>
> {code}
> Alternatively, does Olingo provide utility classes to convert a datetime() String entry into a Java Date or Calendar?
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)