2019-07-24 18:36:48 +02:00
|
|
|
const dateTimeIntervals = {
|
2020-03-06 17:04:36 +01:00
|
|
|
'day': 86400000,
|
|
|
|
'hour': 3600000,
|
2019-07-24 18:36:48 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
export function DateUTC(time: number[]): Date {
|
|
|
|
const r = new Date(0);
|
|
|
|
r.setUTCFullYear(time[0], time[1], time[2]);
|
|
|
|
if (time[3]) r.setUTCHours(time[3], ...time.slice(4));
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isTimeSame(a: Date, b: Date): boolean {
|
2020-02-29 08:38:07 +01:00
|
|
|
return a.getTime() === b.getTime();
|
2019-07-24 18:36:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isTimeBefore(a: Date, b: Date): boolean {
|
|
|
|
return (a.getTime() - b.getTime()) < 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function isTimeAfter(a: Date, b: Date): boolean {
|
|
|
|
return (a.getTime() - b.getTime()) > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addTimespan(x: Date, value: number, span: keyof typeof dateTimeIntervals): Date {
|
|
|
|
return new Date(x.getTime() + (value * dateTimeIntervals[span]));
|
|
|
|
}
|
|
|
|
|
|
|
|
export function subtractTimespan(x: Date, value: number, span: keyof typeof dateTimeIntervals): Date {
|
|
|
|
return new Date(x.getTime() - (value * dateTimeIntervals[span]));
|
|
|
|
}
|