File

src/app/modules/shared/pipes/date-format/date-format.pipe.ts

Description

Pipe for date format

Metadata

Methods

transform
transform(value: Date | string | number, format: string)

To create date format pipe

Parameters :
Name Type Optional Description
value Date | string | number No

current Date, string or number

format string No

format of Date

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 '-';
    }
  }

}

results matching ""

    No results matching ""