Skip to content

Instantly share code, notes, and snippets.

@StalinMazaEpn
Created May 30, 2020 23:25
Show Gist options
  • Save StalinMazaEpn/1f72cc2f83271e792445b116b3e577d4 to your computer and use it in GitHub Desktop.
Save StalinMazaEpn/1f72cc2f83271e792445b116b3e577d4 to your computer and use it in GitHub Desktop.
MomentJS Pipe Typescript - Angular
import { Pipe, PipeTransform } from '@angular/core';
declare var moment: any;
moment.locale('es');
@Pipe({
name: 'moment_pipe'
})
export class MomentPipe implements PipeTransform {
transform(value: Date | string, dateFormat: string): any {
if(dateFormat == 'fromNow'){
return `hace ${moment(value).fromNow(true)}`;
}
if(dateFormat == 'calendar'){
return moment(value).calendar();
}
return moment(value).format(dateFormat);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment