43 lines
1.4 KiB
Lua
Executable file
43 lines
1.4 KiB
Lua
Executable file
#!/usr/bin/env lua
|
|
|
|
-- Everything is in minutes
|
|
local DEFAULT_SLEEP_CYCLE = 90;
|
|
local DEFAULT_TIME_TO_FALL_ASLEEP = 40;
|
|
local DEFAULT_TIME_TO_SLEEP_POWERNAP = 5;
|
|
|
|
local gonnaFallAsleepIn, actualSleepCycle;
|
|
|
|
-- Returns text representation of hh:mm
|
|
-- calculated from [now] seconds
|
|
-- We cant use os.date because of time zones
|
|
local function getHoursAndMinsString(mins)
|
|
local hours = mins // 60;
|
|
local minutes = mins % 60;
|
|
return (hours > 9 and hours or "0" .. hours) .. "h" .. (minutes > 9 and minutes or "0" .. minutes) .. "m";
|
|
end
|
|
|
|
local args = { ... };
|
|
|
|
if (#args == 2) then
|
|
gonnaFallAsleepIn = tonumber(args[1]);
|
|
actualSleepCycle = tonumber(args[2]);
|
|
elseif (#args == 1) then
|
|
gonnaFallAsleepIn = tonumber(args[1]);
|
|
actualSleepCycle = DEFAULT_SLEEP_CYCLE;
|
|
else
|
|
gonnaFallAsleepIn = DEFAULT_TIME_TO_FALL_ASLEEP;
|
|
actualSleepCycle = DEFAULT_SLEEP_CYCLE;
|
|
end
|
|
|
|
local now = os.time();
|
|
|
|
print("If gonna fall sleep at: " .. os.date("%H:%M", now + (gonnaFallAsleepIn * 60)));
|
|
print("Wake up | to sleep\n------------------");
|
|
|
|
now = now + (gonnaFallAsleepIn * 60); -- We need to start counting from when we fall asleep
|
|
local sleepLen = actualSleepCycle;
|
|
for i = 0, 7, 1 do
|
|
print(os.date("%H:%M", now + (actualSleepCycle * 60)) .. " | " .. getHoursAndMinsString(sleepLen));
|
|
sleepLen = sleepLen + actualSleepCycle;
|
|
now = now + (actualSleepCycle * 60);
|
|
end
|