Hello,

Using WO 5.4.3. Here's yet another NSTimestamp/NSTimestampFormatter/ SimpleDateFormat thread... :-)

Heeding the deprecation warning for NSTimestampFormatter, I've been trying to use SimpleDateFormat in its place. I'm doing the following:

1.  PostgreSQL is set to GMT.
2.  Application() contains this:

                // Set the default TZ for NSTimestamps to GMT
                NSTimeZone.setDefaultTimeZone(NSTimeZone.getGMT());
                // Set the default TZ for Java
                TimeZone.setDefault(TimeZone.getTimeZone("GMT"));

3.  Column C in table T is of type "TIMESTAMP WITHOUT TIME ZONE".
4. I'm inserting a creation timestamp into C using 'new NSTimestamp'. I can confirm that the current time in GMT is inserted into T. 5. A user preference system allows users to nominate a local timezone if they prefer not to see the dates as GMT.
6.  In the Session I store a SimpleDateFormat constructed like this:

SimpleDateFormat sdf = new SimpleDateFormat("...some format string...");
        sdf.setTimeZone(userLocalTZ);

Where userLocalTZ is an NSTimeZone constructed from the save preference.
7. When I try to use the SimpleDateFormatter, it doesn't adjust the construction timestamp when binding it to a wo:string formatter. Here's some debugging output:

SurveyInstanceList.timestampFormat: ((NSTimeZone) result.getTimeZone()).secondsFromGMT()) = 34200

This is the TimeZone from the SimpleDateFormat: it's the correct offset from GMT.

SurveyInstanceList.timestampFormat: constructionDate().timeZone() = Etc/GMT (GMT) offset 0

This is the TimeZone from the timestamp.  It's in GMT.

SurveyInstanceList.timestampFormat: result.format(constructionDate())) = 15/04/2009 08:34:41

This is the result of the format: the timestamp is not adjusted, and appears exactly as it appears in the database.

8. If I pull the same TimeZone out of the SimpleDateFormat and use it to create an NSTimestampFormatter, it works:

nsf.setDefaultFormatTimeZone((NSTimeZone)result.getTimeZone());

Using nsf.format adjusts the time to the user's nominated local timezone as expected.

What am I doing wrong with SimpleDateFormat?


--
Paul.

w  http://logicsquad.net/
h  http://paul.hoadley.name/


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list      ([email protected])
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to