diff-for-humans.ts 471 B

123456789101112131415161718
  1. import { Pipe, PipeTransform } from "@angular/core";
  2. import TimeAgo from "javascript-time-ago";
  3. import en from "javascript-time-ago/locale/en";
  4. TimeAgo.locale(en);
  5. const timeAgo = new TimeAgo("en-US");
  6. @Pipe({
  7. name: "diffForHumans"
  8. })
  9. export class DiffForHumansPipe implements PipeTransform {
  10. /**
  11. * Takes a timestamp and makes the diff readable for humans.
  12. */
  13. transform(value: string, ...args) {
  14. return timeAgo.format(new Date(value), "twitter");
  15. }
  16. }