#1715 closed Feature Request (Rejected)
Calculation for Easter to be added to Date.au3
| Reported by: | czardas | Owned by: | Gary |
|---|---|---|---|
| Milestone: | Component: | Standard UDFs | |
| Version: | Severity: | None | |
| Keywords: | Easter | Cc: | czardas11@… |
Description
It was suggested to me that the following UDF would make a nice addition to Date.au3
EasterHodges.au3
; #FUNCTION# ======================================================================================
; Name...........: _DateEaster
; Description ...: Calculates Easter Sunday for a given year.
; Syntax.........: _DateEaster($iYr)
; Parameters ....: $iYr - The year used to calculate Easter
; Return values .: Success - Easter in the format YYYY/MM/DD
; Failure - Returns an empty string and sets @error = 1
; Author ........: David Hodges, (conversion to AutoIt by czardas)
; Remarks .......: Applies to the revised calculation in the Gregorian calendar from 1583 to 4099 AD.
; Related .......: http://www.gmarts.org/index.php?go=415#EasterHodges
; Example .......; Yes
; ==================================================================================================
Func _DateEaster($iYr)
If StringIsInt($iYr) = 0 Or $iYr < 1583 Or $iYr > 4099 Then Return SetError(1, 0, "")
Local $iA, $iB, $iC, $iD, $iE, $iF, $iG, $iH, $iJ, $iK, $iM, $iDy, $iMth
$iA = Int($iYr / 100)
$iB = Mod($iYr, 100)
$iC = Int(3 * ($iA + 25) / 4)
$iD = Mod (3 * ($iA + 25), 4)
$iE = Int(8 * ($iA + 11) / 25)
$iF = Mod(5 * $iA + $iB, 19)
$iG = Mod((19 * $iF + $iC - $iE), 30)
$iH = Int((11 * $iG + $iF) / 319)
$iJ = Int((60 * (5 - $iD) + $iB) / 4)
$iK = Mod(60 * (5 - $iD) + $iB, 4)
$iM = Mod(2 * $iJ - $iK - $iG + $iH, 7)
$iDy = Mod($iG - $iH + $iM + 114, 31) + 1
$iMth = Int(($iG - $iH + $iM + 114) / 31)
If $iDy < 10 Then $iDy = String("0" & $iDy)
Return $iYr & "/0" & $iMth & "/" & $iDy
EndFunc
Example:
#include 'EasterHodges.au3' Local $EasterSunday = _DateEaster(@YEAR) If @error Then Exit ConsoleWrite($EasterSunday & @CRLF)
If you decide the code requires revision, I will do my best to implement any changes you suggest. If you have any other concerns, please let me know.
Attachments (0)
Change History (3)
comment:1 Changed 15 years ago by Jpm
comment:2 Changed 15 years ago by Valik
- Resolution set to Rejected
- Status changed from new to closed
Absolutely not. What general purpose does this function have to the AutoIt community at large? Why not functions to calculate other religious holidays with similar semantics? There are so many logical reasons why this should be a no.
comment:3 Changed 15 years ago by czardas
I had some reservations about making this request. Thanks for looking into it all the same.
Guidelines for posting comments:
- You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
- In-depth discussions should take place on the forum.
For more information see the full version of the ticket guidelines here.

I prefer the more general conversion with the ethos 1 to 3 from Oudin
http://www.gmarts.org/index.php?go=415#EasterOudin
I did the AutoIt adaptation and I will commit it, if you agree
; #FUNCTION# ====================================================================================== ; Name...........: _DateGetEaster ; Description ...: Calculates Easter Sunday for a given year. ; Syntax.........: _DateGetEaster($iYear [, $method = 3) ; Parameters ....: $iYear - The year used to calculate Easter ; $method - 1 Julian date ; 2 Julian to Gregorian date (Orthodox Church) ; 3 Gregorian date (Western Church). Default ; Return values .: Success - Easter in the format YYYY/MM/DD ; Failure - Returns an empty string and sets @error ; 1 Wrong $method ; 2 Year < 326 for a Julian date ; 3 Year < 1583 or Year > 4099 for a Gregorian date ; Author ........: Oudin adapted by Claus Tondering ; Remarks .......: Applies to the revised calculation in the Gregorian calendar from 326 or 1583 to 4099 AD depending on the method. ; This algorithm is adapted from a faq document by Claus Tondering ; URL: http://www.pip.dknet.dk/~pip10160/calendar.faq2.txt ; E-mail: c-t@pip.dknet.dk. ; The FAQ algorithm is based in part on the algorithm of Oudin (1940) ; as quoted in "Explanatory Supplement to the Astronomical Almanac", ; P. Kenneth Seidelmann, editor. ; Related .......: http://www.gmarts.org/index.php?go=415#EasterOudin ; Example .......; Yes ; ================================================================================================== Func _DateGetEaster($iYear, $method = 3) Local $iDay = 0 ; default values for invalid arguments Local $iMonth = 0 $iYear = Int($iYear) If $method < 1 Or $method > 3 Then Return SetError(1, 0, "") ; Method must be 1, 2 or 3 ElseIf $method = 1 And $iYear < 326 Then Return SetError(2, 0, "") ; The original calculation applies to all years from 326 AD ElseIf ($method = 2 Or $method = 3) And ($iYear < 1583 Or $iYear > 4099) Then Return SetError(3, 0, "") ; Gregorian calendar Easters apply for years 1583 to 4099 only EndIf Local $g ; golden year - 1 Local $c ; century Local $h ; = (23 - Epact) mod 30 Local $i ; no of days from March 21 to Paschal Full Moon Local $j ; weekday for PFM (0=Sunday, etc) Local $p ; no of days from March 21 to Sunday on or before PFM ; (-6 to 28 methods 1 & 3, to 56 for method 2) Local $e = 0 ; extra days to add for method 2 (converting Julian date to Gregorian date) $c = Int($iYear / 100) $g = Mod($iYear, 19) If $method = 1 Or $method = 2 Then ; old method (Julian) $i = Mod((19 * $g + 15), 30) $j = Mod($iYear + Int($iYear / 4) + $i, 7) If $method = 2 Then ; extra dates to convert Julian to Gregorian date (Orthodox Church) $e = 10 If $iYear > 1600 Then $e = $e + $c - 16 - Int(($c - 16) / 4) EndIf ElseIf $method = 3 Then ; new method (Gregorian -> Western Church) $h = Mod($c - Int($c / 4) - Int((8 * $c + 13) / 25) + 19 * $g + 15, 30) $i = $h - Int($h / 28) * (1 - Int(29 / ($h + 1)) * Int((21 - $g) / 11)) $j = Mod($iYear + Int($iYear / 4) + $i + 2 - $c + Int($c / 4), 7) EndIf ; return day and month $p = $i - $j + $e ; p can be from -6 to 56 corresponding to dates 22 March to 23 May ; (later dates apply to method 2, although 23 May never actually occurs) $iMonth = 3 + Int(($p + 26) / 30) $iDay = 1 + Mod($p + 27 + Int(($p + 6) / 40), 31) If $iDay < 10 Then $iDay = String("0" & $iDay) Return $iYear & "/0" & $iMonth & "/" & $iDay EndFunc ;==>_DateGetEaster