-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
181 lines (175 loc) · 5.62 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Since</title>
<!-- favicons -->
<link rel="icon" href="/images/favicon/favicon-32.png" sizes="32x32">
<link rel="icon" href="/images/favicon/favicon-128.png" sizes="128x128">
<link rel="icon" href="/images/favicon/favicon-192.png" sizes="192x192">
<!-- Android -->
<link rel="shortcut icon" sizes="196x196" href="/images/favicon/favicon-196.png">
<!-- iOS -->
<link rel="apple-touch-icon" href="/images/favicon/favicon-152.png" sizes="152x152">
<link rel="apple-touch-icon" href="/images/favicon/favicon-180.png" sizes="180x180">
<style>
* {
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
color: #555;
line-height: 1.5
}
body, html {
background-color: #ffffff;
}
.text-center {
text-align: center;
}
h1 {
font-weight: 900;
font-size: 25px;
padding: 15px;
}
.calendar {
width: 75px;
box-shadow: 0px 0px 2px 1px rgba(50, 50, 50, 0.2);
border-radius: 9px;
margin: 0 auto;
text-align: center;
}
.calendar-top {
background: linear-gradient(#ff655c, #eb554d);
border-top-left-radius: 9px;
border-top-right-radius: 9px;
color: #ffffff;
font-weight: 700;
margin: 0;
}
.calendar-bottom {
border-bottom-left-radius: 9px;
border-bottom-right-radius: 9px;
background: linear-gradient(#ffffff, #f5f3ef);
font-weight: 900;
font-size: 200%;
margin: 0;
color: #555;
}
footer {
position: fixed;
bottom: 0;
text-align: center;
color: #555;
font-size: 14px;
width: 100%;
height: 50px;
line-height: 20px;
font-weight: 200;
}
footer a, footer a:visited, footer a:hover {
color: inherit;
}
footer span {
font-size: 20px;
}
@media (prefers-color-scheme: dark) {
* {
color: #ffffff;
}
body, html {
background-color: #1d2229;
}
.calendar {
box-shadow: none;
}
}
</style>
</head>
<body>
<h1 class="text-center"><span id="dateDisplay"></span></h1>
<p class="text-center">Since</p>
<div class="calendar">
<p class="calendar-top">Jul</p>
<p class="calendar-bottom">26</p>
</div>
<p class="text-center">2021</p>
<footer>Made by <a href="https://www.jamerampton.uk">James</a> with <span class="x2">☕️</span></footer>
<script>
function dateDiff(startingDate, endingDate) {
var startDate = new Date(new Date(startingDate).toISOString().substr(0, 10));
if (!endingDate) {
endingDate = new Date().toISOString().substr(0, 10); // need date in YYYY-MM-DD format
}
var endDate = new Date(endingDate);
if (startDate > endDate) {
var swap = startDate;
startDate = endDate;
endDate = swap;
}
var startYear = startDate.getFullYear();
var february = (startYear % 4 === 0 && startYear % 100 !== 0) || startYear % 400 === 0 ? 29 : 28;
var daysInMonth = [31, february, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var yearDiff = endDate.getFullYear() - startYear;
var monthDiff = endDate.getMonth() - startDate.getMonth();
if (monthDiff < 0) {
yearDiff--;
monthDiff += 12;
}
var dayDiff = endDate.getDate() - startDate.getDate();
if (dayDiff < 0) {
if (monthDiff > 0) {
monthDiff--;
} else {
yearDiff--;
monthDiff = 11;
}
dayDiff += daysInMonth[startDate.getMonth()];
}
var weekDiff = parseInt(dayDiff / 7)
dayDiff = dayDiff - (weekDiff * 7);
return {
'years': yearDiff,
'months': monthDiff,
'weeks': weekDiff,
'days': dayDiff
}
}
function pluralise(string, num) {
var suffix = ""
if (num === 0 || num > 1){
suffix = "s"
}
return string + suffix;
}
function updateDisplay(){
var el = document.getElementById('dateDisplay');
var fromDate = '2021-07-26';
var since = dateDiff(fromDate);
var output = "";
var parts = [];
if (since.years) {
parts.push(since.years + pluralise(" year", since.years))
}
if (since.months) {
parts.push(since.months + pluralise(" month", since.months))
}
// Don't show weeks if more than 6 months
if (since.months < 6 && since.weeks) {
parts.push(since.weeks + pluralise(" week", since.weeks))
}
// Don't show days if more than 3 months
if (since.months < 3 && since.days) {
parts.push(since.days + pluralise(" day", since.days))
}
for( var i=0; i<parts.length; i++ ) {
output += parts[i];
if ( i < parts.length-1 ) {
output += ", ";
}
}
el.innerHTML = output;
setTimeout(updateDisplay, 5000);
}
updateDisplay();
</script>
</body>
</html>