-
-
Save saplaum/68cad7afdcef71922eb0ade55eef9fea to your computer and use it in GitHub Desktop.
angular 2 moment pipe
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 'angular2/core'; | |
import * as moment from 'moment'; | |
/* | |
* Time helper using momentjs | |
* Usage: | |
* timestamp | moment:'DD.MM.YYYY' | |
* Defaults to 'L' - locale ie. '01/24/2016' | |
*/ | |
@Pipe({name: 'moment'}) | |
export class MomentPipe implements PipeTransform { | |
transform(value:number, args:string[]) : any { | |
let date = moment(value); | |
if (date.isValid()) { | |
return date.format(args[0] || 'L'); | |
} else { | |
return value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment