tapestry-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Paul Stanton (JIRA)" <j...@apache.org>
Subject [jira] [Created] (TAP5-1575) DateField is not multi-timezone safe
Date Tue, 12 Jul 2011 07:08:00 GMT
DateField is not multi-timezone safe

                 Key: TAP5-1575
                 URL: https://issues.apache.org/jira/browse/TAP5-1575
             Project: Tapestry 5
          Issue Type: Bug
          Components: tapestry-core
    Affects Versions:
            Reporter: Paul Stanton
            Priority: Critical

If the client is in a different timezone to the server, selecting a date will set the wrong
value in the input field in most cases.

The cause is the use of 'milliseconds since epoch'.

The following demonstrates part of the problem:

		TimeZone serverTz = TimeZone.getTimeZone("GMT+1000");
		TimeZone clientTz = TimeZone.getTimeZone("GMT-1500");

		// simulates client to server communication method used by DateField
		SimpleDateFormat serverDf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

		SimpleDateFormat clientDf = (SimpleDateFormat) serverDf.clone();

		String dateSelection = "2011-07-01 00:00:00";
		Date clientDate = clientDf.parse(dateSelection);

		Date serverDate = new Date(clientDate.getTime());
		System.out.println("2011-07-01 00:00:00 = " + serverDf.format(serverDate) + "?");

So if a user selected July 7 2011, the field would display July 2 2011 if the timezones were
as above.

My solution was to remove the usage of both the java and javascript `Date.getTime` and `new
Date(time)` functions. Instead, I serialise to "yyyy-MM-dd" and format/parse this on the server
using the same tz as the format parameter.

This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


View raw message