Re: Adding 30 minutes to an NSDate
Re: Adding 30 minutes to an NSDate
- Subject: Re: Adding 30 minutes to an NSDate
- From: Andy Lee <email@hidden>
- Date: Wed, 20 Jul 2005 04:23:06 -0400
On Jul 20, 2005, at 3:24 AM, j o a r wrote:
I have an app that announces the time every hour. For that, I'm
setting a Timer's next fire time to an NSCalendarDate after each
announcement. Now the problem is the wrap-over from 23:00 to 0:00,
where I'd also have to add 1 to the day and, if that day is at the
end of the month, I'd also have to add to the month.
Do you really have to care about all that, if all you want is to
chime every hour? Why not simply set a timer to fire in 60 minutes,
regardless of which calendar day that happens to be?
This sounds like the right approach to me. I was going to protest
that NSTimers don't necessarily fire when you tell them to, but
followed the docs to this paragraph about CFRunLoopTimer, which is
toll-free bridged with NSTimer:
<file://localhost/Developer/ADC Reference Library/documentation/
CoreFoundation/Reference/CFRunLoopTimerRef/index.html>
A repeating timer reschedules itself based on the scheduled firing
time, not the actual firing time. For example, if a timer is
scheduled to fire at a particular time and every 5 seconds after
that, the scheduled firing time will always fall on the original 5
second time intervals, even if the actual firing time gets delayed.
If the firing time is delayed so far that it passes one or more of
the scheduled firing times, the timer is fired only once for that
time period; the timer is then rescheduled, after firing, for the
next scheduled firing time in the future.
--Andy
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden