import { Pipe, PipeTransform } from '@angular/core';

@Pipe({
  name: 'ifDate'
})
export class IfDatePipe implements PipeTransform {

  transform(value: any, args?: any): any {
    if (value) {
      if (typeof value === 'string') {
        return this.evaluteDate(value);
      }
    }
    return value;
  }

  public evaluteDate(str: string): string {
    const isDate = str.substring(1, 5);
    if (isDate && (isDate.toLocaleLowerCase() === 'date')) {
      const utc = parseInt(str.substring(6, str.length - 2), 10);
      const appoDate = new Date(utc);
      return appoDate.toLocaleDateString();

    } else {
      return str;
    }
  }


}
