File size: 2,080 Bytes
df72131
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const { userNotification } = require("../sockets/Notification");
const { roundEnd } = require("../sockets/RoundStartEnd");

module.exports.scheduleRound2Start = function scheduleRound2Start(targetTime) {
    const currentTime = new Date().getTime();
    const delay = targetTime - currentTime;
    const notificationDelay5Mins = delay - (5 * 60 * 1000); // 5 minutes before round start
    const notificationDelay15Mins = delay - (15 * 60 * 1000); // 15 minutes before round start

    if (notificationDelay15Mins > 0) {
        setTimeout(callback15Mins, notificationDelay15Mins);
    }
    if (notificationDelay5Mins > 0) {
        setTimeout(callback5Mins, notificationDelay5Mins);
    }
    if (delay <= 0) {
        // Target time has already passed, execute the function immediately
        callback1();
    } else {
        setTimeout(callback1, delay);
    }
};

function callback15Mins() {
    userNotification("Round 2 will start in 15 minutes!");
}

function callback5Mins() {
    userNotification("Round 2 will start in 5 minutes!");
}

function callback1() {
    userNotification("Round 2 has started!");
}

module.exports.scheduleRound2End = function scheduleRound2End(targetTime) {
    const currentTime = new Date().getTime();
    const delay = targetTime - currentTime;
    const notificationDelay5Mins = delay - (5 * 60 * 1000); // 5 minutes before round end
    const notificationDelay15Mins = delay - (15 * 60 * 1000); // 15 minutes before round end

    if (notificationDelay15Mins > 0) {
        setTimeout(callback15Mins2, notificationDelay15Mins);
    }
    if (notificationDelay5Mins > 0) {
        setTimeout(callback5Mins2, notificationDelay5Mins);
    }
    if (delay <= 0) {
        // Target time has already passed, execute the function immediately
        callback2();
    } else {
        setTimeout(callback2, delay);
    }
};

function callback15Mins2() {
    userNotification("Round 2 will end in 15 minutes!");
}

function callback5Mins2() {
    userNotification("Round 2 will end in 5 minutes!");
}

function callback2() {
    roundEnd(2);
}