-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.html
240 lines (220 loc) · 7.44 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
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
<!doctype html>
<html>
<head>
<title>Are we reorganized yet?</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<style>
body {
background-color: black;
color: white;
margin: 0;
}
h1, h2 {
text-align: center;
}
h1 {
font-family: 'Comic Sans MS';
font-size: 30vw;
margin: 0;
}
ul {
list-style-type: none;
margin: 0;
padding: 1em;
}
ul li {
text-decoration: line-through;
}
ul li:first-child {
text-decoration: none;
}
.vbox {
display: -webkit-flex;
display: flex;
-webkit-flex-direction: column;
flex-direction: column;
min-height: 100vh;
}
.flex {
-webkit-flex: 1;
flex: 1;
display: -webkit-flex;
display: flex;
-webkit-align-items: center;
align-items: center;
-webkit-justify-content: center;
justify-content: center;
}
</style>
</head>
<body class="vbox">
<h1 id="answer" class="flex">WAIT</h1>
<h2>Days since last reorg: <strong id="last-reorg-days"></strong></h2>
<h2>Expected reorg <strong id="next-reorg-days"></strong></h2>
<ul>
<li>(since September 5, 2024)</li>
<li>(since August 1, 2024)</li>
<li>(since July 30, 2024)</li>
<li>(since May 24, 2024)</li>
<li>(since February 21, 2024)</li>
<li>(since February 8, 2024)</li>
<li>(since February 7, 2024)</li>
<li>(since January 11, 2024)</li>
<li>(since August 14, 2023)</li>
<li>(since April 24, 2023)</li>
<li>(since April 19, 2023)</li>
<li>(since January 26, 2023)</li>
<li>(since August 16, 2022)</li>
<li>(since June 17, 2022)</li>
<li>(since March 2, 2022)</li>
<li>(since December 7, 2021)</li>
<li>(since May 4, 2021)</li>
<li>(since January 19, 2021)</li>
<li>(since August 31, 2020)</li>
<li>(since August 11, 2020)</li>
<li>(since April 8, 2020)</li>
<li>(since March 5, 2020)</li>
<li>(since January 24, 2020)</li>
<li>(since September 24, 2019)</li>
<li>(since June 7, 2019)</li>
<li>(since May 27, 2019)</li>
<li>(since April 25, 2019)</li>
<li>(since March 12, 2019)</li>
<li>(since February 19, 2019)</li>
<li>(since January 30, 2019)</li>
<li>(since January 29, 2019)</li>
<li>(since October 18, 2018)</li>
<li>(since April 6, 2018)</li>
<li>(since March 6, 2018)</li>
<li>(since February 21, 2018)</li>
<li>(since February 1, 2018)</li>
<li>(since January 18, 2018)</li>
<li>(since December 18, 2017)</li>
<li>(since November 21, 2017)</li>
<li>(since August 16, 2017)</li>
<li>(since June 12, 2017)</li>
<li>(since May 5, 2017)</li>
<li>(since April 26, 2017)</li>
<li>(since April 1, 2017)</li>
<li>(since March 17, 2017)</li>
<li>(since February 15, 2017)</li>
<li>(since February 2, 2017)</li>
<li>(since November 11, 2016)</li>
<li>(since September 15, 2016)</li>
<li>(since August 31, 2016)</li>
<li>(since May 23, 2016)</li>
<li>(since May 13, 2016)</li>
<li>(since April 15, 2016)</li>
<li>(since March 21, 2016)</li>
<li>(since March 18, 2016)</li>
<li>(since January 20, 2016)</li>
<li>(since December 8, 2015)</li>
<li>(since December 2, 2015)</li>
<li>(since November 17, 2015)</li>
<li>(since October 15, 2015)</li>
<li>(since October 12, 2015)</li>
<li>(since September 18, 2015)</li>
<li>(since August 27, 2015)</li>
<li>(since August 26, 2015)</li>
<li>(since July 2, 2015)</li>
<li>(since June 18, 2015)</li>
<li>(since June 5, 2015)</li>
<li>(since May 28, 2015)</li>
<li>(since May 20, 2015)</li>
<li>(since May 4, 2015)</li>
<li>(since April 21, 2015)</li>
<li>(since April 14, 2015)</li>
<li>(since March 27, 2015)</li>
</ul>
<script>
function require(name) {
switch (name) {
case 'jquery': return function(key) {
if (key[0] === '#')
return document.getElementById(key.substring(1, key.length));
return document.getElementsByTagName(key);
};
case 'moment': return function(d) {
return new Date(d);
};
case 'mocha': return {
describe: function(txt, func) {
console.log(txt);
try {
func();
console.log('PASS!');
} catch(e) {
console.log('FAIL!', e.toString());
}
}
};
case 'should': return {
equal: function(a,b) {
if ((!!a && a===b) || (1/a === 1/b) || (a!==a && b!==b)) {
return;
}
throw new Error('equality error, expected ' + b + ', got ' + a);
}
};
default: alert('unimplemented library!!!!1!');
}
}
var $ = require('jquery');
var moment = require('moment');
function parseDate(txt) {
return moment(txt.replace('(since', '').replace(')', ''));
}
// unit tests, yo
var mocha = require('mocha');
var should = require('should');
mocha.describe('a LI date element should be correctly parsed', function() {
should.equal(+parseDate('(since July 13, 2017)'), 1499896800000 /* big party */);
});
var NOW = +new Date();
var ONE_DAY = 24 * 60 * 60 * 1000;
var lis = $('li');
var reorgs = [];
for (var i = 0; i < lis.length; i++) {
reorgs.push(parseDate(lis[i].textContent));
// Only use recent reorgs from the last 2 years if there were 10 reorgs
// or use the last 10 reorgs (exceeding the past 2 years).
if (reorgs.length == 10) {
break;
}
if ((+reorgs[0] - +reorgs[reorgs.length - 1]) / ONE_DAY > 2 * 365) {
break;
}
}
var lastReorg = +reorgs[0];
var firstReorg = +reorgs[reorgs.length - 1];
var daysSinceLastReorg = Math.floor((NOW - lastReorg) / ONE_DAY);
$('#last-reorg-days').textContent = daysSinceLastReorg;
let avgTimeBetweenReorgs;
if (reorgs.length == 1) {
// Only one reorg so far, assume reorg every 8 weeks.
avgTimeBetweenReorgs = 8 * 7 * ONE_DAY;
} else {
avgTimeBetweenReorgs = (lastReorg - firstReorg) / (reorgs.length - 1);
}
var expectedNextReorg = lastReorg + avgTimeBetweenReorgs;
let expectedNextReorgDay = new Date(expectedNextReorg);
if (expectedNextReorgDay.getDay() == 6) {
// Saturday, move it Monday.
expectedNextReorg += 2 * ONE_DAY;
} else if (expectedNextReorgDay.getDay() == 0) {
// Sunday, move it Monday.
expectedNextReorg += 1 * ONE_DAY;
}
var daysToNextReorg = Math.ceil((expectedNextReorg - NOW) / ONE_DAY);
const relativeTimeFormatter = new Intl.RelativeTimeFormat("en", {
numeric: "always",
style: "long",
});
let nextReorgText = relativeTimeFormatter.format(daysToNextReorg, "day");
nextReorgText += " (" + (new Date(expectedNextReorg)).toDateString() + ")";
$('#next-reorg-days').textContent = nextReorgText;
$('#answer').textContent = daysToNextReorg > 0 ? 'YES' : 'NO';
</script>
</body>
</html>