thanks everyone for the answers. i agree that Ashley's method is far more readable than using modulus calculations, so i'll look into that further as i can't seem to get it working yet.
currently, i have this working using modulus calculations, but it starts at 00 for the hours and minutes... -=-=-=-=- -(int)timeMenuSelection { return [[menu selectedItem] tag]; } - (IBAction)startTimer:(id)sender { startTime = [NSDate timeIntervalSinceReferenceDate]; [killTimer invalidate]; [killTimer release]; killTimer = nil; killTimer = [[NSTimer scheduledTimerWithTimeInterval:30 target:self selector:@selector(updateTime:) userInfo:nil repeats:YES] retain]; } - (void)updateTime:(NSTimer *)theTimer { NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate]; NSTimeInterval interval = now - startTime; int second = (int)interval; //Tag #1 x 3600 Seconds = 3600 Seconds = 2 Hours. //Tag #2 x 3600 Seconds = 7200 Seconds = 2 Hours. //Tag #3 x 3600 Seconds = 10800 Seconds = 3 Hours. int hoursSelected = ([self timeMenuSelection] * 3600); if (second <= hoursSelected) { NSLog(@"%.2d %.2d %.2d ", (hoursSelected-second)/3600, (hoursSelected*60-second/60)%60, (hoursSelected*3600-second)%60); } else { NSLog(@"TIME'S UP!"); [killTimer invalidate]; [killTimer release]; killTimer = nil; } } -=-=-=-=-=- here's a sample output when the first minute of counting down is about to change: 2008-12-11 07:28:02.028 timerTest[27467:10b] 00 00 04 2008-12-11 07:28:03.028 timerTest[27467:10b] 00 00 03 2008-12-11 07:28:04.028 timerTest[27467:10b] 00 00 02 2008-12-11 07:28:05.028 timerTest[27467:10b] 00 00 01 2008-12-11 07:28:06.028 timerTest[27467:10b] 00 59 00 2008-12-11 07:28:07.028 timerTest[27467:10b] 00 59 59 2008-12-11 07:28:08.028 timerTest[27467:10b] 00 59 58 2008-12-11 07:28:09.028 timerTest[27467:10b] 00 59 57 2008-12-11 07:28:10.028 timerTest[27467:10b] 00 59 56 2008-12-11 07:28:11.029 timerTest[27467:10b] 00 59 55 2008-12-11 07:28:12.028 timerTest[27467:10b] 00 59 54 ideally, it would be nice to have that start at 00 59 00 instead of 00 00 00, otherwise it's adding an additional minute (i think) and won't look appropriate at the beginning... a user selecting 1 hour will first read "Time Remaining: 00 Hours 00 Minutes 00 Seconds" On Thu, Dec 11, 2008 at 12:36 AM, Ashley Clark <[EMAIL PROTECTED]> wrote: > On Dec 10, 2008, at 8:06 PM, Nick Zitzmann wrote: > >> On Dec 10, 2008, at 6:41 PM, Chunk 1978 wrote: >> >>> i read in the docs that the use of NSCalandarDate is discouraged >>> because it's going to be depreciated for OS X 10.6... i'm not really >>> sure if depreciated means that any code with NSCalandarDate will no >>> longer function with the new OS or if it will just be considered out >>> dated... >> >> >> The OP said NSDateComponents, not NSCalendarDate. NSDateComponents will >> not be deprecated any time soon. And despite what the docs say, I don't >> think NSCalendarDate is going away soon, because only NSCalendarDate >> supports encapsulating a time zone within a date. >> >> In any case, if you can avoid using NSCalendar/NSDateComponents to make a >> calendrical calculation, I'd recommend you do so. NSCalendar is quite slow >> to make even the most basic of calculations, especially on PPC Macs. > > > Certainly in a tight loop it might not be appropriate to use NSCalendar but > the OP was using them for display in a timer that only fired once a second. > I'd argue that the NSCalendar/NSDateComponns method calls are more readable > than modulo arithmetic for most people. > > I'd be interested in knowing what kind of performance you saw on PPC Macs > though that would cause you to write them off in all situations. I've not > come across that in my testing. > > > Ashley > > _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]