Storing NSDates and NSCalendarDates in a database

From EOFWiki
Jump to navigationJump to search

Storing NSDates as a number, an offset to GMT

This is the most foolproof solution. An existing NSDate or NSCalendarDate is internally a GMT based NSTimeInterval. A NSTimeInterval is the number of seconds since a references date (1.1.2001).

A NSCalendarDate has a timeZone tacked onto it, but the timeInterval associated with it never changes. Changing the timeZone does not change the timeInterval. Therefore if the timeInterval is interpreted as GMT by everybody, you will not run into any surprises.

The serverTimeZone of the EOAttribute is ignored.

Storing NSDates as strings

If you store a date as a string you should ensure, that the timeZone information is stored with it. That way there is no room for interpretation, when exactly 2013-08-23T23:00:00Z is. If this is a GMT time, in a German program this could be read as 24 August 2013, because the timeZone would add one hour to it. If the server responds with timeZone information, the serverTimeZone of the EOAttribute is ignored.

If you don't or can not store the timeZone information, you will have to define, what the serverTimeZone is in your EOAttribute. The dates will be formatted according to this timeZone and parsed as if coming from that timezone.

Storing NSDates as datetime

Datetime types of the database are analogous to strings. Does your database datetime support timezone ?