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

@Injectable()
export class DateService {
    public addDays(currentDate: Date, nbDays: number): Date {
        const tmpDate = new Date(currentDate.getTime());
        tmpDate.setDate(tmpDate.getDate() + nbDays);

        return tmpDate;
    }

    public addMonths(currentDate: Date, nbMonths: number): Date {
        const tmpDate = new Date(currentDate.getTime());
        tmpDate.setMonth(tmpDate.getMonth() + nbMonths);

        return tmpDate;
    }

    public diffBetweenDates(beginDate: Date, endDate: Date): number {
        const diffInTime = endDate.getTime() - beginDate.getTime();
        const diffInDays = Math.round(diffInTime / (1000 * 3600 * 24));

        return diffInDays;
    }
}
