Last active
August 29, 2015 14:10
-
-
Save cwleonard/30618700c3b646c93c23 to your computer and use it in GitHub Desktop.
Used with the hook.io microservice framework to calculate the date of Easter for a given year.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module['exports'] = function easter(hook) { | |
var year = hook.params.year; | |
hook.debug("i am going to calculate the date of Easter for " + year); | |
// using the "Meeus/Jones/Butcher" algorithm | |
var a = year % 19; | |
var b = Math.floor(year/100); | |
var c = year % 100; | |
var d = Math.floor(b/4); | |
var e = b % 4; | |
var f = Math.floor((b + 8) / 25); | |
var g = Math.floor((b - f + 1) / 3); | |
var h = ((19*a) + b - d - g + 15) % 30; | |
var i = Math.floor (c/4); | |
var k = c % 4; | |
var L = (32 + (2*e) + (2*i) - h - k) % 7; | |
var m = Math.floor((a + (11*h) + (22*L)) / 451); | |
var month = Math.floor((h + L - (7*m) + 114) / 31); | |
var day = ((h + L - (7*m) + 114) % 31) + 1; | |
hook.debug("month is " + month); | |
hook.debug("day is " + day); | |
var monthNames = [ "January", "February", "March", "April", "May", "June", | |
"July", "August", "September", "October", "November", "December" ]; | |
hook.res.end("Easter is " + monthNames[month-1] + " " + day + " in " + year + "\n"); | |
}; | |
module['exports'].schema = { | |
"year": { | |
"type": "number" | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment