[
https://issues.apache.org/jira/browse/GROOVY-6854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14572793#comment-14572793
]
Eric Rodriguez commented on GROOVY-6854:
----------------------------------------
Given the bugfix [GROOVY-7143] the workaround is not possible anymore and there
is no way to override the SimpleDateFormat to comply with ISO 8601
https://github.com/groovy/groovy-core/commit/0dddc1799c893011ddfe08ac87260f796cc7bc24
Can you please consider to support Java 7.0 format or at least add a way to
define the dateformat to "yyyy-MM-dd'T'HH:mm:ss.SSSXXX".
{code}
SimpleDateFormat formatter = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX")
formatter.setTimeZone(TimeZone.getTimeZone('UTC'))
{code}
instead of the US version:
{code}
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ",
Locale.US);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
{code}
> JsonOutput should be configurable with ISO 8601 UTC time zone instead of GMT
> ----------------------------------------------------------------------------
>
> Key: GROOVY-6854
> URL: https://issues.apache.org/jira/browse/GROOVY-6854
> Project: Groovy
> Issue Type: Bug
> Components: JSON
> Affects Versions: 2.3.2
> Reporter: george coller
> Priority: Minor
> Labels: json
>
> I believe ISO 8601 prefers the use of UTC over GMT as described in
> [http://en.wikipedia.org/wiki/ISO_8601#Dates]:
> {quote}
> Time zones in ISO 8601 are represented as local time (with the location
> unspecified), as UTC, or as an offset from UTC.
> {quote}
> GMT while similar, isn't exactly UTC. For example in GMT will format a date
> as:
> {code}
> 2014-03-12T19:02:35+0000
> {code}
> instead of the arguably nicer 'Z' for UTC
> {code}
> 2014-03-12T19:02:35Z
> {code}
> Java 7 introduced the "X" flag to use instead of the "Z" flag (which is RFC
> 822, not ISO 8601) for {{SimpleDateFormat}}, which finally made the class ISO
> 8601 compatible.
> Currently our team uses this workaround for {{JsonOutput}} to get it to
> format ISO dates correctly:
> {code}
> def p = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXX")
> p.setTimeZone(TimeZone.getTimeZone('UTC'))
> JsonOutput.dateFormatter.set(p)
> {code}
> I believe this should be the default for JsonOutput, with some sort of
> workaround available for Groovy users who are on JDK6 or earlier.
> If using JDK8 the new date/time library classes should probably be used
> instead.
> The JsonOutput class should really be reconsidered to be a candidate for
> refactoring to a more extendable structure. The limitations of it being an
> all-static utility class are apparent with its current date handling and also
> because it doesn't clients to extend it to print their own custom classes as
> well. The current method of just dumping all properties is often too
> verbose.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)