0
votes

NSDate value is returned by CloudKit. Which representation will system choose, when I am storing date in Core Data as NSTimeInterval? I know NSTimeInterval stores number of seconds since some specific reference date. But which reference date will be choosen here?

mo.setValue(record.creationDate, forKey: "creationDate")

Latter on I have to compare this date with current date, so I have to convert it back to NSDate, so I have to use one of the NSDate timeIntervalSinceXXX methods.


I have found this in docs:

Dates and Times NSManagedObject represents date attributes using NSDate objects, and stores times internally as an NSTimeInterval value since the reference date (which has a time zone of GMT). Time zones are not explicitly stored—indeed you should always represent a Core Data date attribute in GMT, this way searches are normalized in the database. If you need to preserve the time zone information, you need to store a time zone attribute in your model. This may again require you to create a subclass of NSManagedObject.

I does not say anything what is the reference

1
i'd guess dateWithTimeIntervalSince1970: Everything else would just cause problems. - luk2302
phew, i did not know about that one ;) i will google for a bit... - luk2302
and here you probably have your answer: stackoverflow.com/questions/10705062/… - luk2302
doc is not so 'straightforward', 1970 could be also a 'reference date' but I think stores times internally as an NSTimeInterval value since the reference date sentence means timeIntervalSinceReferenceDate I have to use - János

1 Answers

0
votes

As stated in the documentation and in comments, the internal NSDate reference date is 1 January 2001, which is what is used by Core Data internally when serializing NSDate objects to the database representation.

See Wikipedia's article on epoch. NSDate and CFDate both use the Cocoa epoch time (which dates at least to 1994, in the OpenStep specifications).