My favorites | Sign in
Project Home Downloads Wiki Issues Source
Checkout   Browse   Changes    
 
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
56
57
58
59
60
61
62
63
64
65
66
67
# ----------------------------------------------------------------------------
# Mostra a data do domingo de Páscoa para qualquer ano.
# Obs.: Se o ano não for informado, usa o atual.
# Regra: Primeiro domingo após a primeira lua cheia a partir de 21 de março.
# Uso: zzpascoa [ano]
# Ex.: zzpascoa
# zzpascoa 1999
#
# Autor: Aurelio Marinho Jargas, www.aurelio.net
# Desde: 2008-10-23
# Licença: GPL
# Tags: data
# ----------------------------------------------------------------------------
zzpascoa ()
{
zzzz -h pascoa "$1" && return

local dia mes a b c d e f g h i k l m p q
local ano="$1"

# Se o ano não for informado, usa o atual
test -z "$ano" && ano=$(date +%Y)

# Validação
zztool -e testa_ano $ano || return 1

# Algoritmo de Jean Baptiste Joseph Delambre (1749-1822)
# conforme citado em http://www.ghiorzi.org/portug2.htm
#
if [ $ano -lt 1583 ]
then
a=$(( ano % 4 ))
b=$(( ano % 7 ))
c=$(( ano % 19 ))
d=$(( (19*c + 15) % 30 ))
e=$(( (2*a + 4*b - d + 34) % 7 ))
f=$(( (d + e + 114) / 31 ))
g=$(( (d + e + 114) % 31 ))

dia=$(( g+1 ))
mes=$f
else
a=$(( ano % 19 ))
b=$(( ano / 100 ))
c=$(( ano % 100 ))
d=$(( b / 4 ))
e=$(( b % 4 ))
f=$(( (b + 8) / 25 ))
g=$(( (b - f + 1) / 3 ))
h=$(( (19*a + b - d - g + 15) % 30 ))
i=$(( c / 4 ))
k=$(( c % 4 ))
l=$(( (32 + 2*e + 2*i - h - k) % 7 ))
m=$(( (a + 11*h + 22*l) / 451 ))
p=$(( (h + l - 7*m + 114) / 31 ))
q=$(( (h + l - 7*m + 114) % 31 ))

dia=$(( q+1 ))
mes=$p
fi

# Adiciona zeros à esquerda, se necessário
[ $dia -lt 10 ] && dia="0$dia"
[ $mes -lt 10 ] && mes="0$mes"

echo "$dia/$mes/$ano"
}

Change log

r710 by aureliojargas on Mar 29, 2012   Diff
SEGURANÇA: $1 colocado entre aspas na
chamada padrão zzzz -h de todas as
funções.
Go to: 
Sign in to write a code review

Older revisions

r668 by aureliojargas on Mar 28, 2012   Diff
lint: removendo espaços inúteis.
r655 by aureliojargas on Mar 23, 2012   Diff
s/Aurélio/Aurelio/ *
r540 by aureliojargas on May 24, 2011   Diff
COMBO: Removidos espaços e tabs
inúteis do fim das linhas, verificados
por utils/alinhamento
All revisions of this file

File info

Size: 1640 bytes, 67 lines
Powered by Google Project Hosting