-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCalendario.lua
55 lines (54 loc) · 1.14 KB
/
Calendario.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
function diaini (mes,ano)
local t = os.time ({day=1 ,month = mes , year = ano})
local data=os.date("*t",t)
return data.wday
end
function bissexto(ano)
if ano % 400 == 0 then
return true
elseif ano % 100 == 0 then
return false
elseif ano % 4 == 0 then
return true
else
return false
end
end
function ndiasmes(mes,ano)
if mes == 2 then
if bissexto(ano) then
return 29
else
return 28
end
elseif mes == 1 or mes == 3 or mes == 5 or mes == 7 or
mes == 8 or mes == 10 or mes == 12 then
return 31
else
return 30
end
end
function calendarioAD (mes,ano)
io.write("\n",mes," ",ano,"\n")
io.write("D\tS\tT\tQ\tQ\tS\tS\n")
local ini = diaini(mes,ano)
for i = 1 , ini-1 do
io.write("\t")
end
for dia = 1,ndiasmes(mes,ano) do
io.write(dia)
if (dia + ini-1) % 7 == 0 then
io.write("\n")
else
io.write("\t")
end
end
io.write("\n")
end
io.write("Digite o mês:")
mesl=io.read("*n")
io.write("Digite o ano:")
anol=io.read("*n")
calendarioAD(mesl-1,anol)
calendarioAD(mesl,anol)
calendarioAD(mesl+1,anol)