add date format pipe

This commit is contained in:
X4Lo committed 2024-04-02 03:40:46 +00:00
1 parent e7d574922b
commit d2822f7980
2 files changed
+24

No files matched your search

@@ -0,0 +1,8 @@
import { DateFormatPipe } from './date-format.pipe';
describe('DateFormatPipe', () => {
it('create an instance', () => {
const pipe = new DateFormatPipe();
expect(pipe).toBeTruthy();
});
});
@@ -0,0 +1,16 @@
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({
name: 'dateFormat'
})
export class DateFormatPipe implements PipeTransform {
transform(value: string): string {
if (!value) return '';
const date = new Date(value);
const formatter = new Intl.DateTimeFormat('en-US', { month: 'long', day: '2-digit', year: 'numeric' });
return formatter.format(date);
}
}