diff --git a/.config/awesome/misc/calendar.lua b/.config/awesome/misc/calendar.lua
index 35d3f6c..c1f2960 100644
--- a/.config/awesome/misc/calendar.lua
+++ b/.config/awesome/misc/calendar.lua
@@ -1,8 +1,4 @@
-function for_month(month, year)
- --local month_end = os.time(year = year, month = month + 1)
- --local d = os.date("*t", month_end)
- --local days, first_day = d.day, (d.wday - d.day) % 7
-
+function for_month(month, year, formats)
-- build header
local text = " "
for day_of_week = 1, 7 do
@@ -10,9 +6,36 @@ function for_month(month, year)
text = text .. os.date("%a ", os.time{year = 2006, month = 1, day = day_of_week})
end
- text = text .. "\n" .. month .. "." .. year
+ formats = formats or {}
- return text
+ local week = tonumber(os.date("%V", os.time{year = year, month = month, day = 1}))
+ local current_day = os.date("*t")
+
+ local prev_month_last_day = os.date("*t", os.time{year = year, month = month, day = 0})
+ local month_last_day = os.date("*t", os.time{year = year, month = month + 1, day = 0})
+ for day = 1 - (prev_month_last_day.wday % 7), month_last_day.day do
+ if (day + prev_month_last_day.wday - 1) % 7 == 0 then
+ text = text .. "\n " .. string.format("%.2d", week)
+ week = week + 1
+ end
+ local day_format, day_number
+ if day <= 0 then
+ day_format = "prev_month"
+ day_number = prev_month_last_day.day + day
+ elseif day == current_day.day and
+ month_last_day.month == current_day.month and
+ month_last_day.year == current_day.year then
+ day_format = "today"
+ day_number = day
+ else
+ day_format = "default"
+ day_number = day
+ end
+
+ text = text .. " " .. string.format(formats[day_format] or "%s", string.format("%2d", day_number))
+ end
+
+ return string.format("%.2d.%d", month_last_day.month, month_last_day.year) .. "\n" .. text
end
return { for_month = for_month }
diff --git a/.config/awesome/widgets/date.lua b/.config/awesome/widgets/date.lua
index 05010ff..3fd0529 100644
--- a/.config/awesome/widgets/date.lua
+++ b/.config/awesome/widgets/date.lua
@@ -5,7 +5,19 @@ local wibox = require('wibox')
local vicious = require('vicious')
-- {{{ OK: Date and time
+function calendar_for_month_markup(month, year)
+ local formats = {
+ today = '%s',
+ prev_month = '%s'
+ }
+ return '' .. calendar.for_month(month, year, formats) .. ''
+end
+
function create(self, format)
+ local calendar_formats = {
+ prev_month = '',
+ today = ''
+ }
local icon = wibox.widget.imagebox()
icon:set_image(beautiful.widget_date)
local widget = wibox.widget.textbox()
@@ -16,13 +28,13 @@ function create(self, format)
timer_function = function()
widget:set_text(os.date(' ' .. format .. ':%S '))
month, year = os.date('%m'), os.date('%Y')
- return calendar.for_month(month, year)
+ return calendar_for_month_markup(month, year)
end,
timeout = 60 * 60
})
function adjust_calendar(delta_months)
month = month + delta_months
- tooltip:set_text(calendar.for_month(month, year))
+ tooltip:set_text(calendar_for_month_markup(month, year))
end
local button = awful.util.table.join(