Created
April 16, 2023 17:44
-
-
Save alogic0/9ddb5f744feca0797a5415dbb57c135b to your computer and use it in GitHub Desktop.
Orthodox Easter Calculator
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Orthodox Easter Calculator</title> | |
</head> | |
<body> | |
<h1>Orthodox Easter Calculator</h1> | |
<p>Enter a year and see the year day for Orthodox Easter using Gauss formula.</p> | |
<label for="year">Year:</label> | |
<input type="number" id="year" min="0" max="9999"> | |
<button id="button">Calculate</button> | |
<p id="result">0</p> | |
<script> | |
// return difference in days between Julian and Gregorian calendars | |
const months = [ | |
"January", "February", "March", "April", | |
"May", "June", "July", "August", | |
"September", "October", "November", "December", | |
]; | |
function j2g(year) { | |
return year < 1500 ? 0 : 10 + Math.floor(year / 100 - 16) - Math.floor((year / 100 - 16) / 4); | |
} | |
function isLeapYear(y) { | |
return ((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0); | |
} | |
function paskha(year) { | |
let dt = { | |
month:"", | |
day:0, | |
}; | |
let a = year % 19; | |
let b = year % 4; | |
let c = year % 7; | |
let d = (19 * a + 15) % 30; | |
let e = (2 * b + 4 * c + 6 * d + 6) % 7; | |
let cumday = isLeapYear(year) ? [0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335] : [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334]; | |
let i = 0; | |
dayOfYear = cumday[2] + 22 + d + e + j2g(year); | |
while (cumday[i] < dayOfYear) { | |
i+=1; | |
} | |
dt.month = months[i-1]; | |
dt.day = dayOfYear - cumday[i-1]; | |
return dt; | |
} | |
// get the input element by id | |
var input = document.getElementById("year"); | |
// get the button element by id | |
var button = document.getElementById("button"); | |
// add an event listener to handle button click | |
button.addEventListener("click", function() { | |
// get the input value as a number | |
var year = Number(input.value); | |
// check if the input is a valid year | |
if (isNaN(year) || year < 0 || year > 9999) { | |
// display an error message | |
document.getElementById("result").innerHTML = "Please enter a valid year between 0 and 9999."; | |
return; | |
} | |
// calculate the year day for Orthodox Easter | |
var dt = paskha(year); | |
// display the result | |
document.getElementById("result").innerHTML = "The year day for Orthodox Easter in " + year + " is " + | |
dt.month + " " + dt.day + "."; | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment