UNPKG

unicorn-components

Version:

<a target="_blank" href="https://getunicorn.io"><img src="https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2017/Jul/07/2615006260-5-nitsnetsstudios-ondemand-UNI_avatar.png" align="left"></a>

16 lines (13 loc) 597 B
import * as moment from 'moment'; import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'formatDate' }) export class FormatDatePipe implements PipeTransform { transform(value: string, format: string = null, today = false, yesterday = false): string { if (!value) { return value; } const mo = moment(new Date(value)); if (!format) { return mo.calendar(); } if (today && moment().diff(mo, 'days') === 0) { return 'Today'; } if (yesterday && moment().diff(mo, 'days') === 1) { return 'Yesterday'; } return mo.format(format); } }