Skip to content
Advertisement

Cheking day of the month in lua

So I’ve been configuring my AwesomeWM theme on Linux and I came across this issue. Now I’m not an expert programmer of course so I thought I’d come here to ask for help. I’ve been trying to check if the day of the month is a number from 1 to 9, which will then change the padding of the focused number on the calendar, but it doesn’t seem to work..

if (os.time(%d)>= 1) and (os.time(%d) <= 9) then
    theme.calendar_focus_padding = dpi(5)
else
    theme.calendar_focus_padding = dpi(10)
end

I’m getting errors on a whole different file (my rc.lua) which I don’t really understand why. Here’s the screenshot if anyone understands.

1

All I can understand from this is that it has an issue with the following lines of code (from my rc.lua file):

client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)

I know this is very specific to ask on stack overflow, but if anyone could help, I’d really appreciate that.

Advertisement

Answer

Right so this version seems to work:

if (os.date("%d") >= "1") and (os.date("%d") <= "9") then
    theme.calendar_focus_padding = dpi(5)
else
    theme.calendar_focus_padding = dpi(10)
end

however the code doesn’t act the way it should be. What I mean is, despite this being the 2nd day of July(which should switch the if statement to true and execute everything under the if and before the else statement, right?). Instead, it executes everything under the else statement (theme.calendar_focus_padding = dpi(10)). What’s up with that now?

EDIT: So I figured out that I had to convert os.date(etc) to an int. I did so using the tonumber() function and now I have this, which seems to work:

day = tonumber(os.date("%d"))

if (day >= 1) and (day <= 9) then
    theme.calendar_focus_padding = dpi(20)
else
    theme.calendar_focus_padding = dpi(10)
end
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement