You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/06/26 04:50:05 UTC
[jira] [Commented] (GROOVY-7127) Dates.isJsonDate only recognizes
Javascript Date's toJSON() Format
[ https://issues.apache.org/jira/browse/GROOVY-7127?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14602314#comment-14602314 ]
ASF GitHub Bot commented on GROOVY-7127:
----------------------------------------
GitHub user bobpaulin opened a pull request:
https://github.com/apache/incubator-groovy/pull/45
Groovy 7127
Patch for https://issues.apache.org/jira/browse/GROOVY-7127 With love from CJUG with help from Cosmin Stroe and Steven Hicks.
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/cjug/incubator-groovy GROOVY-7127
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/incubator-groovy/pull/45.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #45
----
commit 2381ccea27233994f4a336d489c1aceea65e5210
Author: bpaulin <bp...@bob_paulin>
Date: 2015-06-26T01:01:35Z
GROOVY-7127 - Added Date Tests
commit b5ed3bf7610c9663a09252f8f821b672a0a8761f
Author: bpaulin <bp...@bob_paulin>
Date: 2015-06-26T02:36:09Z
GROOVY-7127 Allow isJsonDate to accept a date in format
yyyy-MM-ddThh:mm:ss+0000 since this is how the JsonOutput.toJson method
formats a date in Groovy. JSON does not have a standard string output
per the ECMA spec so both may be accepted.
commit 7e9270b965a2735d87bcc7246cd087d86a27e90e
Author: bpaulin <bp...@bob_paulin>
Date: 2015-06-26T02:44:46Z
GROOVY-7127 - Fixed tabs to spaces.
----
> Dates.isJsonDate only recognizes Javascript Date's toJSON() Format
> ------------------------------------------------------------------
>
> Key: GROOVY-7127
> URL: https://issues.apache.org/jira/browse/GROOVY-7127
> Project: Groovy
> Issue Type: Bug
> Components: JSON
> Affects Versions: 2.3.3, 2.3.7
> Reporter: Sergey Mashkov
> Labels: contrib
>
> groovy.json.internal.Dates#isJsonDate is always returns false for valid JSON date. This causes INDEX_OVERLAY parser to not parse dates even if checkDates was set to true
> See the implementation code:
> {code}
> public static boolean isJsonDate(char[] charArray, int start, int to) {
> boolean valid = true;
> final int length = to - start;
> if (length != JSON_TIME_LENGTH) {
> return false;
> }
> valid &= (charArray[start + 19] == '.');
> if (!valid) {
> return false;
> }
> {code}
> However valid JSON date looks like:
> {noformat}
> 2014-10-21T15:15:56+0000
> {noformat}
> so there is no dots in this string so this method will always return false. This consequently leads to groovy.json.internal.CharSequenceValue#doToValue returns string instead of date so parser will never actually parse dates properly
> Test example:
> {code}
> import groovy.json.*
> def o = new JsonSlurper().
> setType(JsonParserType.INDEX_OVERLAY).
> setCheckDates(true).
> parseText(JsonOutput.toJson([a : new Date()]))
> assertEquals(Date.class, o.a)
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)