Files
blitzkit/src/core/blitzkrieg/getTimeDaysAgo.ts
T

20 lines
609 B
TypeScript
Raw Normal View History

import { Region } from '../../constants/regions';
2023-07-10 01:23:49 +00:00
export const TIME_ZONE_MAPPINGS: Record<Region, number> = {
2023-07-10 01:23:49 +00:00
com: -5, // Central North American Time
eu: +1, // Central European Time
asia: +7, // Central Asia Standard Time
};
2023-08-04 02:24:14 +00:00
export default function getTimeDaysAgo(region: Region, daysAgo: number) {
2023-06-19 17:35:28 +00:00
const now = new Date();
2023-07-10 01:23:49 +00:00
if (daysAgo === 0) now.getTime() / 1000;
2023-06-19 17:35:28 +00:00
2023-07-10 01:23:49 +00:00
const time = new Date();
2023-06-19 17:35:28 +00:00
2023-08-04 02:24:14 +00:00
time.setUTCHours(-TIME_ZONE_MAPPINGS[region], 0, 0, 0);
2023-07-10 01:23:49 +00:00
if (time > now) time.setUTCDate(time.getUTCDate() - 1);
time.setUTCDate(time.getUTCDate() - daysAgo + 1);
2023-06-19 17:35:28 +00:00
2023-07-10 01:23:49 +00:00
return time.getTime() / 1000;
2023-06-19 17:35:28 +00:00
}