Re: Time creation and storage
Re: Time creation and storage
- Subject: Re: Time creation and storage
- From: Greg Herlihy <email@hidden>
- Date: Thu, 20 Apr 2006 16:01:36 -0700
- Thread-topic: Time creation and storage
The dateWithString routine is supplying default values for the missing day,
month and year values when the date is being created. And evidently the
default year value is the current year and the default month and day are
January and the first. After all, it is far more common to interpret a date
without a year as referring that date in the current year, then it would be
to assume that the date refers to one 36 years in the past.
If these default values are not the desired values, then the program should
not rely on them and should specify explicitly the year, month and day that
it wants when creating a date. And in any event, there is little likelihood
that the UNIX reference date would be ever be used for a default value since
CFDate's reference date is January 1, 2001.
Furthermore, since the properties in question represent points of time
within the span of the log sheet's date, I would think it make more sense to
store the start and stop times not as date-time values at all, but to
express their values as the number of minutes (or seconds) elapsed since
midnight on the date already being stored in the log sheet.
Greg
On 4/20/06 12:04 PM, "Robert Walker" <email@hidden> wrote:
> I have bumped into an issue with creating and storing time using NSDate.
>
> I have the following structure in my Core Data model:
>
> The Scenario:
> -----------------------------------------------------
> LogSheet <------->> Event
>
> There is one LogSheet per day. LogSheet has a date field.
>
> Each LogSheet can have multiple Events with a start and end time for
> each event.
> -----------------------------------------------------
>
> The Problem:
> ------------------------------------------------------
> I'm using the following code to create the start and end times for
> Event:
>
> [anEvent setValue:[NSCalendarDate dateWithString:@"0800"
> calendarFormat:@"%H%M"] forKey:@"startTime"];
>
> I find it strange that the above example produces this result:
> 2006-01-01 08:00
>
> Instead of:
> 1970-01-01 08:00 <-------- 08:00 of the UNIX reference date
>
> Normally I wouldn't really care about this since I'm only interested
> in the time. However, this application is a Cocoa "front end" to a
> WebObjects Web Service application that serves as a persistent data
> store for this application.
>
> This causes problems with data/time math. It also causes problems
> related to Enterprise Objects Foundation (EOF). EOF receives
> 2006-01-01 08:00, but the "time" field in OpenBase stores only the
> time portion. So when the value is read back from the database it is
> based on the UNIX reference date.
> ------------------------------------------------------
>
> --
> Robert Walker
> email@hidden
>
>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Cocoa-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden