TypeScript: Creating a date filter to show ‘days ago’ in ag-grid

Though I’ve wrote this function for Angular – ag-grid, this can be used as an independent method as well.

image

Code:

 LastUpdated(value: string):string {
let inputDate = new Date(value);
let today = new Date();
let yesterday = new Date(today.setDate(today.getDate()-1));
let numdays = Math.round((today.getTime() - inputDate.getTime()) / (1000*3600*24));
let ret:string = formatDate(inputDate,"MMM, dd yyyy",'en-US', '+4');
if ( inputDate.setHours(0,0,0,0) == new Date().setHours(0,0,0,0)) {
ret = "Today";
} else if ( inputDate.setHours(0,0,0,0) == (yesterday.setHours(0,0,0,0))) {
ret = "Yesterday";
} else if (numdays >= 1 && numdays < 7) {
ret = numdays.toString() + " day" + ((numdays > 1)?'s':'') + " ago";
}
return ret;
}

Angular–ag-grid : how to format a date column?

While you will find multiple solutions for formatting a date in ag-grid on internet/stackoverflow and documentation, here is one method I found handy:

{ field: ‘DateUpdated’, valueFormatter: params => formatDate(params.value, ‘MMM, dd yyyy’, ‘en-US’) }

Angular-.NET knowledge refresh

Ok, last week I was on an Angular+.NET Core learning spree, and I had to continue since my goals were not met.

  • Monday – Angular foundation
  • Tuesday – Angular foundation cont. – services, .NET Core Web API setup, EF Core
  • Wednesday – continue same… had issues to debug
  • Thursday – replaced bootstrap with ng-bootstrap, for no reason
  • Friday – continues ng-bootstrap wars, and unhappy. Decides to learn Angular Material after reading UI library comparisons
  • Saturday, Today – continues with Angular Material