• 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: NSCalendar date calculation anomaly
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSCalendar date calculation anomaly


  • Subject: Re: NSCalendar date calculation anomaly
  • From: Roland King <email@hidden>
  • Date: Wed, 28 Apr 2010 22:52:53 +0800

On 28-Apr-2010, at 10:37 PM, Scott Ribe wrote:

> On Apr 28, 2010, at 1:04 AM, Kubernan wrote:
>
>> Did you try to use NSDateComponents for building your reference date (2001/01/01) such as :
>
> No, reasonable idea though. But even better, I should have been logging the reference date after I created it. When I do that, I get:
>
> 2000-12-31 17:00:00 -0700
>
> Which is correct, midnight at UTC. Then I add 3,412 days and I get:
>
> 2010-05-05 17:00:00 -0600
>
> Which is off by an hour. So the problem seems to be with the addition, not with the creation of the reference date.

Are you sure this isn't the semantics of 'add a day'? There's two ways I can think that 'add n days' would work, one of them adds 24 * 60 * 60 seconds for each day you want to add, that's a simple way to do it.

The other says ok the date I start at is 5pm in the timezone I'm set to (and NSCalendars have timezones) so let me give you 5pm (the same *time* ) in that TZ, on a date n days later. That it seems to me is what has actually happened here, you started at 5pm, you ended at 5pm 3412 days later. It just happens that one of those 5 PMs was in daylight savings time and the other wasn't, so you actually got 1 hour more/less than you wanted.

Another way to put it, if it's 5pm here now and you say to your friend, I'll meet you here same time in a week, you'd expect to be there at 5pm a week later. If the clocks have changed between those two dates it doesn't matter, you'd show up at 5pm wall clock time. _______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >NSCalendar date calculation anomaly (From: Scott Ribe <email@hidden>)
 >Re: NSCalendar date calculation anomaly (From: Kubernan <email@hidden>)
 >Re: NSCalendar date calculation anomaly (From: Scott Ribe <email@hidden>)

  • Prev by Date: Re: NSCalendar date calculation anomaly
  • Next by Date: Re: NSCalendar date calculation anomaly
  • Previous by thread: Re: NSCalendar date calculation anomaly
  • Next by thread: Re: NSCalendar date calculation anomaly
  • Index(es):
    • Date
    • Thread