Used with the hook.io microservice framework to calculate the date of Easter for a given year.
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