Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,9 @@ export class IgxDateFilteringOperand extends IgxBaseDateTimeFilteringOperand {
}
}

export class IgxDateTimeFilteringOperand extends IgxDateFilteringOperand {
export class IgxDateTimeFilteringOperand extends IgxBaseDateTimeFilteringOperand {
protected constructor() {
super();
let index = this.operations.indexOf(this.condition('equals'));
this.operations.splice(index, 1);
index = this.operations.indexOf(this.condition('doesNotEqual'));
this.operations.splice(index, 1);
this.operations = [{
name: 'equals',
isUnary: false,
Expand Down Expand Up @@ -432,6 +428,172 @@ export class IgxDateTimeFilteringOperand extends IgxDateFilteringOperand {
targetp.minutes !== searchp.minutes ||
targetp.seconds !== searchp.seconds;
}
}, {
name: 'before',
isUnary: false,
iconName: 'is-before',
logic: (target: Date, searchVal: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

return target < searchVal;
}
}, {
name: 'after',
isUnary: false,
iconName: 'is-after',
logic: (target: Date, searchVal: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

return target > searchVal;
}
}, {
name: 'today',
isUnary: true,
iconName: 'today',
logic: (target: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

const d = IgxDateTimeFilteringOperand.getDateParts(target, 'yMd');
const now = IgxDateTimeFilteringOperand.getDateParts(new Date(), 'yMd');
return d.year === now.year &&
d.month === now.month &&
d.day === now.day;
}
}, {
name: 'yesterday',
isUnary: true,
iconName: 'yesterday',
logic: (target: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

const td = IgxDateTimeFilteringOperand.getDateParts(target, 'yMd');
const y = ((d) => new Date(d.setDate(d.getDate() - 1)))(new Date());
const yesterday = IgxDateTimeFilteringOperand.getDateParts(y, 'yMd');
return td.year === yesterday.year &&
td.month === yesterday.month &&
td.day === yesterday.day;
}
}, {
name: 'thisMonth',
isUnary: true,
iconName: 'this-month',
logic: (target: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

const d = IgxDateTimeFilteringOperand.getDateParts(target, 'yM');
const now = IgxDateTimeFilteringOperand.getDateParts(new Date(), 'yM');
return d.year === now.year &&
d.month === now.month;
}
}, {
name: 'lastMonth',
isUnary: true,
iconName: 'last-month',
logic: (target: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

const d = IgxDateTimeFilteringOperand.getDateParts(target, 'yM');
const now = IgxDateTimeFilteringOperand.getDateParts(new Date(), 'yM');
if (!now.month) {
now.month = 11;
now.year -= 1;
} else {
now.month--;
}
return d.year === now.year &&
d.month === now.month;
}
}, {
name: 'nextMonth',
isUnary: true,
iconName: 'next-month',
logic: (target: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

const d = IgxDateTimeFilteringOperand.getDateParts(target, 'yM');
const now = IgxDateTimeFilteringOperand.getDateParts(new Date(), 'yM');
if (now.month === 11) {
now.month = 0;
now.year += 1;
} else {
now.month++;
}
return d.year === now.year &&
d.month === now.month;
}
}, {
name: 'thisYear',
isUnary: true,
iconName: 'this-year',
logic: (target: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

const d = IgxDateTimeFilteringOperand.getDateParts(target, 'y');
const now = IgxDateTimeFilteringOperand.getDateParts(new Date(), 'y');
return d.year === now.year;
}
}, {
name: 'lastYear',
isUnary: true,
iconName: 'last-year',
logic: (target: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

const d = IgxDateTimeFilteringOperand.getDateParts(target, 'y');
const now = IgxDateTimeFilteringOperand.getDateParts(new Date(), 'y');
return d.year === now.year - 1;
}
}, {
name: 'nextYear',
isUnary: true,
iconName: 'next-year',
logic: (target: Date) => {
if (!target) {
return false;
}

this.validateInputData(target);

const d = IgxDateTimeFilteringOperand.getDateParts(target, 'y');
const now = IgxDateTimeFilteringOperand.getDateParts(new Date(), 'y');
return d.year === now.year + 1;
}
}].concat(this.operations);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -456,13 +456,13 @@ describe('IgxGrid - Filtering actions #grid', () => {
const today = SampleTestData.todayFullDate;

// Equals 11:15:35
grid.filter('ReleaseDate', cal.timedelta(today, 'hour', 1),
grid.filter('ReleaseDateTime', cal.timedelta(today, 'hour', 1),
IgxDateTimeFilteringOperand.instance().condition('equals'));
fix.detectChanges();
expect(grid.rowList.length).toEqual(1);

// Does not equal 11:15:35
grid.filter('ReleaseDate', cal.timedelta(today, 'hour', 1),
grid.filter('ReleaseDateTime', cal.timedelta(today, 'hour', 1),
IgxDateTimeFilteringOperand.instance().condition('doesNotEqual'));
fix.detectChanges();
expect(grid.rowList.length).toEqual(7);
Expand Down Expand Up @@ -513,6 +513,7 @@ describe('IgxGrid - Filtering actions #grid', () => {
fix.detectChanges();
expect(grid.rowList.length).toEqual(1);
}));

it('should correctly filter by \'date\' filtering conditions when dates are ISO 8601 strings', fakeAsync(() => {
const cal = SampleTestData.timeGenerator;
const today = SampleTestData.today;
Expand Down