-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathcalendar-progress-widget.lua
More file actions
89 lines (75 loc) · 3.14 KB
/
calendar-progress-widget.lua
File metadata and controls
89 lines (75 loc) · 3.14 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
-- name = "Calendar Progress"
-- description = "Shows day, week, month, and year progress bars"
-- type = "widget"
-- author = "meluskyc"
-- version = "1.0"
-- foldable = "false"
local prefs = require "prefs"
function on_load()
prefs.show_day = true
prefs.show_week = true
prefs.show_month = true
prefs.show_year = true
end
function on_resume()
local now = os.date("*t", os.time())
local gui_elems = {}
if prefs.show_day then
local seconds_since_day_start =
now.sec + -- current minute
now.min * 60 + -- previous minutes
now.hour * 3600 -- previous hours
local progress_percentage = math.floor((seconds_since_day_start / (24 * 60 * 60)) * 100)
local label = "Day: " .. progress_percentage .. "%"
table.insert(gui_elems, {"progress", label, {progress = progress_percentage}})
if prefs.show_week or prefs.show_month or prefs.show_year then
table.insert(gui_elems, {"new_line", 1})
end
end
if prefs.show_week then
local seconds_since_week_start =
now.sec + -- current minute
now.min * 60 + -- previous minutes
now.hour * 3600 + -- previous hours
(now.wday - 1) * 86400 -- previous days
local progress_percentage = math.floor((seconds_since_week_start / (7 * 24 * 60 * 60)) * 100)
local label = "Week: " .. progress_percentage .. "%"
table.insert(gui_elems, {"progress", label, {progress = progress_percentage}})
if prefs.show_month or prefs.show_year then
table.insert(gui_elems, {"new_line", 1})
end
end
if prefs.show_month then
local days_in_month = os.date("*t", os.time{year=now.year, month=now.month+1, day=0}).day
local seconds_since_month_start =
now.sec + -- current minute
now.min * 60 + -- previous minutes
now.hour * 3600 + -- previous hours
(now.day - 1) * 86400 -- previous days
local progress_percentage = math.floor((seconds_since_month_start / (days_in_month * 24 * 60 * 60)) * 100)
local label = "Month: " .. progress_percentage .. "%"
table.insert(gui_elems, {"progress", label, {progress = progress_percentage}})
if prefs.show_year then
table.insert(gui_elems, {"new_line", 1})
end
end
if prefs.show_year then
local seconds_since_year_start =
now.sec + -- current minute
now.min * 60 + -- previous minutes
now.hour * 3600 + -- previous hours
(now.yday - 1) * 86400 -- previous days
-- check for leap year
local days_in_year = 365
if (now.year % 4 == 0 and now.year % 100 ~= 0) or (now.year % 400 == 0) then
days_in_year = 366
end
local progress_percentage = math.floor((seconds_since_year_start / (days_in_year * 24 * 60 * 60)) * 100)
local label = "Year: " .. progress_percentage .. "%"
table.insert(gui_elems, {"progress", label, {progress = progress_percentage}})
end
gui(gui_elems).render()
end
function on_settings()
prefs:show_dialog()
end