Repository navigation
Expand file tree
/
Copy pathcalendar.js
More file actions
55 lines (45 loc) · 1.79 KB
/
Copy pathcalendar.js
File metadata and controls
55 lines (45 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Calendar and Deadline Utilities
document.addEventListener('DOMContentLoaded', function() {
// Update timestamps
function updateTime() {
const now = new Date();
const timeString = now.toLocaleTimeString();
const timeDisplays = document.querySelectorAll('.update-msg');
timeDisplays.forEach(display => {
if (display) {
display.textContent = `Last updated: ${timeString}`;
}
});
}
// Calculate days between dates
function getDaysBetween(date1, date2) {
const oneDay = 24 * 60 * 60 * 1000; // hours*minutes*seconds*milliseconds
const diffDays = Math.round(Math.abs((date1 - date2) / oneDay));
return diffDays;
}
// Update deadlines with gap information
function updateDeadlines() {
const listItems = document.querySelectorAll('.list-item');
const now = new Date();
listItems.forEach(item => {
const deadlineText = item.querySelector('.list-item-secondary').textContent;
const deadlineDate = new Date(deadlineText.replace('Due: ', ''));
const daysGap = getDaysBetween(now, deadlineDate);
const gapInfo = document.createElement('div');
gapInfo.className = 'deadline-gap';
gapInfo.textContent = `${daysGap} days remaining`;
// Remove existing gap info if any
const existingGap = item.querySelector('.deadline-gap');
if (existingGap) {
existingGap.remove();
}
item.appendChild(gapInfo);
});
}
// Update time every minute
setInterval(updateTime, 60000);
updateTime();
// Update deadlines initially and every hour
updateDeadlines();
setInterval(updateDeadlines, 3600000);
});