[ 
https://issues.apache.org/jira/browse/OLINGO-21?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13772980#comment-13772980
 ] 

Michael Bolz commented on OLINGO-21:
------------------------------------

Following change in {{EdmDateTime.appendMilliseconds()}} fixes the issue, but 
looks a little bit strange.

{code}
  protected static void appendMilliseconds(final StringBuilder result, final 
long milliseconds, final EdmFacets facets) throws IllegalArgumentException {
    final int digits = milliseconds % 1000 == 0 ? 0 : milliseconds % 100 == 0 ? 
1 : milliseconds % 10 == 0 ? 2 : 3;
    if (digits > 0) {
      result.append('.');
      for (int d = 100; d > 0; d /= 10) {
        final byte digit = (byte) (milliseconds % (d * 10) / d);
        if (digit > 0 || milliseconds % d > 0) {
          result.append((char) ('0' + digit));
        } else if (milliseconds < 0) { /* fix for negative stored calendar 
milliseconds */
          result.append('0');
        }
      }
    }

    if (facets != null && facets.getPrecision() != null) {
      final int precision = facets.getPrecision();
      if (digits > precision) {
        throw new IllegalArgumentException();
      }
      if (digits == 0 && precision > 0) {
        result.append('.');
      }
      for (int i = digits; i < precision; i++) {
        result.append('0');
      }
    }
  }
{code}
                
> Incorrect millisecond handling in EdmDateTime 
> ----------------------------------------------
>
>                 Key: OLINGO-21
>                 URL: https://issues.apache.org/jira/browse/OLINGO-21
>             Project: Olingo
>          Issue Type: Bug
>            Reporter: Michael Bolz
>            Assignee: Michael Bolz
>
> In rare cases a 'dot' is attached during serialization of EdmDateTime in a 
> String.
> Example:
>     Calendar date = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
>     date.set(1954, 7, 4);
>     String formated = instance.valueToString(date, EdmLiteralKind.DEFAULT, 
> getPrecisionScaleFacets(3, null));
> Results in ~ "1954-08-04T09:27:55." 
> The 'dot' at the end of the string is incorrect.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to