-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
91 lines (82 loc) · 3.37 KB
/
app.js
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
document.getElementById('print').addEventListener('click', function() {
const year = document.getElementById('year').value;
const month = document.getElementById('month').value;
const holidayArea = document.getElementById('holidayArea').value;
const resultDiv = document.getElementById('result');
resultDiv.innerHTML = ''; // Clear previous results
const holidays = {
'lisbon': {
'1/1': 'New Year\'s Day',
'2/13': 'Carnival',
'3/29': 'Good Friday',
'4/25': 'Freedom Day',
'5/1': 'Labour Day',
'5/30': 'Corpus Christi',
'6/10': 'Portugal Day',
'6/13': 'Saint Anthony\'s Day',
'8/15': 'Assumption of Mary',
'11/1': 'All Saints\' Day',
'12/25': 'Christmas Day',
},
'setubal': {
'1/1': 'New Year\'s Day',
'2/13': 'Carnival',
'3/29': 'Good Friday',
'4/25': 'Freedom Day',
'5/1': 'Labour Day',
'5/30': 'Corpus Christi',
'6/10': 'Portugal Day',
'8/15': 'Assumption of Mary',
'11/1': 'All Saints\' Day',
'12/25': 'Christmas Day',
// Specific for Setubal
'9/15': 'Bocage Day',
}
};
// Helper function to check if a date is a weekend
function isWeekend(date) {
return date.getDay() === 0 || date.getDay() === 6; // Sunday = 0, Saturday = 6
}
// Generate dates for the selected month
const daysInMonth = new Date(year, month, 0).getDate();
for (let day = 1; day <= daysInMonth; day++) {
const date = new Date(year, month - 1, day); // JS months start at 0
const dateFormat = `${('0' + day).slice(-2)}-${('0' + month).slice(-2)}-${year}`;
const weekDay = date.toLocaleString('en-US', { weekday: 'long' });
let label = `${weekDay}, ${dateFormat}`;
if (isWeekend(date)) {
label += ' (weekend)';
} else if (holidays[holidayArea][`${month}/${day}`]) {
label += ' (holiday!)';
}
resultDiv.innerHTML += `<div>${label}</div>`;
}
// Copy results to clipboard
const resultText = resultDiv.innerText;
navigator.clipboard.writeText(resultText).then(() => {
console.log('Results copied to clipboard!');
}).catch(err => {
console.error('Failed to copy results: ', err);
});
});
document.addEventListener('DOMContentLoaded', function() {
const now = new Date();
const currentYear = now.getFullYear();
const currentMonth = now.getMonth() + 1; // JavaScript months are 0-indexed
// Populate year dropdown dynamically or set the current year as selected
const yearSelect = document.getElementById('year');
for (let year = currentYear; year <= currentYear + 5; year++) { // Example range: current year to current year + 5
const option = document.createElement('option');
option.value = year;
option.text = year;
option.selected = year === currentYear;
yearSelect.appendChild(option);
}
// Set the current month as selected
const monthSelect = document.getElementById('month');
monthSelect.value = currentMonth;
// Your existing code to handle the "PRINT" button click...
document.getElementById('print').addEventListener('click', function() {
// Existing functionality...
});
});