import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class FunctionsService {

  constructor() { }

  orderDate(date: string): string {
    let dateTimeArr = date.split(' ');
    let dateArr = dateTimeArr[0].split('-');
    dateArr = dateArr.reverse();

    let dateStr =dateArr.join('-');
    let timeArr = dateTimeArr[1].split(':');
    let hour = parseInt(timeArr[0]);

    let timeLapse = hour > 12 ? 'PM' : 'AM';
    if(timeLapse == 'PM') hour = hour - 12;
    let hourStr = hour < 10 ? `0${hour}` : `${hour}`;

    timeArr[0] = hourStr;
    let timeStr = timeArr.join(':');
    
    return `${dateStr} ${timeStr} ${timeLapse}`;
  }

  buildName(no: string, ap: string, am: string): string{
    let name = `${no} ${ap}`;
    if(am != "" && am != undefined && am != null){
      name += ` ${am}`;
    }
    return name;
  }
}
