0

I would like to create a Predicate that allows the user to search a date for a text string.

breeze.Predicate.create('startDate', 'contains', filterValue);

The filter value is entered by the user eg. '2014-06-'

'contains' will not work with a DateTime type.

Is is possible to convert the 'startDate' to a formatted string type when creating the Predicate?

Any help appreciated.

ForguesR
  • 3,558
  • 1
  • 17
  • 39
Paul
  • 75
  • 4

1 Answers1

0

Assuming the date format is fixed to yyyy-mm-dd then your best bet is probably converting the partial date to a real date.

  • If the filter value has more than 7 characters assume it is year and month and parse it accordingly. Create two dates, first day of the month (filterStartDate) and last day of the month (filterEndDate). You can have a look there to do that. With those two dates you will be able to mimic a contains with something like :
Predicate
.create('startDate', '>=', filterStartDate)
.or(    'startDate', '<',  filterEndDate);
  • If the filter value has less than 7 characters assume it is only the year. Parse the year (filterYear) and do something like :
Predicate
  .create('startDate', '>=', new Date(Date.UTC(filterYear, 0, 1))) 
  .or(    'startDate', '<',  new Date(Date.UTC(filterYear, 11, 30)));

Of course if the filter value is a full date then look for this date.

Community
  • 1
  • 1
ForguesR
  • 3,558
  • 1
  • 17
  • 39