2020-04-19 14:22:10 +02:00
|
|
|
import { Injectable } from '@angular/core';
|
2020-05-04 16:54:31 +02:00
|
|
|
import * as moment from 'moment';
|
2020-04-19 14:22:10 +02:00
|
|
|
|
|
|
|
@Injectable({
|
2020-04-21 17:26:25 +02:00
|
|
|
providedIn: 'root',
|
2020-04-19 14:22:10 +02:00
|
|
|
})
|
|
|
|
export class DateUtilsService {
|
2020-04-21 17:26:25 +02:00
|
|
|
public static addDaysToDate(days: number, date: Date): Date {
|
2020-05-04 16:54:31 +02:00
|
|
|
return moment(date).add(days, 'days').toDate();
|
2020-04-21 17:26:25 +02:00
|
|
|
}
|
2020-04-19 14:22:10 +02:00
|
|
|
|
2020-04-21 17:26:25 +02:00
|
|
|
public static diffInDays(dateLeft: Date, dateRight: Date): number {
|
2020-05-04 16:54:31 +02:00
|
|
|
return moment(dateLeft).diff(moment(dateRight));
|
2020-04-21 17:26:25 +02:00
|
|
|
}
|
2020-04-19 14:22:10 +02:00
|
|
|
|
2020-05-12 19:16:23 +02:00
|
|
|
public static isDateInFuture(date: Date): boolean {
|
|
|
|
return this.diffInDays(date, new Date()) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static isDateInPast(date: Date): boolean {
|
|
|
|
return this.diffInDays(date, new Date()) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static formatDate(date: Date): string {
|
2020-05-04 16:54:31 +02:00
|
|
|
return moment(date).format('yyyy-MM-dd');
|
2020-04-21 17:26:25 +02:00
|
|
|
}
|
2020-04-19 14:22:10 +02:00
|
|
|
}
|