' Gambas module file
Public Sub Main()
Dim d As Date
Dim s As String
Dim i As Integer
s = "27/1/2013"
d = Date(Val(s))
i = GiornoFase(d)
Print "Giorno fase: "; i,
If i = 0 Then
Print "Luna nuova"
Else If i < 15 Then
Print "Luna crescente"
Else If i = 15 Then
Print "Luna piena"
Else If i > 15 Then
Print "Luna calante"
Endif
End
Public Function GiornoFase(value As Date) As Integer
Dim giorno, mese, anno, fase As Integer
giorno = Day(value)
mese = Month(value)
anno = Year(value)
If mese = 1 Or If mese = 2 Then anno -= 1
fase = giorno + capomese(mese) + epatta(anno) + 1
If fase > 30 Then fase -= 30
Print "Capomese: "; capomese(mese), "Epatta: "; epatta(anno)
Return fase
End
Public Function capomese(mese As Integer) As Integer
Dim cc As Integer[] = [11, 12, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Return cc[mese - 1]
End
Public Function epatta(anno As Integer) As Integer
Dim cc As Integer[] = [0, 11, 22, 3, 14, 25, 6, 17, 28, 9, 20, 1, 12, 23, 4, 15, 26, 7, 18, 9, 10, 21, 2, 13, 24, 5, 16, 27, 8, 19]
Dim dd As Integer[] = [19, 8, 27, 16, 5, 24, 13, 2, 21, 10, 9, 18, 7, 26, 15, 4, 23, 12, 1, 20, 9, 28, 17, 6, 25, 14, 3, 22, 11, 0]
Dim resto, valore As Integer
If anno = 2006 Then Return 0
If anno > 2006 Then
valore = anno - 2006
If valore > 30 Then
resto = valore Mod 30
Return cc[resto]
Else
Return cc[valore]
Endif
Else
valore = 2005 - anno
If valore > 30 Then
resto = valore Mod 30
Return dd[resto]
Else
Return dd[valore]
Endif
Endif
End
Si basa sul fatto che, sempre in base a questo documento e più precisamente alla tabella dell'epatta, ho notato che si ripete costante di trent'anni in trent'anni la stessa sequenza.