-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclosing-time.lua
More file actions
24 lines (20 loc) · 814 Bytes
/
Copy pathclosing-time.lua
File metadata and controls
24 lines (20 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env lua
print("Enter your times in h:m, hh:m, h:mm or hh:mm format")
print("Anything without this format is ignored")
print("Finish your input with Ctrl+D")
example = io.read("*all")
times = {}
for hour, minute in string.gmatch(example, "(%d+):(%d+)") do
table.insert(times, hour * 60 + minute)
end
table.sort(times)
remaining_minutes = 10 * 60 -- set this to your "desired" duration
for i=2,#times,2 do
local start_minutes, end_minutes = times[i-1], times[i]
local passed_minutes = end_minutes - start_minutes
remaining_minutes = remaining_minutes - passed_minutes
end
print("remaining minutes:", remaining_minutes)
latest_time = times[#times]
closing_time = latest_time + remaining_minutes
print("closing time:", string.format("%02d:%02d", closing_time // 60, closing_time % 60))