src/app/modules/shared/pipes/date-format/date-format.pipe.ts
Pipe for date format
Name | dateFormat |
transform | ||||||||||||
transform(value: Date | string | number, format: string)
|
||||||||||||
To create date format pipe
Parameters :
Returns :
string
|
import { Pipe, PipeTransform } from '@angular/core';
import dayjs from 'dayjs';
/**
* Pipe for date format
*
*/
@Pipe({
name: 'dateFormat'
})
export class DateFormatPipe implements PipeTransform {
/**
* To create date format pipe
*
* @param {Date} value current Date, string or number
* @param {string} format format of Date
*
*/
transform(value: Date | string | number, format: string): string {
if (value) {
return dayjs(value).format(format || 'DD MMMM YYYY'); // TODO: NEED to be tested
} else {
return '-';
}
}
}