Re: Time zones are driving me CRAZY
Re: Time zones are driving me CRAZY
- Subject: Re: Time zones are driving me CRAZY
- From: Mankit Sze <email@hidden>
- Date: Thu, 20 Nov 2003 11:44:16 -0800
On Nov 20, 2003, at 1:35 AM, Pierre Bernard wrote:
> Product: WebObjects 5.2.2
> Subject: Inconsistent behavior of NSTimestamp & NSTimezone
>
>
> Hi!
>
> Since upgarding our Windows 2000 development machines to WebObejects
> 5.2.2 running on Sun's J2SE SDK 1.4.1_05, we are observing a series of
> problems with both NSTimestamp and NSTimeZone. This causes us major
> trouble and has basically stalled development on our current project.
> As it stands we can no longer trust parsing, display nor computation
> involving NSTimestamp.
> Below I have detailed a few examples which seem to reveal problems
> with NSTimestampFormatter and NSTimeZone. I can only hope this is the
> single source of all problems. Yet it may just as well be another
> manifestation of the root problem that causes all oddities observed.
> Or, worse, it could be just one of many more problems with timestamps.
>
> The examples below were exectued in the main method of a vanilla
> WOApplication. They were run on a Windows 2000 PC using Java 1.4.1_05.
> The same examples produced slightly different errors in short test on
> a Mac OS 10.3 machine with the lates Java update.
>
> Example 1: Parsing the date "190101" in the "Europe/Luxembourg" time
> zone
>
> NSTimeZone.setDefault(NSTimeZone.getTimeZone("Europe/Luxembourg"));
> TimeZone.setDefault(TimeZone.getTimeZone("Europe/Luxembourg"));
>
> String dateString = "190101";
> NSTimestampFormatter nsFormatter = new
> NSTimestampFormatter("yyyyMM");
> SimpleDateFormat sdFormat = new SimpleDateFormat("yyyyMM",
> Locale.US);
>
> NSTimestamp date1 = (NSTimestamp)
> nsFormatter.parseObject(dateString);
> Date date2 = sdFormat.parse(dateString);
>
> System.out.println(date1.getTime());
> System.out.println(date2.getTime());
>
> System.out.println(date1.getTime() == date2.getTime());
> The above code is parsing the very same date string once using
> NSTimestampFormatter and once using SimpleDateFormat. This produces
> two date objects. One java.util.Date and on NSTimestamp, a subclass of
> Date. Both dates should represent the same point in time. To check
> this their internal represenation - milliseconds since a reference
> date - are compared.
>
> -2177456400000
> -2177454276000
> false
>
> One would expect the results to be the same, yet they are not. There
> is an offset of 2124 seconds.
Running your test case on Java Virtual Machine Ver. 1.3.1 + WebObjects
5.2., I got the following result:
Java Virtual Machine Ver. 1.3.1
-2177456400000<-- from NSTimestampFormatter
-2177456400000<-- from SimpleDateFormat
true
Running your test case on Java Virtual Machine ver. 1.4.1 + WebObjects
5.2.2, I got these outputs:
Java Virtual Machine Ver. 1.4.1_01
-2177456400000<-- from NSTimestampFormatter
-2177454276000<-- from SimpleDateFormat
false
Attached below is a slighly modified version of your test case you
could use to verify the result I produced above.
[demime 0.98b removed an attachment of type application/x-tar which had a name of TestNSTimestampFormatter.tar]
The inconsistency in behavior of SimpleDateFormat between JVM 1.3.1 and
1.4.1 causes you the grief. NSTimestampFormatter works consistently.
Mankit
_______________________________________________
webobjects-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/webobjects-dev
Do not post admin requests to the list. They will be ignored.