import { Pipe, PipeTransform } from "@angular/core";
import { CommonService } from "../../services/common/common.service";

@Pipe({
  name: "time"
})
export class TimePipe implements PipeTransform {
  constructor(public cs: CommonService) { }

  transform(value: any): any {
    if (value) {
      const dateTime = this.cs.evaluteDateAsObject(value);
      return this.cs.localizeTime(dateTime);
      // return this.evaluteTime(value);
    }
    return null;
  }

  public evaluteTime(dateStr: string): string {
    const utc = parseInt(dateStr.substring(6, dateStr.length - 2), 10);
    const appoDate = new Date(utc);
    return appoDate.toLocaleTimeString();
  }
}
