рони,
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE=edge'>
<title>Page Title</title>
<meta name='viewport' content='width=device-width, initial-scale=1'>
</head>
<body>
<style>
#hollyday>div {
background-color: #ececec;
text-align: center;
border: 1px solid #999;
padding: 20px;
color: #f00;
font: bold 24px serif;
}
</style>
<div id="hollyday">
</div>
<script>
var fixDates = [
{ month: 3, day: 8, hour: 8, duration: 12, compliments: "С 8 марта" },
{ month: 3, day: 9, hour: 12, duration: 2, compliments: "Поздравление с Днем счастливых!" },
{ month: 4, day: 11, hour: 8, duration: 12, compliments: "С днём космонавтики !" },
{ month: 4, day: 30, hour: 12, duration: 2, compliments: "с 30 апреля! " },
{ month: 5, day: 1, hour: 0, duration: 48, compliments: "С 1 мая !" },
{ month: 5, day: 9, hour: 12, duration: 2, compliments: "С 9 мая !" }
];
function catholicDate(year)
{
var a = year % 19;
var b = year % 4;
var c = year % 7;
var k = Math.floor(year / 100);
var p = Math.floor((13 + 8 * k) / 25);
var q = Math.floor(k / 4);
var m = (15 - p + k - q) % 30;
var n = (4 + k - q) % 7;
var d = (19 * a + m) % 30;
var e = (2 * b + 4 * c + 6 * d + n) % 7;
if (d === 29 && e === 6)
return new Date(year, 3, 19);
if (d === 28 && e === 6 && ((11 * m + 11) % 30 < 19))
return new Date(year, 3, 18);
if (d + e > 9)
return new Date(year, 3, d + e - 9);
else
return new Date(year, 2, 22 + d + e);
}
function orthodoxDate(year)
{
var a = year % 19;
var b = year % 4;
var c = year % 7;
var d = (19 * a + 15) % 30;
var e = (2 * b + 4 * c + 6 * d + 6) % 7;
var f = d + e;
return f <= 26
? new Date(year, 3, 4 + f)
: new Date(year, 4, f - 26);
}
function getActualCompliments()
{
var now = new Date( "11 May 2021 00:00:00:001" ); // кат.пасха "4 April 2021 00:00:00:001", прав.пасха "2 May 2021 00:00:00:001", радуница "11 May 2021 00:00:00:001", троица "20 June 2021 00:00:00:001"
var result = fixDates.filter(v =>
{
var currentDate = new Date(now.getFullYear(), v.month - 1, v.day, v.hour);
var durms = v.duration * 3600000;
console.log(now, currentDate, (now - currentDate) / 3600000);
var rg = now - currentDate;
return rg <= durms && rg >= 0;
}).map(v => v.compliments);
var caholic = catholicDate(now.getFullYear());
var ortodox = orthodoxDate(now.getFullYear());
if (caholic.getMonth() == now.getMonth() && caholic.getDate() == now.getDate())
result.push("С католической пасхой!");
if (ortodox.getMonth() == now.getMonth() && ortodox.getDate() == now.getDate())
result.push("С православной пасхой!");
var trinity = new Date(ortodox);
trinity.setDate(trinity.getDate() + 49);
if (trinity.getMonth() == now.getMonth() && trinity.getDate() == now.getDate())
result.push("С троицей!");
var radunitsa = new Date(ortodox);
radunitsa.setDate(trinity.getDate() + 9);
if (radunitsa.getMonth() == now.getMonth() && radunitsa.getDate() == now.getDate())
result.push("С радуницей !");
return result;
}
var actualCompliments = getActualCompliments();
console.log(actualCompliments);
if (actualCompliments.length > 0)
{
var hollyday = document.getElementById("hollyday");
hollyday.style.display = "block";
for (var c of actualCompliments)
{
var div = document.createElement("div");
hollyday.appendChild(div);
div.innerHTML = c;
}
}
function foo(month, day, compliment, hour = 0)
{
return { month: month, day: day, hour: hour, compliment: compliment }
}
var now9 = new Date();
now9.setDate(now9.getDate() + 9);
console.log(now9);
var now49 = new Date();
now49.setDate(now49.getDate() + 49);
console.log(now49);
</script>
</body>
</html>
если в этом скрипте в 75 строке указать другие даты из комментария к этой строке (после //), то три даты показывает а одну нет, как это исправить?