• 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: Date constants in predicates
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Date constants in predicates


  • Subject: Re: Date constants in predicates
  • From: Phil Frost <email@hidden>
  • Date: Wed, 30 Nov 2005 09:20:35 -0500

On Wed, Nov 30, 2005 at 07:38:43AM -0500, Timothy Larkin wrote:
> Suppose the user has a text field in which he can compose a search
> predicate.  For instance, he writes, "name = 'David'", and triggers
> the action, which causes the program to create and use an NSPredicate
> object with that string as its query.
>
> This works fine for strings.  But how to construct date queries?
> Suppose he wants all records with a date attribute greater than a
> specific date?  He can't write "date >= 09/01/05" because the date
> constant is interpreted as an invalid number.  He can't write "date
> >= '09/01/05'", because the date constant is then interpreted as a
> string.  He can't even write "date >= [NSDate
> dateWithString:@"09/01/05"]", which is just imparseable.
>
> The IB function that automatically produces interfaces to Entities
> creates a predicate for a date object that is of the form
> "date.description contains[c] $value", but this is nearly useless,
> since it is simply a string comparison, and does not permit searching
> a date as a scalar.

I can't think of a magic way to do this, but it wouldn't be too hard to
write a regular expression which matches the date formats you want to
allow, and then process the user supplied predicate string by searching
for valid dates, replacing them with "%@", parsing the dates with
NSDate, and giving them to predicateWithFormat:argumentArray:. I haven't
tried this, but I imagine it would work.
 _______________________________________________
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: 
 >Date constants in predicates (From: Timothy Larkin <email@hidden>)

  • Prev by Date: Re: Warnings that won't go away
  • Next by Date: bindings and NSNumberFormatter
  • Previous by thread: Date constants in predicates
  • Next by thread: KVC keys vs acronym accessors
  • Index(es):
    • Date
    • Thread