artiya4u / google-http-java-client

Automatically exported from code.google.com/p/google-http-java-client
0 stars 0 forks source link

DateTime ISO 8061 is not parsed #168

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Please add support of DateTime in ISO 8061 format:

YYYY-MM-DDTHH:MM:SS.SSSZ

Example:

2012-11-24T08:05:42.495Z

This is widely used datetime format. For example it is used in MongoDB and 
Github API (http://developer.github.com/v3/)

I faced this problem on: 1.11.0-beta

Original issue reported on code.google.com by alexey.v...@gmail.com on 26 Nov 2012 at 3:44

GoogleCodeExporter commented 9 years ago
Please try DateTime and let me know if it doesn't meet your needs:

http://javadoc.google-http-java-client.googlecode.com/hg/1.12.0-beta/com/google/
api/client/util/DateTime.html

Original comment by yan...@google.com on 26 Nov 2012 at 3:37

GoogleCodeExporter commented 9 years ago
I have tested that. Still doesn't work. Im using GsonFactory.

Here is code to reproduce:

        try {
            DateTime date = jsonFactory.fromString("2012-11-24T08:05:42.495Z", DateTime.class);
            Log.d(TAG, "timestamp:" + date.getValue());
        } catch (Exception e) {
            Log.w(TAG, e);
        }

Get IllegalArgumentException:

ava.lang.IllegalArgumentException:
        at com.google.api.client.json.JsonParser.parseValue(JsonParser.java:644)
        at com.google.api.client.json.JsonParser.parse(JsonParser.java:289)
        at com.google.api.client.json.JsonParser.parse(JsonParser.java:266)
        at com.google.api.client.json.JsonFactory.fromString(JsonFactory.java:207)

Original comment by alexey.v...@gmail.com on 28 Nov 2012 at 8:50

GoogleCodeExporter commented 9 years ago
that's because you're missing the quotes, ie this should work correctly:

            DateTime date = jsonFactory.fromString("\"2012-11-24T08:05:42.495Z\"", DateTime.class);

That said, we can probably improve the error message.

Original comment by yan...@google.com on 28 Nov 2012 at 3:30