• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Date Math Question and Daylight Savings Time
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Date Math Question and Daylight Savings Time


  • Subject: Re: Date Math Question and Daylight Savings Time
  • From: Stephen Todd <email@hidden>
  • Date: Thu, 20 Jan 2005 13:39:19 -0700

I recently dealt with this problem myself, and I found a lot of trouble in using NSTimestamp. The temptation is to call timestampByAddingGregorianUnits() to modify timestamps. The docs say that "This method preserves "clock time" across changes in Daylight Savings Time zones and leap years." While the fact that it accounts for leap years might be true, it does _not_ take care of Daylight Saving. We do separate queries from midnight to midnight time periods across a a week. You would think that you could just timestampByAddingGregorianUnits() it by adding a day, but in reality, only 24 hours are added (Oct 31, 2004, for example, has 25 hours). Well, what you should read between the lines in the docs is that NSTimestamps are in GMT and doesn't participate in DLS.

The solution that I found that worked is to convert it the timestamp to a GregorianCalendar, make your changes, and then create a new time stamp using the info from the GregorianCalendar. It's a pain, but it seems to work for me. So, what I concluded was that don't do any calculations or manipulations on NSTimestamps, just use a GregorianCalendar.

I don't use GregorianCalendars extensively so YMMV, but this seemed to work for us.

Stephen

On Jan 20, 2005, at 11:20 AM, James Cicenia wrote:

Hello All -

I am doing some date math calculations and during daylight savings time my calculations seems to be off a day.

Any thoughts on why?

- James Cicenia

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden


This email sent to email@hidden


_______________________________________________ Do not post admin requests to the list. They will be ignored. Webobjects-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Date Math Question and Daylight Savings Time (From: James Cicenia <email@hidden>)

  • Prev by Date: Re: Date Math Question and Daylight Savings Time
  • Next by Date: Re: Date Math Question and Daylight Savings Time
  • Previous by thread: Re: Date Math Question and Daylight Savings Time
  • Next by thread: RE: Date Math Question and Daylight Savings Time
  • Index(es):
    • Date
    • Thread