mirror of
https://github.com/System-End/YSWS-Catalog.git
synced 2026-04-19 19:55:07 +00:00
Improve date rendering for ended programs with ISO dates
This commit is contained in:
parent
aca65d5e7f
commit
b917f89b35
1 changed files with 18 additions and 4 deletions
22
script.js
22
script.js
|
|
@ -143,7 +143,7 @@ async function loadPrograms() {
|
|||
}
|
||||
}
|
||||
|
||||
function formatDeadline(deadlineStr, opensStr) {
|
||||
function formatDeadline(deadlineStr, opensStr, endedStr) {
|
||||
if (opensStr) {
|
||||
const opensDate = new Date(opensStr);
|
||||
const now = new Date();
|
||||
|
|
@ -156,6 +156,20 @@ function formatDeadline(deadlineStr, opensStr) {
|
|||
}
|
||||
}
|
||||
|
||||
if (endedStr) {
|
||||
if (endedStr.match(/^\d{4}-\d{2}-\d{2}/) || endedStr.includes('T')) {
|
||||
const endedDate = new Date(endedStr);
|
||||
if (!isNaN(endedDate.getTime())) {
|
||||
return `Ended on ${endedDate.toLocaleDateString('en-US', {
|
||||
month: 'long',
|
||||
day: 'numeric',
|
||||
year: endedDate.getFullYear() !== new Date().getFullYear() ? 'numeric' : undefined
|
||||
})}`;
|
||||
}
|
||||
}
|
||||
return endedStr;
|
||||
}
|
||||
|
||||
if (!deadlineStr) return '';
|
||||
|
||||
const deadline = new Date(deadlineStr);
|
||||
|
|
@ -200,7 +214,7 @@ function formatParticipants(name) {
|
|||
}
|
||||
|
||||
function createProgramCard(program) {
|
||||
const deadlineText = formatDeadline(program.deadline, program.opens);
|
||||
const deadlineText = formatDeadline(program.deadline, program.opens, program.ended);
|
||||
const deadlineClass = getDeadlineClass(program.deadline);
|
||||
|
||||
const opensClass = program.opens && new Date() < new Date(program.opens) ? 'opens-soon' : '';
|
||||
|
|
@ -271,7 +285,7 @@ function openModal(program) {
|
|||
program.detailedDescription || program.description;
|
||||
|
||||
const deadlineElement = modal.querySelector('.program-deadline');
|
||||
const deadlineText = formatDeadline(program.deadline, program.opens);
|
||||
const deadlineText = formatDeadline(program.deadline, program.opens, program.ended);
|
||||
const deadlineClass = getDeadlineClass(program.deadline);
|
||||
deadlineElement.className = `program-deadline ${deadlineClass}`;
|
||||
deadlineElement.textContent = deadlineText;
|
||||
|
|
@ -511,7 +525,7 @@ function updateDeadlines() {
|
|||
return;
|
||||
}
|
||||
|
||||
const deadlineText = formatDeadline(programData.deadline, programData.opens);
|
||||
const deadlineText = formatDeadline(programData.deadline, programData.opens, programData.ended);
|
||||
const deadlineClass = getDeadlineClass(programData.deadline);
|
||||
|
||||
element.textContent = deadlineText;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue