Bye moment from package.json (#5215)

* Bye moment from package.json

* Use Mapped types for argument type definition
This commit is contained in:
Satsuki Yanagi
2019-07-25 01:36:48 +09:00
committed by syuilo
parent fd2ae6d3cf
commit 88f5e8e8e2
6 changed files with 59 additions and 29 deletions

31
src/prelude/time.ts Normal file
View File

@@ -0,0 +1,31 @@
const dateTimeIntervals = {
'days': 86400000,
'hours': 3600000,
};
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 {
return (a.getTime() - b.getTime()) === 0;
}
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]));
}