-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintervals.lua
47 lines (40 loc) · 999 Bytes
/
intervals.lua
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
local intervals = {}
intervals.IntervalSecondsMap = {
["5m"] = 300,
["15m"] = 900,
["1h"] = 3600,
["4h"] = 14400,
["12h"] = 57600,
["6h"] = 21600,
["1d"] = 86400,
["7d"] = 86400 * 7,
["1M"] = 2592000
}
function intervals.getIntervalStart(timestamp, interval)
timestamp = math.floor(timestamp) -- Ensure timestamp is an integer
local date = os.date("!*t", timestamp)
if interval == "1h" then
date.min = 0
date.sec = 0
elseif interval == "15m" then
date.min = 0
date.sec = 0
elseif interval == "4h" then
date.min = 0
date.sec = 0
date.hour = date.hour - (date.hour % 4)
elseif interval == "1d" then
date.hour = 0
date.min = 0
date.sec = 0
elseif interval == "1M" then
date.day = 1
date.hour = 0
date.min = 0
date.sec = 0
else
error("Unsupported interval: " .. interval)
end
return os.time(date)
end
return intervals