NSPredicateEditorRowTemplate for date comparison

Posted by Dave DeLong on Stack Overflow See other posts from Stack Overflow or by Dave DeLong
Published on 2010-03-10T21:12:31Z Indexed on 2010/03/12 22:27 UTC
Read the original article Hit count: 253

I'm building an NSPredicateEditor, and I want the ability to do advanced date comparison.

I realize that I can build an NSPredicateEditorRowTemplate with a rightExpressionType of NSDateAttributeType, but the predicates I want to build need to be much more advanced than that.

For example, I need to basic comparison like:

  • dateKeypath < aDate
  • dateKeypath <= aDate
  • dateKeypath = aDate
  • dateKeypath != aDate
  • dateKeypath > aDate
  • dateKeypath >= aDate

These basic comparisons are quite easy to achieve, and I have these working. However, I also need to do comparisons like:

  • dateKeypath isInTheLast n days (or weeks, months, years)
  • dateKeypath isNotInTheLast n days (or weeks, months, years)
  • dateKeypath between aDate and anotherDate

How can I achieve these sorts of comparisons? I understand that I'll need to create a custom NSPredicateEditorRowTemplate, but I haven't found any clear documentation on how to achieve something like this.

EDIT Bonus points are available for also knowing how to make these comparisons a full date-time (year-month-day-hour-minute-second) comparison (as NSDateAttributeType only has year-month-day granularity).

© Stack Overflow or respective owner

Related posts about cocoa

Related posts about nspredicateeditor