forked from iaeiou/calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalendar.php
More file actions
247 lines (230 loc) · 6.28 KB
/
calendar.php
File metadata and controls
247 lines (230 loc) · 6.28 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
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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
<!--
MIT License
Copyright (c) 2022 Neatnik LLC
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Calendar</title>
<meta property="og:title" content="Calendar">
<meta property="og:url" content="https://neatnik.net/calendar">
<meta property="og:description" content="A simple printable calendar with the full year on a single page">
<style>
@import url('https://fonts.googleapis.com/css2?family=Oswald:wght@300;400&display=swap');
@import url('https://rsms.me/inter/inter.css');
@media print {
#info {
display: none;
}
}
html {
font-family: 'Oswald';
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
table {
width: 100%;
height: calc(100% - 2.5em);
border-collapse: separate;
border-spacing: .5em 0;
}
td, th {
font-weight: normal;
text-transform: uppercase;
border-bottom: 1px solid #888;
padding: .3vmin .3vmin;
font-size: .9vmin;
font-weight: 300;
color: #000;
}
th {
font-size: 1.1vmin;
padding: 0;
}
td:empty {
border: 0;
}
.date {
display: inline-block;
width: 1.1em;
}
.day {
display: inline-block;
text-align: center;
width: 1em;
color: #888;
}
.weekend {
background: #eee;
font-weight: 400;
}
p {
margin: 0 0 .5em 0;
text-align: center;
}
* {
color-adjust: exact;
-webkit-print-color-adjust: exact;
}
#info {
font-family: 'Inter', sans-serif;
position: absolute;
top: 0;
left: 0;
margin: 5em 2em;
width: calc(100% - 6em);
background: #333;
color: #eee;
padding: 1em 1em .5em 1em;
font-size: 2vmax;
border-radius: .2em;
}
#info p {
text-align: left;
margin: 0 0 1em 0;
line-height: 135%;
}
#info a {
color: inherit;
}
</style>
</head>
<body>
<div id="info">
<p>👋 <strong>Hello!</strong> If you print this page, you’ll get a nifty calendar that displays all of the year’s dates on a single page. It will automatically fit on a single sheet of paper of any size. For best results, adjust your print settings to landscape orientation and disable the header and footer.</p>
<p>Take in the year all at once. Fold it up and carry it with you. Jot down your notes on it. Plan things out and observe the passage of time. Above all else, be kind to others.</p>
<p style="font-size: 80%; color: #999;">Made by <a href="https://neatnik.net/">Neatnik</a> · Source on <a href="https://github.com/neatnik/calendar">GitHub</a></p>
</div>
<?php
date_default_timezone_set('UTC');
$now = isset($_REQUEST['year']) ? strtotime($_REQUEST['year'].'-01-01') : time();
$dates = array();
$month = 1;
$day = 1;
echo '<p>'.date('Y', $now).'</p>';
echo '<table>';
echo '<thead>';
echo '<tr>';
// Add the month headings
for($i = 1; $i <= 12; $i++) {
echo '<th>'.DateTime::createFromFormat('!m', $i)->format('M').'</th>';
}
echo '</tr>';
echo '</thead>';
echo '<tbody>';
// Prepare a list of the first weekdays for each month of the year
$date = strtotime(date('Y', $now).'-01-01');
$first_weekdays = array();
for($x = 1; $x <= 12; $x++) {
$first_weekdays[$x] = date('N', strtotime(date('Y', $now).'-'.$x.'-01'));
$$x = false; // Set a flag for each month so we can track first days below
}
// Start the loop around 12 months
while($month <= 12) {
$day = 1;
for($x = 1; $x <= 42; $x++) {
if(!$$month) {
if($first_weekdays[$month] == $x) {
$dates[$month][$x] = $day;
$day++;
$$month = true;
}
else {
$dates[$month][$x] = 0;
}
}
else {
// Ensure that we have a valid date
if($day > cal_days_in_month(CAL_GREGORIAN, $month, date('Y', $now))) {
$dates[$month][$x] = 0;
}
else {
$dates[$month][$x] = $day;
}
$day++;
}
}
$month++;
}
// Now produce the table
$month = 1;
$day = 1;
if(isset($_REQUEST['layout']) && $_REQUEST['layout'] == 'aligned-weekdays') {
// Start the outer loop around 42 days (6 weeks at 7 days each)
while($day <= 42) {
echo '<tr>';
// Start the inner loop around 12 months
while($month <= 12) {
if($dates[$month][$day] == 0) {
echo '<td></td>';
}
else {
$date = date('Y', $now).'-'.str_pad($month, 2, '0', STR_PAD_LEFT).'-'.str_pad($dates[$month][$day], 2, '0', STR_PAD_LEFT);
if(date('N', strtotime($date)) == '7') {
echo '<td class="weekend">';
}
else {
echo '<td>';
}
echo $dates[$month][$day];
echo '</td>';
}
$month++;
}
echo '</tr>';
$month = 1;
$day++;
}
}
else {
// Start the outer loop around 31 days
while($day <= 31) {
echo '<tr>';
// Start the inner loop around 12 months
while($month <= 12) {
// If we’ve reached a point in the date matrix where the resulting date would be invalid (e.g. February 30th), leave the cell blank
if($day > cal_days_in_month(CAL_GREGORIAN, $month, date('Y', $now))) {
echo '<td></td>';
$month++;
continue;
}
// If the day falls on a weekend, apply a specific class for styles
if(DateTime::createFromFormat('!Y-m-d', date('Y', $now).'-'.$month.'-'.$day)->format('N') == 6 || DateTime::createFromFormat('!Y-m-d', date('Y', $now).'-'.$month.'-'.$day)->format('N') == 7) {
echo '<td class="weekend">';
}
else {
echo '<td>';
}
// Display the day number and day of the week
echo '<span class="date">'.$day.'</span> <span class="day">'.substr(DateTime::createFromFormat('!Y-m-d', date('Y', $now).'-'.$month.'-'.$day)->format('D'), 0, 1).'</span>';
echo '</td>';
$month++;
}
echo '</tr>';
$month = 1;
$day++;
}
}
?>
</tbody>
</table>
</body>
</html>