+ notifytable[#notifytable+1] = string.format("%-4s%s", strx, (x+st_day)%7==0 and x ~= mth_days and "\n" or "")
+ end
+ if string.len(cal.icons or "") > 0 and today then cal.icon = cal.icons .. today .. ".png" end
+ cal.month, cal.year = d.month, d.year
+
+ if cal.week_number ~= "none" then
+ local m = os.time { year = year or current_year, month = month and month or current_month, day = 0 }
+ local head_prepend = string.rep(" ", tostring(string.format(cal.week_number_format, 0)):len())
+
+ if cal.week_number == "left" then
+ notifytable[1] = head_prepend .. notifytable[1] -- month-year row
+ notifytable[2] = head_prepend .. notifytable[2] -- weekdays row
+ notifytable[8] = notifytable[8]:gsub("\n", "\n" .. cal.get_week_number(m, st_day, 0)) -- first week of the month
+
+ for x = 10,#notifytable do
+ if cal.sum_week_days(st_day, x) == 2 then
+ notifytable[x] = cal.get_week_number(m, st_day, x) .. notifytable[x]
+ end
+ end
+ elseif cal.week_number == "right" then
+ notifytable[8] = notifytable[8]:gsub("\n", head_prepend .. "\n") -- weekdays row
+ for x = 9,#notifytable do
+ if cal.sum_week_days(st_day, x) == 1 then
+ notifytable[x] = notifytable[x]:gsub("\n", cal.get_week_number(m, st_day, x - 7) .. "\n")
+ end
+ end
+ -- last week of the month
+ local end_days = cal.sum_week_days(st_day, mth_days)
+ if end_days ~= 0 then end_days = 7 - end_days end
+ notifytable[#notifytable] = notifytable[#notifytable] .. string.rep(" ", 4 * end_days) .. cal.get_week_number(m, st_day, mth_days + end_days)
+ end
+ end
+
+ return notifytable
+ end
+
+ function cal.getdate(month, year, offset)
+ if not month or not year then
+ month = tonumber(os.date("%m"))
+ year = tonumber(os.date("%Y"))
+ end
+
+ month = month + offset
+
+ while month > 12 do
+ month = month - 12
+ year = year + 1
+ end
+
+ while month < 1 do
+ month = month + 12
+ year = year - 1
+ end
+
+ return month, year
+ end
+
+ function cal.hide()
+ if not cal.notification then return end
+ naughty.destroy(cal.notification)
+ cal.notification = nil
+ end
+
+ function cal.show(seconds, month, year, scr)
+ cal.notification_preset.text = tconcat(cal.build(month, year))
+
+ if cal.three then
+ local current_month, current_year = cal.month, cal.year
+ local prev_month, prev_year = cal.getdate(cal.month, cal.year, -1)
+ local next_month, next_year = cal.getdate(cal.month, cal.year, 1)
+ cal.notification_preset.text = string.format("%s\n\n%s\n\n%s",
+ tconcat(cal.build(prev_month, prev_year)), cal.notification_preset.text,
+ tconcat(cal.build(next_month, next_year)))
+ cal.month, cal.year = current_month, current_year