Calcolare il giorno di Pasqua

Posted on Saturday, March 26, 2005 3:37 AM

Funzione per il calcolo della domenica di Pasqua, dal 326 al 4099, basata sull'algoritmo di Oudin-Tondering e implementata in VisualBasic.

Function EasterDay (d, m, ByVal y, ByVal method) As Boolean

' EASTER SUNDAY DATE CALCULATION
' This procedure returns Easter Sunday day and month
' for a specified year and method.
' Inputs:
'  y is the specified year
' method is 1, 2 or 3 as detailed below
' Outputs
' d & m are the returned day and month
' Procedure Calls
' Function ValidateArgs()
' Sub GetEasterDate()
'====================================================
' The Gregorian calendar has gradually been adopted world
' wide over from October 1582.  The last known use of the
' Julian calendar by the author was in Greece in 1923.
' Either at the time of the calendar change or at a later
' date, some (but not all) regions have used a revised
' Easter date calculation based on the Gregorian calendar.
' The Gregorian calendar is valid until 4099.
' As a result, the 3 possible methods are:
' 1. The original calculation based on the Julian calendar
' 2. The original calculation, with the Julian date
'    converted to the equivalent Gregorian date
' 3. The revised calculation based on the Gregorian calendar
' Most Western churches moved from method 1 to method 3 at
' the adoption of the Gregorian calendar, while most
' Orthodox churches moved from method 1 to method 2.
' Here is a guide on which method to use.  It is important
' check the history of the region in question to find the
' correct date of their change from Julian to Gregorian
' calendars, and if applicable, their change from the
' original to revised Easter Sunday date calculation.
' AUSTRALIA
'   Has used the Gregorian calendar since settlement
'   Western churches & public holidays use method 3
'   Orthodox churches use method 2
' EUROPE
'   For years 326 to 1582, use method 1
'   What was then Italy changed calendar AND calculation
'   method in October 1582, so for years 1583 to 4099,
'   use method 3.  Most mainland European regions had
'   converted to the Gregorian calendar by 1700
' ENGLAND
'   For years 326 to 1752, use method 1
'   Adopted the Gregorian calendar in September 1752
'   Use method 3 for Western churches for years 1753 to 4099
'   Use method 2 for Orthodox churches for years 1753 to 4099
' AMERICA
'   Use method 1 from 326 AD until changes as follows:
'   Regions of America under French influence adopted the
'   Gregorian calendar in October 1582, while regions
'   under British influence adopted both the new calendar
'   and calculation from September 1752.
'   Use method 2 for Orthodox churches after the adoption
'   of the Gregorian calendar.
'   Use method 3 for Western churches after the adoption
'   of the Gregorian calendar.
'======================================================
'Method 1: ORIGINAL CALCULATION
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' From 326 AD, Easter Sunday was determined as the
' Sunday following the Paschal Full Moon (PFM) date
' for the year based on the Julian Calendar.  PFM dates
' were made up of a simple cycle of 19 Julian calendar
' dates.  This method returns a Julian calendar date,
' and applies for all years from 326
' (The author's last known use of the Julian calendar
' was in Greece in 1923).
'Method 2: ORIGINAL CALCULATION converted to GREGORIAN CALENDAR
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' Same (original) calculation, also converts the Julian
' calendar date to the equivalent Gregorian calendar date.
' It applies for years 1583 to 4099.  This method
' is currently used by Orthodox Churches.
'Method 3: REVISED CALCULATION
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
' This method calculates Easter Sunday as the Sunday
' following the Paschal Full Moon (PFM) date for the
' year based on the Gregorian Calendar.  PFM dates are
' calculated from the relationship between the sun,
' moon & earth (as understood in 1582) using many 19
' Gregorian calendar date cycles.   This method was
' adopted from 1583 in Europe, 1753 in England and is
' currently used by Western churches.
'================================================
' Validate arguments
' returns true if y (year) and method combination is valid
' y and method are both integers
 d = 0     'default values for invalid arguments
 m = 0
 EasterMallen = False
 If method < 1 Or method > 3 Then
  MsgBox "Method must be 1, 2 or 3", 48
  Exit Function
 ElseIf method = 1 And y < 326 Then
  MsgBox "The original calculation applies to all years from 326 AD", 48
  Exit Function
 ElseIf (method = 2 Or method = 3) And (y < 1583 Or y > 4099) Then
  MsgBox "Gregorian calendar Easters apply for years 1583 to 4099 only", 48
  Exit Function
 Else
  EasterMallen = True
 End If
    
' Calculate Easter Sunday date
 Dim FirstDig, Remain19, temp    'intermediate results (all integers)
 Dim tA, tB, tC, tD, tE          'table A to E results (all integers)
 FirstDig = y \ 100              'first 2 digits of year (\ means integer division)
 Remain19 = y Mod 19             'remainder of year / 19
 If method = 1 Or method = 2 Then
 ' calculate PFM date
  tA = ((225 - 11 * Remain19) Mod 30) + 21
 ' find the next Sunday
  tB = (tA - 19) Mod 7
  tC = (40 - FirstDig) Mod 7
  temp = y Mod 100
  tD = (temp + temp \ 4) Mod 7
  tE = ((20 - tB - tC - tD) Mod 7) + 1
  d = tA + tE
  If method = 2 Then  'convert Julian to Gregorian date
   '10 days were 'skipped' in the Gregorian calendar from 5-14 Oct 1582
   temp = 10
   'Only 1 in every 4 century years are leap years in the Gregorian
   'calendar (every century is a leap year in the Julian calendar)
   If y > 1600 Then temp = temp + FirstDig - 16 - ((FirstDig - 16) \ 4)
   d = d + temp
  End If
 ElseIf method = 3 Then
 ' calculate PFM date
  temp = (FirstDig - 15) \ 2 + 202 - 11 * Remain19
  Select Case FirstDig
   Case 21, 24, 25, 27 To 32, 34, 35, 38
    temp = temp - 1
   Case 33, 36, 37, 39, 40
    temp = temp - 2
  End Select        
  temp = temp Mod 30
  tA = temp + 21
  If temp = 29 Then tA = tA - 1
  If (temp = 28 And Remain19 > 10) Then tA = tA - 1
 ' find the next Sunday
  tB = (tA - 19) Mod 7
  tC = (40 - FirstDig) Mod 4
  If tC = 3 Then tC = tC + 1
  If tC > 1 Then tC = tC + 1
  temp = y Mod 100
  tD = (temp + temp \ 4) Mod 7
  tE = ((20 - tB - tC - tD) Mod 7) + 1
  d = tA + tE
 End If
' return the date
 If d > 61 Then
  d = d - 61
  m = 5       'for method 2, Easter Sunday can occur in May
 ElseIf d > 31 Then
  d = d - 31
  m = 4
 Else
  m = 3
 End If
End Function
Guarda e acquista le nostre fotografie a 1 dollaro! B2T portfolio