-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrontab.html
More file actions
726 lines (675 loc) · 22.1 KB
/
crontab.html
File metadata and controls
726 lines (675 loc) · 22.1 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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
<!DOCTYPE html>
<meta charset="utf-8">
<title>crontab</title>
<style>
* {
box-sizing: border-box;
}
::selection {
background-color: rgba(255, 255, 128, .2);
}
html {
color: #cccccc;
background-color: #1a1a1a;
text-align: center;
font-family: "Courier New", Courier, monospace;
font-size: 1.3em;
}
body {
max-width: 900px;
margin: auto;
padding: 0 1em;
}
.clickable {
text-decoration: underline;
cursor: pointer;
user-select: none;
}
#hr {
font-family: Georgia, serif;
font-size: 200%;
font-style: italic;
margin-bottom: .2em;
margin-top: .9em;
}
#hr > .active {
color: #ffff80;
}
#anotherDiv {
font-size: 75%;
}
.example {
font-size: 75%;
float: right;
}
#input {
font-family: inherit;
text-align: center;
font-size: 250%;
width: 100%;
background-color: #333333;
border: 1px solid #cccccc;
border-radius: 1em;
color: #ffffff;
margin-top: 7px;
}
#input.invalid {
border-color: darkred;
}
#input.warning {
border-color: saddlebrown;
}
#input:focus {
outline: none;
}
#input::selection {
color: #ffff80;
background-color: rgba(255, 255, 128, .2);
}
#warningDiv {
color: saddlebrown;
font-size: 75%;
height: 0;
}
#partExplanationDiv {
font-size: 75%;
color: #a8a8a8;
height: 24em;
}
.cron-parts > * {
display: inline-block;
vertical-align: top;
border-radius: 1em;
margin: 1.1em .36em;
}
.cron-parts > .active {
color: #ffff80;
}
.cron-parts > .invalid {
background-color: darkred;
}
.cron-parts > .warning {
background-color: saddlebrown;
}
table {
margin-left: auto;
margin-right: auto;
border-collapse: collapse;
max-width: 400px;
}
th,
td {
border-top: 1px solid #333333;
border-bottom: 1px solid #333333;
}
th {
width: 13em;
text-align: right;
padding: .2em 1em .2em 0;
}
td {
text-align: left;
padding: .2em 0 .2em 1em;
}
.tips {
font-size: 75%;
text-align: left;
display: inline-block;
vertical-align: top;
margin-bottom: 3em;
column-count: 2;
}
ul {
margin: 0;
}
@media screen and (max-width: 480px) {
#input {
font-size: 200%;
}
#partExplanationDiv .clickable {
padding: .1em .01em;
margin: 0 .1em 0 .1em;
}
table {
max-width: 360px;
}
th {
width: 7em;
}
.tips {
column-count: 1;
}
}
</style>
<div id="hr"></div>
<div id=anotherDiv></div>
<div><input id="input" autocomplete="off"></div>
<div class="example clickable">random</div>
<div id="warningDiv">Non standard! May not work with every cron.</div>
<div id=partExplanationDiv>
<div class="cron-parts">
<div>minute</div>
<div>hour</div>
<div>day<br>(month)</div>
<div>month</div>
<div>day<br>(week)</div>
</div>
<table>
<tbody>
<tr><th>*</th><td>any value</td></tr>
<tr><th>,</th><td>value list separator</td></tr>
<tr><th>-</th><td>range of values</td></tr>
<tr><th>/</th><td>step values</td></tr>
</tbody>
<tbody>
<tr><th>@yearly</th><td>(non-standard)</td></tr>
<tr><th>@annually</th><td>(non-standard)</td></tr>
<tr><th>@monthly</th><td>(non-standard)</td></tr>
<tr><th>@weekly</th><td>(non-standard)</td></tr>
<tr><th>@daily</th><td>(non-standard)</td></tr>
<tr><th>@hourly</th><td>(non-standard)</td></tr>
<tr><th>@reboot</th><td>(non-standard)</td></tr>
</tbody>
<tbody>
<tr><th>0-59</th><td>allowed values</td></tr>
</tbody>
<tbody>
<tr><th>0-23</th><td>allowed values</td></tr>
</tbody>
<tbody>
<tr><th>1-31</th><td>allowed values</td></tr>
</tbody>
<tbody>
<tr><th>1-12</th><td>allowed values</td></tr>
<tr><th>JAN-DEC</th><td>alternative single values</td></tr>
</tbody>
<tbody>
<tr><th>0-6</th><td>allowed values</td></tr>
<tr><th>SUN-SAT</th><td>alternative single values</td></tr>
<tr><th>7</th><td>sunday (non-standard)</td></tr>
</tbody>
</table>
</div>
<div class="tips">
<ul>
<li data-cron="* * * * *">every minute</li>
<li data-cron="* * * * *">every 1 minute</li>
<li data-cron="*/2 * * * *">every 2 minutes</li>
<li data-cron="*/2 * * * *">every even minute</li>
<li data-cron="1-59/2 * * * *">every uneven minute</li>
<li data-cron="*/3 * * * *">every 3 minutes</li>
<li data-cron="*/4 * * * *">every 4 minutes</li>
<li data-cron="*/5 * * * *">every 5 minutes</li>
<li data-cron="*/5 * * * *">every five minutes</li>
<li data-cron="*/6 * * * *">every 6 minutes</li>
<li data-cron="*/10 * * * *">every 10 minutes</li>
<li data-cron="*/10 * * * *">every ten minutes</li>
<li data-cron="*/15 * * * *">every 15 minutes</li>
<li data-cron="*/15 * * * *">every fifteen minutes</li>
<li data-cron="*/15 * * * *">every quarter hour</li>
<li data-cron="*/20 * * * *">every 20 minutes</li>
<li data-cron="*/30 * * * *">every 30 minutes</li>
<li data-cron="30 * * * *">every hour at 30 minutes</li>
<li data-cron="*/30 * * * *">every half hour</li>
<li data-cron="0 * * * *">every 60 minutes</li>
<li data-cron="0 * * * *">every hour</li>
<li data-cron="0 * * * *">every 1 hour</li>
<li data-cron="0 */2 * * *">every 2 hours</li>
<li data-cron="0 */2 * * *">every two hours</li>
<li data-cron="0 */2 * * *">every even hour</li>
<li data-cron="0 */2 * * *">every other hour</li>
<li data-cron="0 */3 * * *">every 3 hours</li>
<li data-cron="0 */3 * * *">every three hours</li>
<li data-cron="0 */4 * * *">every 4 hours</li>
<li data-cron="0 */6 * * *">every 6 hours</li>
<li data-cron="0 */6 * * *">every six hours</li>
<li data-cron="0 */8 * * *">every 8 hours</li>
<li data-cron="0 */12 * * *">every 12 hours</li>
<li data-cron="0 9-17 * * *">hour range</li>
<li data-cron="0 9-17 * * *">between certain hours</li>
<li data-cron="0 0 * * *">every day</li>
<li data-cron="0 0 * * *">daily</li>
<li data-cron="0 0 * * *">once a day</li>
<li data-cron="0 0 * * *">every night</li>
<li data-cron="0 1 * * *">every day at 1am</li>
<li data-cron="0 2 * * *">every day at 2am</li>
<li data-cron="0 8 * * *">every day 8am</li>
<li data-cron="0 9 * * *">every morning</li>
<li data-cron="0 0 * * *">every midnight</li>
<li data-cron="0 0 * * *">every day at midnight</li>
<li data-cron="0 0 * * *">every night at midnight</li>
<li data-cron="0 0 * * SUN">every sunday</li>
<li data-cron="0 0 * * MON">every monday</li>
<li data-cron="0 0 * * TUE">every tuesday</li>
<li data-cron="0 0 * * WED">every wednesday</li>
<li data-cron="0 0 * * THU">every thursday</li>
<li data-cron="0 0 * * FRI">every friday</li>
<li data-cron="0 0 * * FRI">every friday at midnight</li>
<li data-cron="0 0 * * SAT">every saturday</li>
<li data-cron="0 0 * * 1-5">every weekday</li>
<li data-cron="0 0 * * 1-5">weekdays only</li>
<li data-cron="0 0 * * 1-5">monday to friday</li>
<li data-cron="0 0 * * 6,0">every weekend</li>
<li data-cron="0 0 * * 6,0">weekends only</li>
<li data-cron="0 0 * * 0">every 7 days</li>
<li data-cron="0 0 * * 0">weekly</li>
<li data-cron="0 0 * * 0">once a week</li>
<li data-cron="0 0 * * 0">every week</li>
<li data-cron="0 0 1 * *">every month</li>
<li data-cron="0 0 1 * *">monthly</li>
<li data-cron="0 0 1 * *">once a month</li>
<li data-cron="0 0 1 */2 *">every other month</li>
<li data-cron="0 0 1 */3 *">every quarter</li>
<li data-cron="0 0 1 */6 *">every 6 months</li>
<li data-cron="0 0 1 1 *">every year</li>
</ul>
</div>
<script>
// bug in original:
// 0 0 */4 4 0
// 0 0 29 2 */7
// never run example:
// * * 31 4 *
function ordinal(str) {
return str + ([undefined, "st", "nd", "rd"][+str > 20 ? str % 10 : +str] || "th");
}
function padZero2(e) {
return ("0" + e).slice(-2)
}
function describe_strings(list) {
switch (list.length) {
case 0: return "";
case 1: return list[0];
case 2: return list[0] + " and " + list[1];
default: return list.slice(0, list.length - 1).join(", ") + ", and " + list[list.length - 1]
}
}
function func_p(e, fieldName, itemNames, ubound) {
e = e.split(",").map(function (x) {
if (x == "*") return "every " + fieldName;
x = x.match(/\d+|./g).map(function (e) {
return isNaN(Number(e)) ? e : Number(e)
})
if (Number.isInteger(x[0])) {
if (x.length == 1) {
return "" + (itemNames[x[0]] || x[0]);
} else if (x.length == 3 && "/" === x[1] && Number.isInteger(x[2])) {
return "every " + ordinal(x[2]) + " " + fieldName + " from " + (itemNames[x[0]] || x[0]) + " through " + (itemNames[ubound] || ubound);
} else if (x.length == 3 && "-" === x[1] && Number.isInteger(x[2]) && x[2] >= x[0]) {
return "every " + fieldName + " from " + (itemNames[x[0]] || x[0]) + " through " + (itemNames[x[2]] || x[2]);
} else if (x.length == 5 && "-" === x[1] && Number.isInteger(x[2]) && x[2] >= x[0] && "/" === x[3] && Number.isInteger(x[4]) && x[4] >= 1) {
return "every " + ordinal(x[4]) + " " + fieldName + " from " + (itemNames[x[0]] || x[0]) + " through " + (itemNames[x[2]] || x[2]);
}
} else if (x.length == 3 && "/" === x[1] && Number.isInteger(x[2]) && "*" === x[0]) {
return "every " + ordinal(x[2]) + " " + fieldName;
}
return "";
})
return ((itemNames.length ? "" : fieldName + " ") + describe_strings(e)).replace("every 1st", "every").replace(fieldName + " every", "every").replace(", " + fieldName, ", ").replace(", and " + fieldName, ", and ")
}
function uniq(e) {
return e.reduce(function (e, t) {
if (e.indexOf(t) < 0) e.push(t);
return e;
}, []);
}
function linspaceLike(start, stop, step) {
var r = [];
for (var i = start; i <= stop; i += step) r.push(i);
return r;
}
function nextDate(schedule, time) {
if (!(Object.keys(schedule).length && schedule.months.length && schedule.dates.length && schedule.weekdays.length && schedule.hours.length && schedule.minutes.length)) return undefined;
var utcMilliseconds = time.getUTCMilliseconds();
if (utcMilliseconds != 0) time = new Date(time.getTime() + (1000 - utcMilliseconds));
var utcSeconds = time.getUTCSeconds();
if (utcSeconds != 0) time = new Date(time.getTime() + 1000 * (60 - utcSeconds));
for (var depth = 1; depth < 2048; depth++) {
var month = time.getUTCMonth() + 1;
var year = time.getUTCFullYear();
if (!schedule.months.includes(month)) {
time = new Date(Date.UTC(year, month + 1 - 1, 1, 0, 0));
continue;
}
var date = time.getUTCDate();
var s = schedule.dates.includes(date);
var c = schedule.weekdays.includes(time.getUTCDay());
if (schedule.daysAnded && (!s || !c) || !schedule.daysAnded && !s && !c) {
time = new Date(Date.UTC(year, month - 1, date + 1, 0, 0));
continue;
}
var hour = time.getUTCHours();
if (!schedule.hours.includes(hour)) {
time = new Date(Date.UTC(year, month - 1, date, hour + 1, 0));
continue;
}
var minute = time.getUTCMinutes();
if (!schedule.minutes.includes(minute)) {
time = new Date(Date.UTC(year, month - 1, date, hour, minute + 1));
continue;
}
return time;
}
return undefined;
};
setTimeout(function () {
state.date = new Date
update()
setInterval(function () {
state.date = new Date
update()
}, 60000);
}, 1000 * (61 - new Date().getUTCSeconds()));
var randomExamplesArray = [
"5 0 * 8 *",
"15 14 1 * *",
"0 22 * * 1-5",
"23 0-20/2 * * *",
"5 4 * * sun",
"0 0,12 1 */2 *",
"0 4 8-14 * *",
"0 0 1,15 * 3",
"@weekly",
]
var normalizeSpace = function (e) {
return e.trim().replace(/\s+/g, " ")
};
function parseSchedule(text) {
text = normalizeSpace(text)
// prenormalize
var originalParts = text.split(" ")
var prenormalized
if (originalParts.length == 1 && "@reboot" == originalParts[0]) {
prenormalized = {
originalParts: originalParts,
parts: [],
}
} else {
var parts = (originalParts.length == 1 ? ({
"@yearly": ["0", "0", "1", "1", "*"],
"@annually": ["0", "0", "1", "1", "*"],
"@monthly": ["0", "0", "1", "*", "*"],
"@weekly": ["0", "0", "*", "*", "0"],
"@daily": ["0", "0", "*", "*", "*"],
"@midnight": ["0", "0", "*", "*", "*"],
"@hourly": ["0", "*", "*", "*", "*"],
}[originalParts[0]] || [originalParts[0]]) : originalParts).map(function (e, t) {
var i;
if (t == 3) {
i = { jan: "1", feb: "2", mar: "3", apr: "4", may: "5", jun: "6", jul: "7", aug: "8", sep: "9", oct: "10", nov: "11", dec: "12" }
} else if (t == 4) {
i = { sun: "0", mon: "1", tue: "2", wed: "3", thu: "4", fri: "5", sat: "6" }
} else {
return e
}
return Object.keys(i).reduce(function (e, t) {
var from = new RegExp("(^|[ ,-/])" + t + "($|[ ,-/])", "gi");
var to = "$1" + i[t] + "$2";
return e.replace(from, to).replace(from, to);
}, e)
})
prenormalized = {
originalParts: originalParts,
parts: parts,
daysAnded: !!parts[2] && "*" === parts[2][0] || !!parts[4] && "*" === parts[4][0]
}
}
// normalize
var validCharacters = /[^\d\-\/\,]/i;
var npts = prenormalized.parts.map(function (e) {
return e.slice(0)
}).map(function (e) {
return e.replace(/\*\/1(?!\d)/g, "*")
});
var schedule
if (npts.length == 0 && prenormalized.originalParts.length) {
schedule = {}
} else {
schedule = {
errors: [],
warnings: [],
daysAnded: prenormalized.daysAnded,
}
if (npts.length != 5) schedule.errors.push("fields");
[["minutes", 0, 59], ["hours", 0, 23], ["dates", 1, 31], ["months", 1, 12], ["weekdays", 0, 6]].forEach(function (bounds, kk) {
var key = bounds[0], lbound = bounds[1], ubound = bounds[2]
if (npts[kk] && npts[kk].length) {
var from = /(^|[,-/])\*($|[,-/])/g
var to = "$1" + lbound + "-" + ubound + "$2"
var v1 = npts[kk].replace(from, to).replace(from, to)
var v2 = {
errors: [],
warnings: [],
}
schedule[key] = []
v1.split(",").forEach(function (e) {
var n = ((e || "").match(/\d+|./g) || []).map(function (e) {
return isNaN(Number(e)) ? e : Number(e)
})
if (Number.isInteger(n[0])) {
if (n.length == 1) {
schedule[key].push(n[0])
} else if (n.length == 3 && "/" === n[1] && Number.isInteger(n[2]) && 1 <= n[2]) {
schedule[key] = schedule[key].concat(linspaceLike(n[0], ubound, n[2]))
v2.warnings.push("nonstandard")
} else if (n.length == 3 && "-" === n[1] && Number.isInteger(n[2]) && n[2] >= n[0]) {
schedule[key] = schedule[key].concat(linspaceLike(n[0], n[2], 1))
} else if (n.length == 5 && "-" === n[1] && Number.isInteger(n[2]) && n[2] >= n[0] && "/" === n[3] && Number.isInteger(n[4]) && 1 <= n[4]) {
schedule[key] = schedule[key].concat(linspaceLike(n[0], n[2], n[4]))
}
} else {
v2.errors.push("invalid part")
}
})
if (kk == 4) schedule[key] = schedule[key].map(function (x) {
return x === 7 ? (v2.warnings.push("sunday"), 0) : x
})
schedule[key] = uniq(schedule[key]).sort((a, b) => a - b).filter(e => !isNaN(e))
v2.errors = uniq(v2.errors)
v2.warnings = uniq(v2.warnings)
var v4 = prenormalized.originalParts[kk]
var out_of_range = schedule[key].length && (schedule[key][0] < lbound || schedule[key][schedule[key].length - 1] > ubound)
if (v2.errors.length || out_of_range || validCharacters.test(v1)) {
schedule[key] = []
schedule.errors.push(key)
}
if (v2.warnings.length || (kk >= 3 && v4 && npts[kk] !== v4 && v4.length > 3 && /\D/.test(v4))) {
schedule.warnings.push(key)
}
} else if (npts[kk] === undefined) {
schedule.errors.push(key)
}
})
schedule.errors.length || delete schedule.errors;
schedule.warnings.length || delete schedule.warnings;
}
// describe
var description
if (!schedule.errors) {
if ("@reboot" == prenormalized.originalParts[0]) {
description = {
special: "After rebooting.",
}
} else {
var dates = prenormalized.parts[2] == "*" ? "" : "on " + func_p(prenormalized.parts[2], "day-of-month", [], 31)
var months = prenormalized.parts[3] == "*" ? "" : "in " + func_p(prenormalized.parts[3], "month", [undefined, "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"], 12)
var weekdays = prenormalized.parts[4] == "*" ? "" : "on " + func_p(prenormalized.parts[4], "day-of-week", ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"], 7)
var datesWeekdays = dates && weekdays ? (prenormalized.daysAnded ? "if it's" : "and") : ""
description = {
start: "At",
dates: dates || undefined,
datesWeekdays: datesWeekdays || undefined,
weekdays: weekdays || undefined,
months: months || undefined,
end: ".",
}
var TWO_DIGITS = /^0*\d\d?$/
if (TWO_DIGITS.test(prenormalized.parts[0]) && TWO_DIGITS.test(prenormalized.parts[1])) {
description.minutes = padZero2(prenormalized.parts[0])
description.hours = padZero2(prenormalized.parts[1])
description.isTime = true
} else {
description.minutes = func_p(prenormalized.parts[0], "minute", [], 59) || undefined
description.hours = prenormalized.parts[1] == "*" ? undefined : "past " + func_p(prenormalized.parts[1], "hour", [], 23);
}
}
}
return {
text: text,
schedule: schedule,
description: description,
isSpecialString: text.startsWith("@")
}
}
var state = Object.assign({
exampleIndex: 0,
selectedPart: undefined,
selectedDirectly: false,
date: new Date,
focussed: false,
}, parseSchedule("5 4 * * *"))
// showNextExample
document.getElementsByClassName("example")[0].onclick = function () {
Object.assign(state, parseSchedule(randomExamplesArray[state.exampleIndex]))
state.exampleIndex = (state.exampleIndex + 1) % randomExamplesArray.length
update()
}
document.querySelectorAll("[data-cron]").forEach(function (el) {
el.className = "clickable"
el.onclick = function () {
Object.assign(state, parseSchedule(this.getAttribute("data-cron")))
update()
input.focus()
}
})
input.oninput = function (e) {
Object.assign(state, parseSchedule(e.target.value))
update()
};
input.onblur = function (e) {
state.text = normalizeSpace(state.text)
state.selectedPart = undefined
state.focussed = false
update()
};
input.onfocus = function (e) {
state.focussed = true
input.onselect()
};
input.onselect = input.onmousedown = input.onkeyup = input.onmouseup = function () {
if (!state.focussed) return
if (state.isSpecialString) {
state.selectedPart = undefined
state.selectedDirectly = true
} else {
var o = normalizeSpace(state.text.substring(0, input.selectionStart + 1)).split(" ").length
state.selectedPart = o === normalizeSpace(state.text.substring(0, input.selectionEnd + 1)).split(" ").length ? Math.max(Math.min(o, 5), 1) : undefined
state.selectedDirectly = true
}
update()
}
for (var jj = 0; jj < 5; jj++) {
partExplanationDiv.children[0].children[jj].onclick = (ii => function () {
state.selectedPart = state.isSpecialString ? undefined : ii + 1
state.selectedDirectly = false
update()
})(jj)
}
function update() {
// human readable
function activeClass(part, t) {
return t.selectedPart === part ? "active" : ""
}
hr.innerHTML = ""
if (state.description) {
var humanDesc = state.description;
var span2 = document.createElement("span");
span2.setAttribute("class", activeClass(1, state));
span2.textContent = humanDesc.minutes
var span3 = document.createElement("span");
span3.setAttribute("class", activeClass(2, state));
span3.textContent = humanDesc.hours
var span4 = document.createElement("span");
span4.setAttribute("class", activeClass(3, state));
span4.textContent = humanDesc.dates
var span5 = document.createElement("span");
span5.textContent = humanDesc.datesWeekdays
var span6 = document.createElement("span");
span6.setAttribute("class", activeClass(5, state));
span6.textContent = humanDesc.weekdays
var span7 = document.createElement("span");
span7.setAttribute("class", activeClass(4, state));
span7.textContent = humanDesc.months
if (humanDesc.special) {
hr.textContent = humanDesc.special
} else {
hr.textContent = humanDesc.start
if (humanDesc.isTime) {
hr.appendChild(document.createTextNode(" "))
hr.appendChild(span3)
hr.appendChild(document.createTextNode(":"))
hr.appendChild(span2)
} else {
if (humanDesc.minutes) hr.appendChild(document.createTextNode(" "))
hr.appendChild(span2)
if (humanDesc.hours) hr.appendChild(document.createTextNode(" "))
hr.appendChild(span3)
}
if (humanDesc.dates) hr.appendChild(document.createTextNode(" "))
hr.appendChild(span4)
if (humanDesc.datesWeekdays) hr.appendChild(document.createTextNode(" "))
hr.appendChild(span5)
if (humanDesc.weekdays) hr.appendChild(document.createTextNode(" "))
hr.appendChild(span6)
if (humanDesc.months) hr.appendChild(document.createTextNode(" "))
hr.appendChild(span7)
hr.appendChild(document.createTextNode(humanDesc.end))
}
}
// next-date
anotherDiv.innerHTML = ""
if (state.schedule && !state.schedule.errors) {
var somedate = nextDate(state.schedule, new Date(Date.UTC(state.date.getFullYear(), state.date.getMonth(), state.date.getDate(), state.date.getHours(), state.date.getMinutes(), state.date.getSeconds())));
if (somedate) {
var ulist = [somedate]
for (var counter = 0; counter < 5; counter++) {
somedate = nextDate(state.schedule, new Date(somedate.getTime() + 1));
ulist.push(somedate);
}
anotherDiv.innerHTML = ulist.map(function (e, t) {
return [t ? "then" : "next", " at ", e.getUTCFullYear(), "-", padZero2(e.getUTCMonth() + 1), "-", padZero2(e.getUTCDate()), " ", padZero2(e.getUTCHours()), ":", padZero2(e.getUTCMinutes()), ":00"].join("")
}).join("<br>");
}
}
// text-editor
if (state.selectedPart && !state.selectedDirectly) {
var parts = state.text.split(" ").slice(0, state.selectedPart)
var selLen = parts.pop().length
var selSta = parts.join(" ").length;
if (selSta > 0) selSta++;
input.selectionStart = selSta;
input.selectionEnd = selSta + selLen;
input.focus()
}
input.className = state.schedule.errors ? "invalid" : state.schedule.warnings ? "warning" : ""
if (!state.focussed) input.value = state.text;
// warning
warningDiv.style.display = state.schedule.warnings ? "" : "none"
// part-explanation
for (var ii = 0; ii < 5; ii++) {
var el = partExplanationDiv.children[0].children[ii]
el.className = "clickable";
if (state.selectedPart == ii + 1) el.classList.add("active");
var r = ["minutes", "hours", "dates", "months", "weekdays"][ii];
if (state.schedule.errors && state.schedule.errors.includes(r)) {
el.classList.add("invalid")
} else if (state.schedule.warnings && state.schedule.warnings.includes(r)) {
el.classList.add("warning")
}
}
for (var ii = 0; ii < 6; ii++) {
partExplanationDiv.children[1].children[ii + 1].style.display = state.selectedPart === (ii ? ii : undefined) ? "" : "none"
}
}
update()
</script>