reworked the date format pipe
This commit is contained in:
1 parent
e30c58ed90
commit
fbca314026
1 file changed
+18
-6
@@ -1,16 +1,28 @@
|
|||||||
import { Pipe, PipeTransform } from '@angular/core';
|
import { Pipe, PipeTransform } from '@angular/core';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
|
||||||
@Pipe({
|
@Pipe({
|
||||||
name: 'dateFormat'
|
name: 'dateFormat',
|
||||||
})
|
})
|
||||||
export class DateFormatPipe implements PipeTransform {
|
export class DateFormatPipe implements PipeTransform {
|
||||||
|
// transform(value: string): string {
|
||||||
|
// if (!value) return '';
|
||||||
|
|
||||||
transform(value: string): string {
|
// const date = new Date(value);
|
||||||
if (!value) return '';
|
// const formatter = new Intl.DateTimeFormat('en-US', { month: 'long', day: '2-digit', year: 'numeric' });
|
||||||
|
// return formatter.format(date);
|
||||||
|
// }
|
||||||
|
|
||||||
const date = new Date(value);
|
transform(
|
||||||
const formatter = new Intl.DateTimeFormat('en-US', { month: 'long', day: '2-digit', year: 'numeric' });
|
value: Date | string | number,
|
||||||
return formatter.format(date);
|
formatString: string = 'yyyy-MM-dd'
|
||||||
|
): string {
|
||||||
|
const date = value instanceof Date ? value : new Date(value);
|
||||||
|
if (!date.getTime()) {
|
||||||
|
console.log('Invalid date provided to customDateFormat');
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return format(date, formatString);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user