Luaスクリプトでもカレンダーを表示できます。 フォントはMS ゴシックなど同幅のフォント を指定してください。
-- calendar.lua
function weekday(y, m, q)
t = {year = y, month = m, day = 1}
return os.date("%w", os.time(t))
end
function isLeap(y)
return y % 4 == 0 and (y % 400 == 0 or y % 100 ~= 0)
end
function days(y, m)
local ds = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
if m == 2 and isLeap(y) then
return 29
end
return ds[m]
end
function calendar(y, m)
x = "";
local space = weekday(y, m, 1)
local tab = {}
for i = 1, space do tab[#tab+1] = " " end
for i = 1, days(y, m) do tab[#tab+1] = string.format("%2d", i) end
x = x .. string.format(" %2d月 %d\n", m, y)
x = x .. "日 月 火 水 木 金 土\n"
local n = 0
local ln = 0
for i = 1, #tab do
if i > 1 then
if n % 7 == 0 then
x = x .. "\n"
ln = ln + 1
else
x = x .. " "
end
end
x = x .. tab[i]
n = n + 1
end
if 6-ln > 0 then
for i = 1, 6-ln do x = x .. "\n" end
end
return x
end
function main()
local date = os.date("*t")
local m = date.month
local y = date.year
return calendar(y, m)
end
x = main()
comments powered by Disqus