dws_wielkanoc/index.js

70 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2024-09-19 07:10:24 +02:00
function isNaturalNumber (str) {
var pattern = /^(0|([1-9]\d*))$/;
return pattern.test(str);
}
function calculate(){
let year = document.getElementById("year").value;
if (isNaturalNumber(year) == false){
document.getElementById("result").textContent = "Błąd. Podano nieodpowiedni ciąg znaków!"
}
else if (year < 1900 || year > 2099){
document.getElementById("result").textContent = "Błąd. Podano rok spoza zakresu 1900-2099!"
}
else{
let a, b, c, d, e, p, q, month;
p = 24;
q = 5;
month = 3;
a = year % 19;
b = year % 4;
c = year % 7;
d = ((19 * a) + p) % 30;
e = ((2 * b) + (4 * c) + (6 * d) + q) % 7;
result = d + e + 22;
if (result > 31){
result = result - 31;
month += 1;
}
if (result > 25 && month == 4){
result = result - 7;
}
document.getElementById("result").textContent = `Data wielkanocy: ${result}.0${month}.${year}`;
}
}
// d
// function calculate() {
// let year = document.getElementById("year").value;
// if (isNaturalNumber(year) == false) {
// document.getElementById("result").textContent = "Błąd. Podano nieodpowiedni ciąg znaków!"
// }
// else if (year < 1 || year > 5000) {
// document.getElementById("result").textContent = "Błąd. Podano rok spoza zakresu 1-5000!"
// }
// else {
// let a, b, c, d, e, f, g, h, i, k, l, m, month, day;
// a = year % 19;
// b = Math.floor(year / 100);
// c = year % 100;
// d = Math.floor(b / 4);
// e = b % 4;
// f = Math.floor((b + 8) / 25);
// g = Math.floor((b - f + 1) / 3);
// h = (19 * a + b - d - g + 15) % 30;
// i = Math.floor(c / 4);
// k = c % 4;
// l = (32 + 2 * e + 2 * i - h - k) % 7;
// m = Math.floor((a + 11 * h + 22 * l) / 451);
// month = Math.floor((h + l - 7 * m + 114) / 31);
// day = ((h + l - 7 * m + 114) % 31) + 1;
// document.getElementById("result").textContent = `Data wielkanocy: ${day.toString().padStart(2, '0')}.${month.toString().padStart(2, '0')}.${year}`;
// }
// }