2019-07-24 10:36:48 -06:00
|
|
|
const dateTimeIntervals = {
|
2020-03-06 09:04:36 -07:00
|
|
|
'day': 86400000,
|
|
|
|
'hour': 3600000,
|
2020-03-06 19:23:31 -07:00
|
|
|
'ms': 1,
|
2019-07-24 10:36:48 -06:00
|
|
|
};
|
|
|
|
|
2020-03-06 19:23:31 -07:00
|
|
|
export function dateUTC(time: number[]): Date {
|
2020-03-19 11:46:13 -06:00
|
|
|
return new Date(Date.UTC(...time));
|
2019-07-24 10:36:48 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
export function isTimeSame(a: Date, b: Date): boolean {
|
2020-02-29 00:38:07 -07:00
|
|
|
return a.getTime() === b.getTime();
|
2019-07-24 10:36:48 -06: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;
|
|
|
|
}
|
|
|
|
|
2020-03-06 19:23:31 -07:00
|
|
|
export function addTime(x: Date, value: number, span: keyof typeof dateTimeIntervals = 'ms'): Date {
|
2019-07-24 10:36:48 -06:00
|
|
|
return new Date(x.getTime() + (value * dateTimeIntervals[span]));
|
|
|
|
}
|
|
|
|
|
2020-03-06 19:23:31 -07:00
|
|
|
export function subtractTime(x: Date, value: number, span: keyof typeof dateTimeIntervals = 'ms'): Date {
|
2019-07-24 10:36:48 -06:00
|
|
|
return new Date(x.getTime() - (value * dateTimeIntervals[span]));
|
|
|
|
}
|