mirror of
https://github.com/MisskeyIO/misskey
synced 2024-12-26 12:38:16 +09:00
1b48e0d6e0
This reverts commit 0420c548da
.
30 lines
811 B
TypeScript
30 lines
811 B
TypeScript
const dateTimeIntervals = {
|
|
'day': 86400000,
|
|
'hour': 3600000,
|
|
'ms': 1,
|
|
};
|
|
|
|
export function dateUTC(time: number[]): Date {
|
|
return new Date(Date.UTC(...time));
|
|
}
|
|
|
|
export function isTimeSame(a: Date, b: Date): boolean {
|
|
return a.getTime() === b.getTime();
|
|
}
|
|
|
|
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 addTime(x: Date, value: number, span: keyof typeof dateTimeIntervals = 'ms'): Date {
|
|
return new Date(x.getTime() + (value * dateTimeIntervals[span]));
|
|
}
|
|
|
|
export function subtractTime(x: Date, value: number, span: keyof typeof dateTimeIntervals = 'ms'): Date {
|
|
return new Date(x.getTime() - (value * dateTimeIntervals[span]));
|
|
}
|