Skip to content

Commit

Permalink
feat: add moment.js based date pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
4gray committed Feb 4, 2021
1 parent d008115 commit 4881ba8
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/app/shared/pipes/moment-date.pipe.spec.ts
Original file line number Diff line number Diff line change
@@ -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 changes: 18 additions & 0 deletions src/app/shared/pipes/moment-date.pipe.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}
4 changes: 3 additions & 1 deletion src/app/shared/shared.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -24,6 +25,7 @@ import { FilterPipeModule } from 'ngx-filter-pipe';
FormsModule,
HeaderComponent,
MaterialModule,
MomentDatePipe,
ReactiveFormsModule,
TranslateModule,
],
Expand Down

0 comments on commit 4881ba8

Please sign in to comment.