feat: add moment.js based date pipe

This commit is contained in:
4gray committed 2021-02-05 00:03:31 +01:00
1 parent d008115b26
commit 4881ba8fe0
3 files changed
+29 -1

No files matched your search

@@ -0,0 +1,8 @@
import { MomentDatePipe } from './moment-date.pipe';
describe('Pipe: MomentDatee', () => {
it('create an instance', () => {
const pipe = new MomentDatePipe();
expect(pipe).toBeTruthy();
});
});
+18
View File
@@ -0,0 +1,18 @@
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment';
/**
* Moment.js based pipe to parse and return the provided date based on given params
*/
@Pipe({
name: 'momentDate',
})
export class MomentDatePipe implements PipeTransform {
transform(
value: string,
formatToParse: string,
formatToReturn = 'MMMM Do, dddd'
): any {
return moment(value, formatToParse).format(formatToReturn);
}
}
+3 -1
View File
@@ -6,9 +6,10 @@ import { HeaderComponent } from './components/';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MaterialModule } from 'app/material.module';
import { FilterPipeModule } from 'ngx-filter-pipe';
import { MomentDatePipe } from './pipes/moment-date.pipe';
@NgModule({
declarations: [HeaderComponent],
declarations: [HeaderComponent, MomentDatePipe],
imports: [
CommonModule,
FilterPipeModule,
@@ -24,6 +25,7 @@ import { FilterPipeModule } from 'ngx-filter-pipe';
FormsModule,
HeaderComponent,
MaterialModule,
MomentDatePipe,
ReactiveFormsModule,
TranslateModule,
],