Re: How do I compare two NSDates using NSPredicate Core Data

2010-04-12 Thread Jeffrey Oleander
A date-time is a date-time, regardless of how it is 
displayed or entered or obtained from the system.

The whole purpose of the NSDate object is to allow easy
comparison, and determination of intervals by subtraction...
well, a couple of the main purposes... and be able to
display dates and intervals as appropriate to the context.

Calendar systems and date display formats don't lend 
themselves to such calculations, and change-overs from
one calendar to another have made it more difficult.

 On Fri, 2010/04/09, Ashley Clark acl...@ghoti.org wrote:
 From: Ashley Clark acl...@ghoti.org
 Subject: Re: How do I compare two NSDates using NSPredicate  Core Data
 To: Sean McBride s...@rogue-research.com
 Cc: Cocoa-dev@lists.apple.com
 Date: Friday, 2010 April 9, 12:52
 On 2010 Apr 5, at 19:02, Sean McBride wrote:
 On Sun, 2010 Apr 04 23:15:16 -0400, Michael A. Crawford said:
 Thus far I've gotten away with using
 -predicateWithFormat and scalar
 values.  I now need to compare a couple of
 NSDate instances but am not
 sure how to code it up with NSPredicate. 
 Consider me a 'visual' learner.

 I'm pretty sure you can use just , , ==, etc.
 with NSDates in NSPredicates.

 One thing that many people overlook is that NSDates
 *always* include a time component. And if that time
 wasn't specified explicitly it typically defaults
 to a preset value set in the editing control (if
 one was used) or the current time at the time the
 date string was parsed.
 
 So, if you were expecting to compare a set of NSDate
 objects to be on a particular date irrespective of
 their time value... you have a bit of work to do.
 A simple way to approximate the test is to look at
 a time range from midnight to midnight-1 second
 of the following day.

 That of course leaves another issue aside though,
 that of differing timezones. All NSDate objects are
 converted to the local timezone by default and the
 original timezone information is not stored in the
 object, so an NSDate created as {2010/01/01 23:59 EDT}
 when read back at some later point when the computer
 is now on the west coast (PDT) would show as
 {2009/12/31 20:59 PDT}.
 
 All of that to say, comparing dates with predicates
 (or at all) is hard.



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How do I compare two NSDates using NSPredicate Core Data

2010-04-12 Thread Jens Alfke


On Apr 12, 2010, at 9:35 AM, Jeffrey Oleander wrote:


A date-time is a date-time, regardless of how it is
displayed or entered or obtained from the system.
The whole purpose of the NSDate object is to allow easy
comparison, and determination of intervals by subtraction...


Yup. An NSDate is really just a fancy wrapper around a floating-point  
number (a CFAbsoluteTime) representing the number of seconds since  
1/1/2001.


(OK, an NSDate also remembers a time zone, but that's just for  
converting to human-readable form, it doesn't affect the actual time  
stored.)


—Jens___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How do I compare two NSDates using NSPredicate Core Data

2010-04-09 Thread Ashley Clark
On Apr 5, 2010, at 7:02 PM, Sean McBride wrote:

 On Sun, 4 Apr 2010 23:15:16 -0400, Michael A. Crawford said:
 
 Thus far I've gotten away with using -predicateWithFormat and scalar
 values.  I now need to compare a couple of NSDate instances but am not
 sure how to code it up with NSPredicate.  Consider me a 'visual' learner.
 
 I'm pretty sure you can use just , , ==, etc. with NSDates in NSPredicates.

One thing that many people overlook is that NSDates *always* include a time 
component. And if that time wasn't specified explicitly it typically defaults 
to a preset value set in the editing control (if one was used) or the current 
time at the time the date string was parsed.

So, if you were expecting to compare a set of NSDate objects to be on a 
particular date irrespective of their time value... you have a bit of work to 
do. A simple way to approximate the test is to look at a time range from 
midnight to midnight-1 second of the following day.

That of course leaves another issue aside though, that of differing timezones. 
All NSDate objects are converted to the local timezone by default and the 
original timezone information is not stored in the object, so an NSDate created 
as {2010/01/01 23:59 EDT} when read back at some later point when the computer 
is now on the west coast (PDT) would show as {2009/12/31 20:59 PDT}.

All of that to say, comparing dates with predicates (or at all) is hard.


Ashley

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How do I compare two NSDates using NSPredicate Core Data

2010-04-09 Thread Sean McBride
On Fri, 9 Apr 2010 12:52:21 -0500, Ashley Clark said:

 Thus far I've gotten away with using -predicateWithFormat and scalar
 values.  I now need to compare a couple of NSDate instances but am not
 sure how to code it up with NSPredicate.  Consider me a 'visual' learner.

 I'm pretty sure you can use just , , ==, etc. with NSDates in
NSPredicates.

One thing that many people overlook is that NSDates *always* include a
time component. And if that time wasn't specified explicitly it
typically defaults to a preset value set in the editing control (if one
was used) or the current time at the time the date string was parsed.

So, if you were expecting to compare a set of NSDate objects to be on a
particular date irrespective of their time value... you have a bit of
work to do. A simple way to approximate the test is to look at a time
range from midnight to midnight-1 second of the following day.

That of course leaves another issue aside though, that of differing
timezones. All NSDate objects are converted to the local timezone by
default and the original timezone information is not stored in the
object, so an NSDate created as {2010/01/01 23:59 EDT} when read back at
some later point when the computer is now on the west coast (PDT) would
show as {2009/12/31 20:59 PDT}.

All of that to say, comparing dates with predicates (or at all) is hard.

I get what you're saying, but a date represents an exact moment in time,
irrespective of location or time zone or any of that.  Sometimes people
may use an NSDate when they probably should be using NSDateComponents,
which you can easily do in a Core Data context using a 'transformable'
attribute.  Comparing NSDateComponents is harder because you also need a
calendar, etc.

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: How do I compare two NSDates using NSPredicate Core Data

2010-04-05 Thread Sean McBride
On Sun, 4 Apr 2010 23:15:16 -0400, Michael A. Crawford said:

Thus far I've gotten away with using -predicateWithFormat and scalar
values.  I now need to compare a couple of NSDate instances but am not
sure how to code it up with NSPredicate.  Consider me a 'visual' learner.

I'm pretty sure you can use just , , ==, etc. with NSDates in NSPredicates.

--

Sean McBride, B. Eng s...@rogue-research.com
Rogue Researchwww.rogue-research.com
Mac Software Developer  Montréal, Québec, Canada


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com