-
-
Notifications
You must be signed in to change notification settings - Fork 116
/
dateUsFilterCondition.ts
18 lines (16 loc) · 1.08 KB
/
dateUsFilterCondition.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import { FieldType, FilterCondition, FilterConditionOption } from '../models/index';
import { testFilterCondition } from './filterUtilities';
import { mapMomentDateFormatWithFieldType } from './../services/utilities';
import * as moment_ from 'moment-mini';
const moment = moment_; // patch to fix rollup "moment has no default export" issue, document here https://github.com/rollup/rollup/issues/670
const FORMAT = mapMomentDateFormatWithFieldType(FieldType.dateUs);
export const dateUsFilterCondition: FilterCondition = (options: FilterConditionOption) => {
const searchTerms = Array.isArray(options.searchTerms) && options.searchTerms[0] || [];
if (!moment(options.cellValue, FORMAT, true).isValid() || !moment(searchTerms[0], FORMAT, true).isValid()) {
return true;
}
const dateCell = moment(options.cellValue, FORMAT, true);
const dateSearch = moment(searchTerms[0], FORMAT, true);
// run the filter condition with date in Unix Timestamp format
return testFilterCondition(options.operator || '==', parseInt(dateCell.format('X'), 10), parseInt(dateSearch.format('X'), 10));
};