Skip to content

Instantly share code, notes, and snippets.

@lydemann
Created March 31, 2019 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lydemann/26f0b9d20de5394280201ecfcb4136af to your computer and use it in GitHub Desktop.
Save lydemann/26f0b9d20de5394280201ecfcb4136af to your computer and use it in GitHub Desktop.
duedate-today-count.pipe.ts
import { Pipe, PipeTransform } from '@angular/core';
import { TODOItem } from '@app/shared/models/todo-item';
@Pipe({
name: 'duedateTodayCount'
})
export class DuedateTodayCountPipe implements PipeTransform {
transform(todoItems: TODOItem[], args?: any): any {
console.log('Called getDuedateTodayCount');
return todoItems.filter((todo) => this.isToday(new Date(todo.dueDate))).length;
}
private isToday(someDate) {
const today = new Date();
return (
someDate.getDate() == today.getDate() &&
someDate.getMonth() == today.getMonth() &&
someDate.getFullYear() == today.getFullYear()
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment