Created
May 30, 2020 23:25
-
-
Save StalinMazaEpn/1f72cc2f83271e792445b116b3e577d4 to your computer and use it in GitHub Desktop.
MomentJS Pipe Typescript - Angular
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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