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

function pad(value: number, digits = 2) {
  let s = String(value);
  while (s.length < digits) {
    s = '0' + s;
  }
  return s;
}

@Pipe({
  name: 'exactHours',
})
export class ExactHoursPipe implements PipeTransform {
  transform(time: TimeWindow): string {
    return `${pad(time.from.hours)}:${pad(time.from.minutes)} - ${pad(time.to.hours)}:${pad(time.to.minutes)}`;
  }
}
