NSDate, NSTimeInterval, Calculating time passed and Core Data

I'm creating a timesheet/stopwatch application of sorts for the iPhone.
I am using an NSDate in CoreData and following this pattern:
1) Start:
Session* session = (Session*)\[NSEntityDescription insertNewObjectForEntityForName:@"Session" inManagedObjectContext:managedObjectContext_\];
session.startTime = \[NSDate date\];
2) Calculate time passed and update label:
NSTimeInterval timeDiff = -1*\[session.startTime timeIntervalSinceNow\];
cell.textLabel.text = \[NSString stringWithFormat:@"%f", timeDiff\];
I also see that I could use:
NSTimeInterval timeDiff = \[\[NSDate date\] timeIntervalSinceDate:session.startTime\];
cell.textLabel.text = \[NSString stringWithFormat:@"%f", timeDiff\];
I don't like this since it is needlessly creating a lot of dates - and there could be 100s of these timers running at the same time ... or, does timeIntervalSinceNow possibly also create a new date evertime under the covers and I'm pre-optimizing or something too early. Can anyone suggest a better way to do this? For instance, initially, I was simply using NSTimeInterval:
NSTimeInterval startTime = \[NSDate timeIntervalSinceReferenceDate\];
NSTimeInterval endTime = \[NSDate timeIntervalSinceReferenceDate\] - startTime;
But I end up struggling with the best way to manage this as part of a CoreData entity. Should I uses a double? or a Date? I understand that a Date is implemented as an NSTimeInterval but I can't assign or subtract an NSTimeInterval directly to my entity.date
session.startTime = \[NSDate timeIntervalSinceReferenceDate\];
NSTimeInterval timeDiff = \[NSDate timeIntervalSinceReferenceDate\] - session.startTime;
Obviously, this won't compile when startTime is a Date object but I think it illustrates what I'm after. Trying to 'lightly' calculate time passed by using the start time assigned to an Entity. Maybe the original way is just fine. I'm just looking for suggestions. I guess I could try running this inside a profiler. As a side note, is there a better way to print the stopwatch output to the screen? It seems like overkill to constantly update a Label's text property ... hundreds, maybe thousands of times especially when there may be 10 or so timers running on the same screen. Does anyone have any advice for stopwatch type 'update the time' label behavior?
I'm doing this in an NSTimer potentially set to fire every .01s ... IE: this method will get hit quite a bit ...
Thanks.
Message was edited by: LutherBaker

LutherBaker wrote:
I don't like this since it is needlessly creating a lot of dates - and there could be 100s of these timers running at the same time ... Can anyone suggest a better way to do this?
That doesn't sound good. Why would you have so many?
I'm just looking for suggestions. I guess I could try running this inside a profiler. As a side note, is there a better way to print the stopwatch output to the screen? It seems like overkill to constantly update a Label's text property ... hundreds, maybe thousands of times especially when there may be 10 or so timers running on the same screen. Does anyone have any advice for stopwatch type 'update the time' label behavior?
I'm doing this in an NSTimer potentially set to fire every .01s ... IE: this method will get hit quite a bit ...
That doesn't seem like a side note. That seems like the main point.
As "good" video is typically around 30 frames per second, it doesn't make any sense to update the user interface any more frequently than that. Also, you really only need one timer. Let that timer update all the values. You may not need any timers. You could do everything via key-value coding and let the OS handle all the work.

Similar Messages

  • Time Streams and Shipping Dates

    Hello,
    Does anyone have any documentations regarding time streams? I am checking on how time streams and determination of shipping dates such as loading date, pricing date, GI date, etc. are related.
    I noticed that when we run ZZTTSTR program from SAP which clears time stream handles, before we create order documents, somehow some order documents determine wrong shipping dates.
    We setup a background job to run ZZTTSTR daily every night and during the day we upload order files which converts to about 500-1000 order IDOCs and posted to be order documents.
    Now, i removed the backround job of ZZTTSTR and the issue never happened again. I'm looking for more info about time streams so I can determine how this caused my issue.
    I hope someone can help.

    You will get it within the window you were originally promised by Apple. If you get it early, bonus.
    There is nothing else anyone here can say about it.
    Speculation and rumor are prohibited by the Apple Support Communities Terms of Use.

  • Time machine and wiki data recovery

    I'm running into an issue where I need to recover wiki data from a Time Machine back-up..
    The backstory:
    The wiki server was running on a 2008 Mac Pro which had an unrecoverable disk failure.  Given the age of the machine, the power it drew, and the fact that I dont need the horsepower of a macPro to host the wiki, I picked up a new Mac Mini to host the server data. It is a very low usage system, so the Mini should have all the power I need..  Not to mention its cost is over $2,000 less..
    I've been able to recover all the files I need from the Time Machine backup disk, except for the Wiki..     The last time I needed to do something like this was 10.6, and everything was in flat files, so it was a simple copy operation..  Now however it looks like there is a postgres database to deal with..  Being that I only have access to the files on the TM backup, Im not sure how to recover the wiki.
    My thought was to simply to a TM restore, but because Im going from a MacPro to a MacMini, it barks that its a different hardware type and will not complete the restore..
    So the end question is, has anyone ever had to recover an Apple wiki, from a Time Machine backup disk, running 10.8, with the destination being a Mac Mini?  If yes, how did you overcome not running the postgres database?
    Thanks..

    Restore these items, then reboot:
    /Library/Server/PostgreSQL For Server Services
    /Library/Server/Wiki

  • Comparing a time period and a date via trigger....

    Hi ,
    There are among others three tables....
    Table material
       material_code number
       onomasia   varchar2(50)
       guarantee_end_date date
    Table supplier_contract
         contract_code number
         start_date date
         end_date date
        supplier number(5)
    Table supplier_contract_material
          contract_code number
          material_code numberThe table material , for each material contains the guarantee_end_date , whereas the other two contain info about the materials that should be replaced/fixed/ e.t.c by the supplier in the specific time period (start_date - end_date).
    The thing that has to be done is there have not be any overlap of the dates.... In other words , when a material is bought then this is covered for replacement by the end of the date (guarantee_end_date in the first table). After this date there should be contract with the supplier for this material for a specific period (start_date - end_date , in the second table).
    I want to secure the database that when the end_user tries to update this time_period(start_date - end_date) before or between the guarantee_end_date ("when i say between the guarantee_end_date " , i mean the condition guarantee_end_date between start_date and end_date is not acceptable) then an alert would be raised ....
    So , I wrote the following trigger:
    create or replace trigger trg_check_eggisi
    before update on supplier_contract
    for each row
    declare
    guarantee_end_date_var date;
    begin
       begin
         select guarantee_end_date 
           into guarantee_end_date_var
           from material a, supplier_contract_material b
          where a.material_code=b.material_code
           and b.contract_code=:new.contract_code;
         exception
          when no_data_found
           then return;
        end;
       if guarantee_end_date_var>:new.guarantee_end_date_var
         then
         raise_application_error(-20021,'NOT_APPLICABLE');
       end if;   
    end;The problem is that the error ORA-01422 is raised ... because more than 1 material may be contained in the specific contract....
    Do you have any idea...????
    many thanks ,
    Simon

    Hi  John,
    As you want to  display the planned value of Depreciation for future years,
    since this is not possible you can display the planned values only for that year and that too for subsequent periods,  you  will  see  the Yellow icon stating it is planned which is not yet posted in the posted value Tab,
    Since if  you  want to display planned values for future year you have to  post Depreciation for subsequent period and close the fiscal year and again same procedure follows....
    Regards,
    Imran M Arab

  • Report on Real Time Cube and Master data

    Dear Experts,
    I am new to BI. I have created real time cube using some characteristics and top of that I built 3 reports with referring to Master data.
    And in the 3 reports, I have used different characteristics for all the report expect one ( common in all the reports).
    Now I have to create consolidated report using all the characteristics. I have build some sample reports but getting not assigned where there is no data.
    How can I achieve this?
    Thanks in advance,
    Saravanan R

    Hi suman,
    Thanks for your reply .
    I have attached the screen shot of the output. I have created the Infoset using info objects and real time cube, on top of that I have created query.
    this is the problem am facing can please suggest on this .

  • Can i use one hardrive for time machine and other data?

    i want to buy an external drive for my macbook pro retina. i want to knwo if i were to buy an external hardrive big enought ot back up my 768 on my retina could i also put other media on it (like video and movie) without it overwriting or something like that

    screenfreak wrote:
    i want to buy an external drive for my macbook pro retina. i want to knwo if i were to buy an external hardrive big enought ot back up my 768 on my retina could i also put other media on it (like video and movie) without it overwriting or something like that
    Buy one hard drive for TimeMachine, large as possible for maximum amount of saved states, keep it connected more often so it updates more often to recover deleted files.
    Buy one hard drive the same size or slightly larger to clone your boot drive to it, it will be a hold option key bootable clone in case your boot drive fails to boot. Update it before doing anything major to your machine. Keep it disconnected in case of malware so it doesn't get infected or delete your files.
    Buy one hard drive for extra storage if your boot drive is getting full for instance.
    Buy one hard drive to backup the extra storage drive and treat it like the clone, make sure you have clean extra storage drive before connecting and updating it.
    Label and date each drive, your memory will fail you and you'll accidentally overwrite a drive.
    Keep your drives separate and in their respective purposes, in other words do not use partitions or use TimeMachine to backup other drives.
    Never use Filevault, it's cracked, it's worthless, impossible to recover data and you'll have to give up the password for repair or customs/searches anyway. Use a external hardware based encrypted drives and USB Iron Keys. This way your sensitive data is off the machine and can be used with another machine.
    Despite how many drives and backups, it's good to also make burned and labeled DVD's of your most important files like music for instance when you first get them. It's because sectors fail on hard drives and takes out your data and thus on all backups made afterwards. With burned DVD's it's permanent, unless you scratch it, melt it or loose it.
    Hardware also fails, more often than software because it's moved/abused while in operation.
    If you lose your TM drive, you ALSO lose what's on the other partitions on the drive or data that TM drive was backing up from other drives.
    Drives are cheap, data is not. Protect the data. Because it's a fortune trying to recover lost data off a dead drive.

  • Whats run time configuration and php date and time constants?

    http://www.w3schools.com/php/php_ref_date.asp .....are they required to make dynamic websites....??

    Are they required to make dynamic websites?  No.  But if you are going to use any date functions (like for example one I frequently use - stringtotime()), then you would need to use -
    date_default_timezone_set()
    to properly establish the timezone to be used for your calculations.

  • How do you calculate difference in time (hours and minutes) between 2 two date/time fields?

    Have trouble creating formula using FormCalc that will calculate difference in time (hours and minutes) from a Start Date/Time field and End Date/Time field. 
    I am using to automatically calculate total time in hours and minutes only of an equipment outage based on a user entered start date and time and end date and time. 
    For example a user enters start date/time of an equipment outage as 14-Oct-12 08:12 AM and then enters an end date/time of the outage of 15-Oct-12 01:48 PM.  I need a return that automatically calculates total time in hours and minutes of the equipment outage.
    Thanks Chris

    Hi,
    In JavaScript you could do something like;
    var DateTimeRegex = /(\d\d\d\d)-(\d\d)-(\d\d)T(\d\d):(\d\d)/;
    var d1 = DateTimeRegex.exec(DateTimeField1.rawValue);
    if (d1 !== null)
        var fromDate = new Date(d1[1], d1[2]-1, d1[3], d1[4], d1[5]);
    var d2 = DateTimeRegex.exec(DateTimeField2.rawValue);
    if (d2 !== null)
        var toDate = new Date(d2[1], d2[2]-1, d2[3], d2[4], d2[5]);
    const millisecondsPerMinute = 1000 * 60;
    const millisecondsPerHour = millisecondsPerMinute * 60;
    const millisecondsPerDay = millisecondsPerHour * 24;
    var interval = toDate.getTime() - fromDate.getTime();
    var days = Math.floor(interval / millisecondsPerDay );
    interval = interval - (days * millisecondsPerDay );
    var hours = Math.floor(interval / millisecondsPerHour );
    interval = interval - (hours * millisecondsPerHour );
    var minutes = Math.floor(interval / millisecondsPerMinute );
    console.println(days + " days, " + hours + " hours, " + minutes + " minutes");
    This assumes that the values in DateTimeField1 and DateTimeField2 are valid, which means the rawValue will be in a format like 2009-03-15T18:15
    Regards
    Bruce

  • Core data and Populate field programmatic

    Hi
    On a window i have a couple of controls Combo box, Text field and a few buttons
    all linked to core data which is working perfect ish
    if I select the combo box and change the value its updated in core data straight away
    if I press a button it put a value in the text box but doesn't update the code data field until i click in the field and add a space or something simular ..
    is it a focus thing, the field don't lose focus until I have done it manually
    can someone point me in the right direction for this
    just want to click a button , put that value in the textbox and core data is updated without having to click in the text box
    regards
    Tony

    Does this help?

  • Calculation time as related to db size

    Hi,
    I have a database with various scenarios and versions. I have a nightly calculation (not just an aggregation) that runs on one scenario/version. As other scenarios and versions have been created, the database size has grown quite a bit, and the nightly calculation grows each time new scenario/version data sets are created. It has always been my understanding that the fix statement restricts the number of blocks brought into the calculation, and that theoretically, data existing in other intersections not being fixed on should have nothing to do with the calculation time. However, this is not my experience. I even tested it out in a development app by clearing all of the data in 8 of the other scenarios and versions and saw my calculation time cut by 27%. Does anyone know why this should be? It concerns me that as we save off more and more historical copies of the data, the calculation time on the active data will grow and grow.
    We are in the process of implementing a BSO/ASO solution to reduce the data in the BSO cube, but I don't see why it should be necessary and would like any insight into this.
    Thanks,
    Sabrina

    You may be calculating on those blocks, but the overhead of these operations grows as the database grows
    Each time it has to calculate on a block, it needs to go into the index file - find the location of the block in the .pag file, then go to the .pag file and bring that block into memory.
    I am not opposed to segregating historical data which is not used often and moving that to a separate cube from a design perspective, and really it probably would be a good idea if the cycle time on your calcs are currently taking forever.
    You can try and improve performance by modifying the cache settings - but that's performance tuning, and outside the scope of your original question.
    -Matt

  • Calling and manipulating data on an Interactive Adobe form from ABAP report

    Dear All,
    Can you please tell me how to call an interactive adobe from from a custom adobe form?
    If so how can we pass and receive data between the interactive adobe form and the abap report program?
    Thank you.
    Regards,
    Prosenjit.

    Hi,
    It is possible to call an Interactive Adobe form from ABAP report and pass data into the form. If you search the forum, you will get many threads explaining the process. Let me know if you have any specific questions on this.
    Regards,
    Sanoosh

  • Core data psql or cgi bash?

    It's kind of getting down to the nitty gritty about selecting a data system for a project. The cgi stores data and makes requests for the client, as usual. The cgi is generating the content. The data required is pretty simple, and I was thinking of simply using bash commands to store and retrieve data. I also have psql already set up on the system, but I don't know or recognize what advantages that would offer. I could also make a core data application and access it via the cgi, or place the application in the cgi? I'm also not sure what advantages that would offer with relatively simple data sets. I'm not sure what the difference is between core data stores and core data xml stores, if they are more easily accessible, if they use less memory than xml, if there is an accessing overhead? It seems like the fastest way to get in and out of data from a cgi is to simply deploy one's own scripting and file system? Any charitable or wise advice or thoughts on this?

    Maybe the CGI isn't printing out a content-type header?

  • Core Data Issue

    I am creating a coredata sqlite database file in a mac app (using core data) and am attempting to use the same database and core data model in an ipad app.   I have copied all NSManagedObject files and the .xcdatamodeld directory from the mac app to the ios app.  Even though all files are identical I get "
    The model used to open the store is incompatible with the one used to create the store" when trying to read from the store in the app.  My question is what is actually being compared when this error is thrown?  It looks like it throws the error following SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA.   What is a z_uuid?  Any ideas on how to debug this?   my error dump is below.
    2014-05-06 12:57:29.118 Genome[9055:60b] CoreData: sql: SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA
    2014-05-06 12:57:29.119 Genome[9055:60b] CoreData: annotation: Disconnecting from sqlite database.
    2014-05-06 12:57:29.121 Genome[9055:60b] Unresolved error Error Domain=NSCocoaErrorDomain Code=134100 "The operation couldn’t be completed. (Cocoa error 134100.)" UserInfo=0x109527050 {metadata={
        NSPersistenceFrameworkVersion = 481;
        NSStoreModelVersionHashes =     {
            Annotation = <d4eb8bbc 528c6ac9 3cc1decb ca49790e 9933c09b faf47ec9 108fb9b4 b083e144>;
            Band = <14c5dda0 3db4c5c7 27952ce6 5421b597 6d97bed9 b6f225c7 0d956b54 2cfc8282>;
            Gene = <e70a2ed2 fa4c0c3e 1fb8eabc f0f1c26b 9dadb033 0c9198fe 9ba2393e c1a3f9c2>;
            Test = <051b8cd1 849daecf 7a94ac5a 87134d9b 1db8b51c 60bdca34 cb828268 01d6a73a>;
            User = <ebf4a8c8 7209296b 30bdf66c bd7a3dac afa9c8c5 d04f363f 14469686 ba458804>;
            Variant = <58231e33 52687ba7 053846d2 e8d27ed2 58ec690b 2fb09efc 303f299f 2592d6f5>;
        NSStoreModelVersionHashesVersion = 3;
        NSStoreModelVersionIdentifiers =     (
        NSStoreType = SQLite;
        NSStoreUUID = "9B3D312C-95C8-45E3-9F2F-2581E88403A8";
        "_NSAutoVacuumLevel" = 2;
    }, reason=The model used to open the store is incompatible with the one used to create the store}, {
        metadata =     {
            NSPersistenceFrameworkVersion = 481;
            NSStoreModelVersionHashes =         {
                Annotation = <d4eb8bbc 528c6ac9 3cc1decb ca49790e 9933c09b faf47ec9 108fb9b4 b083e144>;
                Band = <14c5dda0 3db4c5c7 27952ce6 5421b597 6d97bed9 b6f225c7 0d956b54 2cfc8282>;
                Gene = <e70a2ed2 fa4c0c3e 1fb8eabc f0f1c26b 9dadb033 0c9198fe 9ba2393e c1a3f9c2>;
                Test = <051b8cd1 849daecf 7a94ac5a 87134d9b 1db8b51c 60bdca34 cb828268 01d6a73a>;
                User = <ebf4a8c8 7209296b 30bdf66c bd7a3dac afa9c8c5 d04f363f 14469686 ba458804>;
                Variant = <58231e33 52687ba7 053846d2 e8d27ed2 58ec690b 2fb09efc 303f299f 2592d6f5>;
            NSStoreModelVersionHashesVersion = 3;
            NSStoreModelVersionIdentifiers =         (
            NSStoreType = SQLite;
            NSStoreUUID = "9B3D312C-95C8-45E3-9F2F-2581E88403A8";
            "_NSAutoVacuumLevel" = 2;
        reason = "The model used to open the store is incompatible with the one used to create the store";

    That is not it.  I acually had it working with Mavaricks and ios7 and then something changed.   I am wondering what exactly is being compared when the The model used to open the store is incompatible with the one used to create the store error is thrown.  It is obviously not the columns of the db and properties of the managed objects because they are identical.

  • Basic and scheduling  dates & time calculation in process order creation

    Hi guru's,
    i have one requirement, i need to calculate and display the basic and scheduled dates & times based on the given input i.e material , plant , process order type , quantity , UOM and scheduling type ( for corresponding scheduling type user will provide either start date or finish date ) using RFC. can  u plz provide any function module for this purpose or logic for calculating the same  , as i am working on version 4.7ee .
    Awaiting for a quick response.
    Regards,
    Madan

    Dear Rohan,
    1.Check the length of break timings defined in the resource that is assigned in the phase.
    2.Check in OPUZ whether for the process order type and plant combination whether scheduling is to include the break time also
    (whether the check box for scheduling with breaks) is included.
    Check and revert back.
    Regards
    Mangalraj.S

  • HT200197 my apple tv won't pass the setting date and time screen?

    why won't my apple tv pass the setting date and time screen?

    That indicates a network issue.
    Check the DNS settings, they should be set to automatic.

Maybe you are looking for

  • Problem with multi-touch screen when lid is closed

    I have a T400s with the MT screen, running a clean installed Win 7 32-bit and all latest Lenovo drivers/BIOS. I use external screen/keyboard/mouse at work so I am used to have the lid closed. I set in power management in the way that closing the lid

  • Full 64-bit Aperture 3 Performance Maxed

    All Macs running Snow Leopard that are Core2Duo or better are capable of full 64-bit, but from reading the threads I would say almost nobody is doing this. Currently, of all Macs on the market now, only the X-Serve boots into full 64 bit mode by defa

  • Dynamic Dropdown Field is blank

    I am using LiveCycle Designer 8.05<br /><br />And I am trying to create a dropdown form populated dynamically I guess from an .xml file.(Unless there is a better method)<br /><br />Basically I need to be able to have people update the contents of dro

  • Oracle Service Bus 11gR3(11.1.1.3.0) Clustering Configuration Error.

    Hi , I am trying to configure a domain with a AdminServer and 2 Managed servers hosting Oracle Service Bus. I created a admin server and it started up fine. Then i extended the domain and checked on Oracle Service Bus and tried to create two managed

  • Different weblogic instances listening to a topic

              Hi,           I have a scenario like this---.           I have 2 weblogic servers running on two different m/c s .They are NOT in a cluster.They           have their own JMS Servers running.There are some queues and one topic on each