-
Notifications
You must be signed in to change notification settings - Fork 2
/
time.ts
31 lines (24 loc) · 1.03 KB
/
time.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 1 second real time = 7 seconds tarkov time
const tarkovRatio = 7;
export function hrs(num: number) {
return 1000 * 60 * 60 * num;
}
export function realTimeToTarkovTime(time: Date, left: boolean) {
// tarkov time moves at 7 seconds per second.
// surprisingly, 00:00:00 does not equal unix 0... but it equals unix 10,800,000.
// Which is 3 hours. What's also +3? Yep, St. Petersburg - MSK: UTC+3.
// therefore, to convert real time to tarkov time,
// tarkov time = (real time * 7 % 24 hr) + 3 hour
const oneDay = hrs(24);
const russia = hrs(3);
const offset = russia + (left ? 0 : hrs(12));
const tarkovTime = new Date((offset + (time.getTime() * tarkovRatio)) % oneDay);
return tarkovTime;
}
export function timeUntilRelative(until: number, left: boolean, date: Date) {
const tarkovTime = realTimeToTarkovTime(date, left);
if (until < tarkovTime.getTime()) until += hrs(24);
const diffTarkov = until - tarkovTime.getTime();
const diffRT = diffTarkov / tarkovRatio;
return diffRT;
}