Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Doing a GWT.create on the TimeZoneConstants class is bad game according to the GWT Javadoc [1]. So what I did was create a class on the server-side that parses /com/google/gwt/i18n/client/constants/TimeZoneConstants.properties and builds a cache of all the JSON objects for each time zone (indexed by their Olson TZID).</p> <p>My site is running on jboss, so I copied TimeZoneConstants.properties into my site's war/WEB-INF/lib directory (probably didn't need to copy it there since the GWT jars are already there). Then I have a singleton class that does the parsing when constructed:</p> <pre><code>InputStream inStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(PROPERTIES_FILE); InputStreamReader isr = new InputStreamReader(inStream); BufferedReader br = new BufferedReader(isr); for (String s; (s = br.readLine()) != null;) { // using a regex to grab the id to use as a key to the hashmap // a full json parser here would be overkill Pattern pattern = Pattern.compile("^[A-Za-z]+ = (.*\"id\": \"([A-Za-z_/]+)\".*)$"); Matcher matcher = pattern.matcher(s); if (matcher.matches()) { String id = matcher.group(2); String json = matcher.group(1); if (!jsonMap.containsKey(id)) { jsonMap.put(id, json); } } } br.close(); isr.close(); inStream.close(); </code></pre> <p>Finally I make an RPC call to get the TimeZoneInfoJSON to the client (assuming the server knows which TimeZoneID I'm interested in):</p> <pre><code>getTimeZone(new PortalAsyncCallback&lt;String&gt;() { public void onSuccess(String tzJson) { timeZone = TimeZone.createTimeZone(TimeZoneInfo.buildTimeZoneData(tzJson)); } }); </code></pre> <p>Not the most elegant solution but it has given me a way to display dates and times for a specific time zone over DST transitions.</p> <p>[1] <a href="http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/i18n/client/constants/TimeZoneConstants.html" rel="nofollow">http://google-web-toolkit.googlecode.com/svn/javadoc/2.0/com/google/gwt/i18n/client/constants/TimeZoneConstants.html</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload