Files
SkydiveLogs/Front/skydivelogs-app/src/services/date.service.ts
2021-06-29 18:10:47 +02:00

28 lines
775 B
TypeScript

import { Injectable } from '@angular/core';
@Injectable()
export class DateService {
private milliSeconInDay: number;
constructor() {
this.milliSeconInDay = 1000 * 60 * 60 * 24;
}
public AddDays(currentDate: Date, nbDays: number): Date {
const totalMilliSeconds = nbDays * this.milliSeconInDay;
const currentTime = currentDate.getTime();
const tmpDate = new Date(currentDate.getTime());
tmpDate.setTime(currentTime + totalMilliSeconds);
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;
}
}