Bug ID 6342679: NSTimestamp Happy New Year Bug

Barði Einarsson <[email protected]> Mon, 22 Dec 2008 08:48:13 -0000
Newsgroups gmane.comp.web.webobjects.devel
Message-ID <3641A4427AF6E74385A255179741DC7F1A6BAD@mail>
Bug ID 6342679: NSTimestamp Happy New Year Bug

Comments please.

Two things not reported by me:
1. The computers running the software are on GMT.
2. The behavior changes depending on the year.

Best regards,
Bardi


-----Original Message-----
From: [email protected] [mailto:[email protected]]
Sent: Thu 18-Dec-08 17:29
To: Barði Einarsson
Subject: Bug ID 6342679: NSTimestamp Happy New Year Bug
 
Hi Bardi,

This is a follow-up to Bug ID# 6342679.

Engineering has determined that this issue behaves as intended based  
on the following information:

This is actually a "feature" of GregorianCalendar.

The default GregorianCalendar is build withe local time zone of the  
machine. In order for this example to work you must force the  
GregorianCalendar to be GMT. This works:

     public static int yearFromDate(NSTimestamp date) {
     	if (null == date) {
     		return NOT_APPLICABLE;
     	}
     	GregorianCalendar cal = new GregorianCalendar();
     	cal.setTimeZone(TimeZone.getTimeZone("UTC"));
     	cal.setTime(date);
     	System.out.println("date in yearFromDate : " + date);
     	int result = cal.get(GregorianCalendar.YEAR);
     	System.out.println("yearFromDate : " + result);
     	return result;
     }

date in yearFromDate : 1964-01-01 00:00:00 Etc/GMT
yearFromDate : 1964

Note setting the TimeZone after creating the GregorianCalendar.

We consider this issue closed.  If you have any questions or concern  
regarding this issue, please update your report directly (http://bugreport.apple.com 
).

Thank you for taking the time to notify us of this issue.

Best Regards,

Kit Cheung
Apple Developer Connection
Worldwide Developer Relations
**************************************************************************
THE INFORMATION CONTAINED IN THIS MESSAGE IS UNDER NON-DISCLOSURE
**************************************************************************

-------------------------------------------------------
Bug ID #: 6342679
Bug Title: NSTimestamp Happy New Year Bug
-------------------------------------------------------
<GMT04-Nov-2008 16:56:50GMT> Bardi Einarsson:
     public static int yearFromDate(NSTimestamp date) {
     	if (null == date) {
     		return NOT_APPLICABLE;
     	}
     	GregorianCalendar cal = new GregorianCalendar();
     	cal.setTime(date);
     	System.out.println("date in yearFromDate : " + date);
     	int result = cal.get(GregorianCalendar.YEAR);
     	System.out.println("yearFromDate : " + result);
     	return result;
     }

date in yearFromDate : 1964-01-01 00:00:00 Etc/GMT
yearFromDate : 1963