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

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

  constructor() { }

  deferenceBetweenDays(start: any, end: any) {
    const diffTime = Math.abs(end - start);
    return Math.ceil(diffTime / (1000 * 60 * 60 * 24)); 
  }

  notSameDate(start: any, end: any): boolean {
    return new Date(start).toLocaleDateString() != new Date(end).toLocaleDateString()
  }
  isSameDate(start: any, end: any): boolean {
    return !this.notSameDate(start, end)
  }

  EventEndDateTreatment({startTime, endTime}) {

    const startTimeSamp = new Date(startTime).toLocaleDateString()
    const endTimeSamp = new Date(endTime).toLocaleDateString()

    const endMinutes = new Date(endTime).getMinutes()
    const endHours = new Date(endTime).getHours() 


    if (startTimeSamp < endTimeSamp  && (endMinutes + endHours) == 0) {
      endTime = new Date(endTime);
      endTime.setSeconds(endTime.getSeconds() - 1);
      return new Date(endTime)
    } else {
      return new Date(endTime)
    }
  }



  getDay(date) {
    return (((new Date (date)).getDate())).toString().padStart(2,'0')
  }
}
