// Dia da semana de uma data fornecida
//
// Zeller's congruence
//
// For the Gregorian calendar, Zeller's congruence is
//
// h = ( d + int ( (m+1)*26/10) + K + int(K/4) + int(J/4) + 5*J ) mod 7
// where
// h is the day of the week (0 = Saturday, 1 = Sunday, 2 = Monday, ...)
// d is the date of the month
// m is the month (3 = March, 4 = April, 5 = May, ..., 14 = February)
// K the year of the century (year mod 100).
// J is the century (actually year/100) (For example, in 1995 the century would be 19, even though it was the 20th century.)
//
// NOTE: In this algorithm January and February are counted as months 13 and 14 of the previous year.
// E.g. if it is February 2, 2010, the algorithm counts the date as the second day of the fourteenth
// month of 2009 (14/02/2009 in MM/DD/YYYY format)
//
function y=mod(m,n)
y=m-int(m/n)*n
endfunction
function y=diadasemana(d,m,a)
if m==1 | m==2
m=m+12;
a=a-1;
end
J=int(a/100);
K=mod(a,100);
h = mod( ( d + int ( (m+1)*26/10) + K + int(K/4) + int(J/4) + 5*J ) , 7)
ds=int8(h)
select ds
case 0 then
y='Sabado'
case 1 then
y='Domingo'
case 2 then
y='Segunda-feira'
case 3 then
y='TerĂ§a-feira'
case 4 then
y='Quarta-feira'
case 5 then
y='Quinta-feira'
case 6 then
y='Sexta-feira'
else
y='ERRO'
end
endfunction
diadasemana(01,01,2000)