-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal.lua
executable file
·59 lines (45 loc) · 1.36 KB
/
cal.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
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env lua
conky_color = "${color2}%2d${color}"
t = os.date("*t", os.time())
year, month, currentday = t.year, t.month, t.day
daystart = os.date("*t", os.time{year=year,month=month,day=01}).wday
--require 'pl.pretty'.dump(daystart)
month_name = os.date("%B")
days_in_month = {
31, 28, 31, 30, 31, 30,
31, 31, 30, 31, 30, 31
}
-- check for leap year
-- Any year that is evenly divisible by 4 is a leap year
-- Any year that is evenly divisible by 100 is a leap year if
-- it is also evenly divisible by 400.
LeapYear = function (year)
return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
end
if LeapYear(year) then
days_in_month[2] = 29
end
title_start = (20 - (string.len(month_name) + 5)) / 2
title = string.rep(" ", math.floor(title_start + 0.5)) .. -- add padding to center the title
(" %s %s\n Mo Tu We Th Fr Sa Su\n"):format(month_name, year)
io.write("${color4}" .. title .. "${color}")
function seq(a, b)
if a > b then
return
else
return a, seq(a + 1, b)
end
end
days = days_in_month[month]
io.write("${color}")
io.write(
string.format(
string.rep(" ", daystart-2) ..
string.rep(" %2d", days), seq(1, days)
):gsub(string.rep(".", 21), "%0\n")
:gsub(("%2d"):format(currentday),
(conky_color):format(currentday),
1
) .. "\n"
)
io.write("${color}")