codice:
'--------------------------------------------------------
'restituisce un vettore di date festive
'viene passato l'anno
'--------------------------------------------------------
Public Function DateFestive(ByVal anno%) As DateTime()
Dim Festivita() As DateTime = { _
New DateTime(anno, 1, 1), _
New DateTime(anno, 1, 6), _
New DateTime(anno, 4, 25), _
New DateTime(anno, 5, 1), _
New DateTime(anno, 6, 2), _
New DateTime(anno, 8, 15), _
New DateTime(anno, 10, 30), _
New DateTime(anno, 11, 1), _
New DateTime(anno, 12, 4), _
New DateTime(anno, 12, 8), _
New DateTime(anno, 12, 25), _
New DateTime(anno, 12, 26), _
PasquaGregoriana(anno), _
PasquaGregoriana(anno).AddDays(1)}
Festivita.Sort(Festivita)
Return Festivita
End Function
'------------------------------------------------------------------
'Restituisce vero o falso a seconda che la data passata sia
'festiva o meno
'------------------------------------------------------------------
Public Overloads Function IsFestive(ByVal Data As Date) As Boolean
Dim Anno%, Mese%, Giorno%
IsFestive = False
Anno = Data.Year 'Year(Data)
Mese = Data.Month 'Month(Data)
Giorno = Data.Day 'Day(Data)
If Mese = 1 And Giorno = 1 Then '1 gennaio
IsFestive = True
ElseIf Mese = 1 And Giorno = 6 Then '6 gennaio
IsFestive = True
ElseIf Mese = 4 And Giorno = 25 Then '25 aprile
IsFestive = True
ElseIf Mese = 5 And Giorno = 1 Then '1 maggio
IsFestive = True
ElseIf Mese = 6 And Giorno = 2 Then '2 giugno
IsFestive = True
ElseIf Mese = 8 And Giorno = 15 Then '15 agosto
IsFestive = True
ElseIf Mese = 10 And Giorno = 30 Then '30 ottobre San Saturnino Patrono
IsFestive = True
ElseIf Mese = 11 And Giorno = 1 Then '1 novembre
IsFestive = True
ElseIf Mese = 12 And Giorno = 4 Then '4 dicembre Santa Barbara
IsFestive = True
ElseIf Mese = 12 And Giorno = 8 Then '8 dicembre
IsFestive = True
ElseIf Mese = 12 And Giorno = 25 Then '25 dicembre
IsFestive = True
ElseIf Mese = 12 And Giorno = 26 Then '26 dicembre
IsFestive = True
Else
Dim Pasqua As DateTime
Pasqua = PasquaGregoriana(Anno)
Dim LunediAngelo As DateTime
LunediAngelo = Pasqua.AddDays(1) 'DateAdd("d", 1, Pasqua)
If Mese = Pasqua.Month And Giorno = Pasqua.Day Then
IsFestive = True
ElseIf Mese = LunediAngelo.Month And Giorno = LunediAngelo.Day Then
IsFestive = True
End If
End If
End Function
Public Overloads Function IsFestive(ByVal Anno%, ByVal Mese%, ByVal Giorno%) As Boolean
Return IsFestive(New DateTime(Anno, Mese, Giorno))
End Function
'---------------------------------------------------------------------------------------
' Routine che restituisce il giorno della Pasqua passando
' come parametro l'anno. L'algoritmo è valido per tutti gli anni
' nel Calendario Gregoriano, ossia dal 1583 in poi.
' Basata su un metodo sviluppato nel 1876 e che comparve
' nell'Ecclesiastical Calendar di Butcher, poi ripubblicato:
' - da Spencer Jones in "General Astronomy" del 1922
' - nel Journal of the British Astronomical Association, del 1977
' - da Jean Meeus in "Astronomical Formulae for Calculators" del 1979.
'
' Pasqua cade nella domenica seguente al primo plenilunio ecclesiastico dopo il 21 marzo
'---------------------------------------------------------------------------------------
Public Function PasquaGregoriana(ByVal anno%) As Date
Dim a%, b%, c%, p%, q%, r%
a = anno% Mod 19 : b = anno% \ 100 : c = anno% Mod 100
p = (19 * a + b - (b \ 4) - ((b - ((b + 8) \ 25) + 1) \ 3) + 15) Mod 30
q = (32 + 2 * ((b Mod 4) + (c \ 4)) - p - (c Mod 4)) Mod 7
r = (p + q - 7 * ((a + 11 * p + 22 * q) \ 451) + 114)
PasquaGregoriana = DateSerial(anno%, r \ 31, (r Mod 31) + 1)
End Function