# EasterHodges

## Recommended Posts

Although the following code didn't require much modification, I still think it's interesting and worth sharing.

I can't remember where I found the original.

AutoIt Version:

```Func _easter()

\$a = \$yyyy / 100
\$a = Int(\$a)

\$b = Mod(\$yyyy, 100)

\$c = \$a + 25
\$c = 3 * \$c / 4
\$c = Int(\$c)

\$d = \$a + 25
\$d = Mod (3 * \$d, 4)

\$e = \$a + 11
\$e = 8 * \$e / 25
\$e = Int(\$e)

\$f = 5 * \$a
\$f = Mod(\$f + \$b, 19)

\$g = 19 * \$f + \$c - \$e
\$g = Mod(\$g, 30)

\$h = 11 * \$g + \$f
\$h = \$h / 319
\$h = Int(\$h)

\$j = 5 - \$d
\$j = 60 * \$j + \$b
\$j = \$j / 4
\$j = Int(\$j)

\$k = 5 - \$d
\$k = Mod(60 *\$k + \$b, 4)

\$m = Mod(2 * \$j - \$k - \$g + \$h, 7)

\$n = \$g - \$h + \$m + 114
\$n = \$n / 31
\$n = Int(\$n)

\$p = Mod(\$g - \$h + \$m + 114, 31)

\$dy = \$p + 1
\$mth = \$n

EndFunc```

Original version by David Hodges:

Accurate from 1583 to 4099 in the Gregorian calendar.

```Function EasterHodges(dy, mth, ByVal y, ByVal method) As Boolean

'by David Hodges, derived by refining the "Butcher's Ecclesiastical Calendar" rule
'eliminating one step in the process

Dim a, b, c, d, e, f, g, h, j, k, m, n, p

' Validate arguments
If method <> 3 Or y < 1583 Or y > 4099 Then
EasterHodges = False
d = 0
m = 0
MsgBox "Hodges method only applies to the revised calculation in the Gregorian calendar from 1583 to 4099 AD"
Exit Function
End If

EasterHodges = True

a = y \ 100
b = y Mod 100

c = (3 * (a + 25)) \ 4
d = (3 * (a + 25)) Mod 4

e = (8 * (a + 11)) \ 25

f = (5 * a + b) Mod 19

g = (19 * f + c - e) Mod 30

h = (f + 11 * g) \ 319

j = (60 * (5 - d) + b) \ 4
k = (60 * (5 - d) + b) Mod 4

m = (2 * j - k - g + h) Mod 7

n = (g - h + m + 114) \ 31
p = (g - h + m + 114) Mod 31

dy = p + 1
mth = n

'Easter Sunday is g - h + m days after March 22nd
'(the earliest possible Easter date)

End Function```

##### Share on other sites

I needed some simple code to practice creating a UDF. So I modified the code above. The UDF could be useful to someone making a calander or something. Does this conform to standard syntax?

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)```

I am wondering about the original code. Perhaps someone could enlighten me as to what language it is. I'm not sure: because there isn't so much to go on.

Edited by czardas

##### Share on other sites

czardas,

This would be a nice addition to Date.au3

James

##### Share on other sites

czardas,

I am wondering about the original code. Perhaps someone could enlighten me as to what language it is

From the page you linked to:

And Finally - The Code!

You can cut and paste the code below. Most code is in Visual Basic, however, there are also implementations for C, Delphi (object Pascal) Javascript (or ECMA Script) and Matlab.

M23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

##### Share on other sites

czardas,

This would be a nice addition to Date.au3

James

Wow, that would be something. I have only just figured out how to create a UDF. This algorithm by David Hodges seemed to be the most straight forward, compaired to some of the other methods from the same page. I used it for a simple calendar I made a while back.

Melba23

I thought it was visual basic, but wasn't sure. I think several languages use similar syntax and I am only really familiar with AutoIt and a bit of javascript. Thanks.

## Create an account

Register a new account

×

• Wiki

• Back

• Git