[ https://issues.apache.org/jira/browse/GROOVY-6854?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14936292#comment-14936292 ]
Balachandran Sivakumar commented on GROOVY-6854: ------------------------------------------------ That's roughly what this PR is doing - creating a private static TimeZone field that can be set with the setTimeZone call. It also is adding a private static final SimpleDateFormat field, but that's private because this bug was specifically about time zones. I was thinking about creating a separate ticket for the Date Format, but if every one is OK, I'll make that configurable as well. Making the date field customisable would mean that we will be modifying the testDate and tetCalendar test cases to accommodate for this change. > 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: Improvement > Components: JSON > Affects Versions: 2.3.2 > Reporter: george coller > Labels: contrib > > 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)