Re: NSTimestamp Behaviour
Ray Kiddy <[email protected]>
| Newsgroups | gmane.comp.web.webobjects.devel |
|---|---|
| Message-ID | <[email protected]> |
On Oct 12, 2006, at 8:33 AM, Jeff Dunnett wrote:
> Hello,
>
> Does anyone know the behaviour of NSTimestamp when a 0 is put in the
> date field.
>
> For example...
>
> The constructor I am using is:
>
> NSTimestamp(int year, int month, int date, int hour, int minute, int
> second, TimeZone tz)
>
> I am passing in:
>
> NSTimestamp(Integer.parseInt(aSelectedYear), aSelectedMonth, 0, 0,
> 0, 0, TimeZone.getTimeZone("GMT-4"))
>
> The documentation says that date should be between 1 and 31. Still
> the constructor doesn't throw an exception when I pass a 0 into the
> date field. It seems to be decrementing the value of
> aSelectedMonth. For instance if aSelectedMonth = 6 (June) the value
> of aSelectedMonth becomes 5 (May). If aSelectedMonth = 1 (January)
> it wraps around to become 12 (December). Does anyone know if this
> is supposed to happen when you enter 0 into date?
>
> Regards,
> Jeff
> _______________________________________________
> WebObjects-dev mailing list
> [email protected]
> http://www.omnigroup.com/mailman/listinfo/webobjects-dev
There are certainly some things that can be fixed in NSTimestamp. It
was intended to fix a lack in the JDK at the time and it is arguable
that the JDK has fixed the problems, and people have learned useful
ways around the problems, and NSTimestamp is not doing so much good
and probably some harm.
That being said, what does one do when the JDK is wrong in similar ways?
public class testCalendar {
public static void main(String[] arg) {
java.util.GregorianCalendar cal = new
java.util.GregorianCalendar();
cal.set(2000,1,0);
System.out.println("cal =
year:"+cal.get(java.util.Calendar.YEAR)+", month:"+
cal.get(java.util.Calendar.MONTH)+", date:"+
cal.get(java.util.Calendar.DATE));
}
}
This gives:
cal = year:2000, month:0, date:31
So, I jjust passed in year 2000, month 1, and date 0. If it had given
me December 31, 1999, that might have made some sense.
Does the result we see make sense?
WebObjects has gotten in trouble trying to more clever than the JDK
with some of these issues. What should we do here?
- ray
------------------------------
WebObjects Engineering
Developer Tools
Apple Computer, Inc
_______________________________________________
WebObjects-dev mailing list
[email protected]
http://www.omnigroup.com/mailman/listinfo/webobjects-dev