-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendar-2.html
182 lines (155 loc) · 7.13 KB
/
calendar-2.html
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Agricultural Calendar</title>
<style>
body {
font-family: Arial, sans-serif;
}
.calendar-container {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 80px; /* Adjusted margin to prevent overlap */
}
.controls {
position: fixed;
top: 20px;
left: 50%;
transform: translateX(-50%);
margin-bottom: 20px;
background-color: #fff;
padding: 10px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
z-index: 1000;
}
.month {
border: 1px solid #333;
padding: 15px;
margin: 10px;
width: 300px;
}
.day-range, .special-day {
font-weight: bold;
color: #00509E;
}
.special-day {
color: #FF5733;
}
.month h2 {
margin: 0;
font-size: 18px;
}
.day {
margin: 10px 0; /* Adjust margin for spacing between dates */
}
#print-button {
margin-top: 20px;
}
</style>
</head>
<body>
<div class="calendar-container">
<div class="controls">
<button id="prevYear">Previous Year</button>
<button id="nextYear">Next Year</button>
<button id="repeatYear">Skip to a Repeated Year</button>
<span id="yearDisplay"></span>
</div>
<div id="calendar"></div>
<button id="print-button" onclick="printCalendar()">Print Calendar</button>
</div>
<script>
const monthNames = [
{ name: "Primavera", days: 37, specialDays: { 1: "New Year's Day", 21: "Philoson" } },
{ name: "Floralis", days: 38 },
{ name: "Aestivalis", days: 37, specialDays: { 2: "Hiemsol", 35: "Tax Day", 34: "Ventussaccus", 26: "Start Threshing", 24: "Scythings" } },
{ name: "Restorare", days: 38 },
{ name: "Revitalis", days: 37 },
{ name: "Nutrientia", days: 38, specialDays: { 5: "Anthotides", 35: "Tax Day", 34: "Cytisum", 32: "Scythings" } },
{ name: "Fructalis", days: 37, specialDays: { 21: "Anthoson" } },
{ name: "Recolere", days: 38, specialDays: { 21: "Aestasol" } },
{ name: "Hypoxis", days: 37, specialDays: { 35: "Tax Day", 34: "Anemoisakos", 26: "Start Threshing", 24: "Scythings" } },
];
const holidays = {
Hiemsol: { day: 2, month: 3 }, // 2nd day of Aestivalis
Anthotides: { day: 5, month: 6 }, // 5th day of Nutrientia
Anthoson: { day: 21, month: 7 }, // 21st day of Fructalis
Aestasol: { day: 21, month: 8 }, // 21st day of Recolere
Philoson: { day: 21, month: 1 } // 21st day of Primavera
};
// Store the calculated New Year's Day for each agricultural year
let newYearDates = [];
// Calculate the start date for each agricultural year dynamically
function calculateNewYearDates(startingYear) {
let previousEnd = new Date(2025, 2, 24); // 25th day of March, 2025 for Year 1
newYearDates = [new Date(previousEnd.getTime() + 24 * 60 * 60 * 1000)]; // New Year is the day after the previous year's end
for (let i = 1; i < startingYear; i++) {
let totalDays = monthNames.reduce((acc, month) => acc + month.days, 0);
previousEnd = new Date(previousEnd.getTime() + totalDays * 24 * 60 * 60 * 1000);
newYearDates.push(new Date(previousEnd.getTime() + 24 * 60 * 60 * 1000)); // New Year is the day after the previous year's end
}
}
let currentYear = 1;
function displayCalendar(agriculturalYear) {
const calendarDiv = document.getElementById('calendar');
calendarDiv.innerHTML = '';
const yearDisplay = document.getElementById('yearDisplay');
const gregorianYear = 2025 + (agriculturalYear - 1);
yearDisplay.innerText = `Agricultural Year: ${agriculturalYear}, Gregorian Year: ${gregorianYear}`;
let newYearDate = newYearDates[agriculturalYear - 1];
monthNames.forEach((month) => {
const monthDiv = document.createElement('div');
monthDiv.className = 'month';
monthDiv.innerHTML = `<h2>${month.name} (Year ${agriculturalYear})</h2>`;
for (let day = 1; day <= month.days; day++) {
const dayDiv = document.createElement('div');
dayDiv.className = 'day';
// Prepare output for the agricultural day
const agriculturalDay = `${day}th day of ${month.name}, Year ${agriculturalYear}`;
let gregorianStartDay = calculateGregorianDate(agriculturalYear, day, monthNames.indexOf(month) + 1); // Convert to Gregorian date
const gregorianDayString = `${['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'][gregorianStartDay.getDay()]}, ${gregorianStartDay.getDate()}th day of ${gregorianStartDay.toLocaleString('default', { month: 'long' })}, ${gregorianStartDay.getFullYear()}`;
dayDiv.innerHTML = `${agriculturalDay} (Gregorian: ${gregorianDayString})`;
// Handle special days
if (month.specialDays && month.specialDays[day]) {
dayDiv.innerHTML = `<span class="special-day">${agriculturalDay}: ${month.specialDays[day]} (Gregorian: ${gregorianDayString})</span>`;
}
// Check for holidays
for (const holiday in holidays) {
const holidayInfo = holidays[holiday];
if (holidayInfo.day === day && monthNames.indexOf(month) + 1 === holidayInfo.month) {
dayDiv.innerHTML = `<span class="special-day">${agriculturalDay}: ${holiday} (Gregorian: ${gregorianDayString})</span>`;
}
}
monthDiv.appendChild(dayDiv);
}
calendarDiv.appendChild(monthDiv);
});
}
function calculateGregorianDate(agriculturalYear, day, month) {
let newYearDate = newYearDates[agriculturalYear - 1];
let gregorianDate = new Date(newYearDate);
let totalDays = monthNames.reduce((acc, m) => acc + m.days, 0);
let agriculturalDaysPassed = monthNames.slice(0, month - 1).reduce((acc, m) => acc + m.days, 0) + day - 1; // subtract 1 to include current day
// Calculate the Gregorian date
gregorianDate.setDate(newYearDate.getDate() + agriculturalDaysPassed);
return gregorianDate;
}
document.getElementById('prevYear').addEventListener('click', () => {
currentYear--;
displayCalendar(currentYear);
});
document.getElementById('nextYear').addEventListener('click', () => {
currentYear++;
displayCalendar(currentYear);
});
document.getElementById('repeatYear').addEventListener('click', () => {
// Implement logic for skipping to a repeated year if needed
});
calculateNewYearDates(10); // Set how many years to calculate
displayCalendar(currentYear);
</script>
</body>
</html>