• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Time creation and storage [Solved]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Time creation and storage [Solved]


  • Subject: Re: Time creation and storage [Solved]
  • From: Robert Walker <email@hidden>
  • Date: Thu, 20 Apr 2006 19:45:36 -0400

Greg,

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.


Ahh. That actually does make sense. I guess I'm just used to the Java way of handling times without dates, which does use January 1, 1970 when parsing date/time strings that contain no date field values.

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.

Very good point. Unfortunately, I have a lot of existing data in the database, but I should be able to develop a workaround in the web services to take care of this. My Cocoa application is new. The WebObjects application supplying the data is not.


On Apr 20, 2006, at 7:01 PM, Greg Herlihy wrote:

See above...

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
References: 
 >Re: Time creation and storage (From: Greg Herlihy <email@hidden>)

  • Prev by Date: Re: Weird behavior when adding subview
  • Next by Date: NSOpenGLView's unwantedly 'linked'
  • Previous by thread: Re: Time creation and storage
  • Next by thread: how do I get notified when a key is pressed?
  • Index(es):
    • Date
    • Thread