Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > NSCalendarDate Query

NSCalendarDate Query
Thread Tools
jessejlt
Mac Enthusiast
Join Date: Feb 2003
Location: Portland, Oregon
Status: Offline
Reply With Quote
Mar 25, 2004, 03:56 AM
 
I am making a project timer so that I can keep track of how much time I spend on... well projects.
I want to do something to the effect:

NSCalendarDate *start;
NSCalendarDate *end;
NSCalendarDate *total;

// Start Timer
start = [ NSCalendarDate calendarDate ];

// Sometime Later
end = [ NSCalendarDate calendarDate ];

total = ( NSCalendarDate * ) ( end - start );

But of course this doesn't work. I'm not sure if it doesn't work because I'm not casting correctly, or if it's not possible to subtract two NSCalendarDate 's... Or both. Is there a better way to do this? If not, is it possible to overload operators in Objective-C?
Somebody please kick me into the right direction.

Also, I have an NSTableView that I would like to row-sort, but I'm having a hard time finding any good examples. Does anyone have any good places to start?

Danka;
jesse ;-)
     
Ibson
Mac Enthusiast
Join Date: Nov 2001
Status: Offline
Reply With Quote
Mar 25, 2004, 06:10 AM
 
Have a look at -[NSCalendarDate years:months:days:hours:minutes:seconds:sinceDate:]

Code:
NSCalendarDate *startDate = [NSCalendarDate calendarDate]; NSCalendarDate *endDate = [NSCalendarDate calendarDate]; int years, months, days, hours, minutes, seconds; [endDate years:&years months:&months days:&days hours:&hours minutes:&minutes seconds:&seconds sinceDate:endDate];
Operators cannot be overloaded in Obj-C. Always look at Apple's documentation.

If you just want the number of seconds between two dates, you might just want +[NSDate date] and -[NSDate timeIntervalSinceDate:].

For table view sorting, check out http://cocoadev.com/index.pl?SortingTableViewByColumn (although it's a tad dated now that we have Panther). You can now sort table views using NSSortDescriptor (if Panther-only is okay).
     
   
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:43 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,