import * as moment from 'moment';

export function toTime(timestamp: number): string {
  const date = moment.unix(timestamp / 1000).add(7, 'hours');

  const hours = date.hours();
  const minutes = date.minutes();
  return `${hours < 10 ? '0' : ''}${hours}:${
    minutes < 10 ? '0' : ''
  }${minutes}`;
}

export function phoneNumberOnly(phone: string): string {
  return phone.replace(/[^0-9]/g, '');
}

export function timeIsBefore(
  currentTime: number,
  time: number,
  diffInMilliseconds: number,
): boolean {
  return time < currentTime + diffInMilliseconds;
}
