Feedback

VB - Berechnung des Datums des Ostersonntags

Veröffentlicht von am 11/26/2007
(3 Bewertungen)
Diese Funktion berechnet zu einem gegebenen Jahr (year) das Datum des Ostersonntags und gibt es als DateTime zurück.
Daraus können dann alle anderen von Ostern abhängigen Feiertage berechnet werden:

Rosenmontag: -48 Tage
Faschingsdienstag: -47 Tage
Aschermittwoch: -46 Tage
Gründonnerstag: -3 Tage
Karfreitag: -2 Tage
Karsamstag: -1 Tag
Ostermontag: +1 Tag
Christi Himmelfahrt: + 39 Tage
Pfingstsonntag: +49 Tage
Pfingstmontag: +50 Tage
Fronleichnam: +60 Tage
  ''' <summary>
  ''' caclulates date of easter sunday in given year
  ''' </summary>
  ''' <param name="year">year date has to be in</param>
  ''' <returns>date of easter sunday</returns>
  Public Shared Function Easter(ByVal year As Integer) As DateTime
    Dim _month As Integer
    Dim _day As Integer
    Dim _moon As Integer
    Dim _epact As Integer
    Dim _sunday As Integer
    Dim _gold As Integer
    Dim _century As Integer
    Dim _corx As Integer
    Dim _corz As Integer
    ' The Golden Number of the year in the 19 year Metonic Cycle: 
    _gold = (year Mod 19) + 1
    ' Calculate the Century:
    _century = (year \ 100) + 1
    ' Number of years in which leap year was dropped in order
    ' to keep in step with the sun:
    _corx = (3 * _century) \ 4 - 12
    ' Special correction to syncronize Easter with moon's orbit:
    _corz = (8 * _century + 5) \ 25 - 5
    ' Find Sunday:
    _sunday = (5 * year) \ 4 - _corx - 10
    ' ^ evtl. long To prevent overflow at year 6554
    ' Set Epact - specifies occurrence of full moon:
    _epact = (11 * _gold + 20 + _corz - _corx) Mod 30
    If _epact < 0 Then
      _epact += 30
    End If
    If (((_epact = 25) AndAlso (_gold > 11)) OrElse (_epact = 24)) Then
      _epact += 1
    End If
    ' Find Full Moon:
    _moon = 44 - _epact
    If _moon < 21 Then
      _moon += 30
    End If
    ' Advance to Sunday:
    _moon += 7 - ((_sunday + _moon) Mod 7)
    If (_moon > 31) Then
      _month = 4
      _day = _moon - 31
    Else
      _month = 3
      _day = _moon
    End If
    Return New DateTime(year, _month, _day)
  End Function


Kommentare zum Snippet

 

Logge dich ein, um hier zu kommentieren!