Re: NSNumberFormatter & NSTimestamp -- Not Happening
Re: NSNumberFormatter & NSTimestamp -- Not Happening
- Subject: Re: NSNumberFormatter & NSTimestamp -- Not Happening
- From: Jonathan Rochkind <email@hidden>
- Date: Wed, 17 Sep 2003 11:35:43 -0500
You know, I think all this stuff is buggy. Both the Java classes for
handling times and dates, and the WO classes.
But I've been doing all my date calculation with the Java classes,
GregorianCalendar and stuff. And it _seems_ to be working for me. For
instance, I set a 00:00:00 reference time (and assuming that's what's meant
by 'midnight', it does seem to work for me) like this:
public static NSTimestamp setToZeroTime(NSTimestamp input) {
java.util.GregorianCalendar cal = new java.util.GregorianCalendar();
cal.setTime(input);
cal.set( java.util.GregorianCalendar.HOUR_OF_DAY, 0);
cal.set( java.util.GregorianCalendar.MINUTE, 0);
cal.set( java.util.GregorianCalendar.SECOND, 0);
cal.set( java.util.GregorianCalendar.MILLISECOND, 0);
return new NSTimestamp( cal.getTime() );
}
If I'm creating a new date/time at a particular point, I create it with
GregorianCalendar, and then convert to NSTimestamp. It _seems_ to be
working for me. The GregorianCalendar does have a timezone attached, and
you set a particular time in that timezone. Then you convert to an
NSTimestamp, and it properly converts to the 'seconds since UTC epoch'
format of NSTimestamp, and seems to work. Just for another perspective
on another possibility. You could test it with all the various edge and
critical conditions that it might seem likely to fail with; I'd be
interested to hear any results of anyone who does.
--Jonathan
At 09:02 AM 9/17/2003 -0700, Chuck Hill wrote:
When doing things like this I prefer noon, rather than midnight, as a
reference time:
NSTimeZone timeZone = NSTimeZone.systemTimeZone();
outDate = new NSTimestamp(dateYear, dateMonth, dateDay, 12, 0, 0, timeZone);
Then it does not matter it if gets moved to 11AM or 1PM, the day is still
the same.
Does that make it better for your case?
Chuck
At 07:19 PM 17/09/2003 +1200, Denis Stanton wrote:
>Hi Albert
>
>Thank you for taking the time to look into this.
>
>On Wednesday, September 17, 2003, at 04:52 PM, Albert Jagnow wrote:
>
>> I am pretty sure that NSTimestamp is stored in UTC which is not
>> affected by daylight savings time. If you compare two timestamps
>> where one was stored on October 25 2003 at 2:00AM local time and the
>> other was stored on October 26 2003 at 1:00AM local time after the
>> time change, these dates are 24 hours apart even though one is at 2:00
>> local time and the other is at 1:00 local time. If you look at the
>> UTC time for each in a database (assuming local time is central time)
>> you should see something like 2003-10-25 07:00:00 for the first time
>> and 2003-10-26 07:00:00 for the second. The difference calculation
>> below should give you a diff of 24 hours or 1 day. This is the
>> correct difference is it not?
>
>That's not the way it works out in practice. I am prepared to believe
>that that I am causing this through my own ignorance, but my experience
>so far suggests that not all days are equal.
>
>I am developing an application for booking rental cars. The user sets
>outDate and returnDate by selecting day number, month name and year
>number from three pop-up menus. These are used to form dates with
>approximately the following code:
>
> NSTimeZone timeZone = NSTimeZone.systemTimeZone();
> outDate = new NSTimestamp(dateYear, dateMonth, dateDay, 0, 0,
>0, timeZone);
>
>If I set an outDate of 1 October and a return date of 7th October, and
>then use System.out.println to display the results without formatting I
>will see:
>
>2003-01-01 12:00:00 Etc/GMT
>2003-01-07 11:00:00 Etc/GMT
>
>The user intends renting for a whole week, but performing the
>calculation discussed would return a duration of 6.9583 days,
>truncated to 6 days.
>
>The workaround is to always add 1 hour before performing the division.
>Some weeks will then be 7 days and others 7.0416. All will truncate to
>7.
>
>Maybe the better answer is to set a timezone of UTC in the first place,
>but I haven't figured out how to do this so I'm using system time.
>
>Denis
>_______________________________________________
>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.
>
--
Chuck Hill email@hidden
Global Village Consulting Inc. http://www.global-village.net
_______________________________________________
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.
_______________________________________________
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.