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

20 lines
627 B
TypeScript
Raw Normal View History

2023-07-10 01:23:49 +00:00
import { BlitzServer } from '../../constants/servers.js';
export const TIME_ZONE_MAPPINGS: Record<BlitzServer, number> = {
com: -5, // Central North American Time
eu: +1, // Central European Time
asia: +7, // Central Asia Standard Time
};
export default function getTimeDaysAgo(server: BlitzServer, 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-07-10 17:42:29 +00:00
time.setUTCHours(-TIME_ZONE_MAPPINGS[server], 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
}