czardas Posted August 4, 2009 Share Posted August 4, 2009 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: expandcollapse popupFunc _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. expandcollapse popupFunction 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 operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
czardas Posted July 12, 2010 Author Share Posted July 12, 2010 (edited) 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 EndFuncExample:#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 July 13, 2010 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
James Posted July 13, 2010 Share Posted July 13, 2010 czardas, This would be a nice addition to Date.au3 James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 13, 2010 Moderators Share Posted July 13, 2010 czardas,I am wondering about the original code. Perhaps someone could enlighten me as to what language it isFrom 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
czardas Posted July 13, 2010 Author Share Posted July 13, 2010 czardas,This would be a nice addition to Date.au3 JamesWow, 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. Melba23I 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. operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now