File size: 7,092 Bytes
2a5feb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>cron.explain — Human-readable cron expressions</title>
<meta name="description" content="Instantly translate cron expressions to plain English. Free, fast, no signup.">
<style>
  * { margin: 0; padding: 0; box-sizing: border-box; }
  body { background: #0d1117; color: #c9d1d9; font-family: -apple-system, 'Segoe UI', monospace; min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 3rem 1rem; }
  h1 { font-size: 2rem; margin-bottom: 0.25rem; color: #f0f6fc; }
  .sub { color: #484f58; margin-bottom: 2rem; }
  .input-row { display: flex; gap: 0.5rem; width: 100%; max-width: 600px; margin-bottom: 1.5rem; }
  input { flex: 1; background: #161b22; border: 1px solid #30363d; border-radius: 6px; padding: 0.85rem 1rem; color: #f0f6fc; font-family: 'Courier New', monospace; font-size: 1.1rem; outline: none; }
  input:focus { border-color: #58a6ff; }
  input::placeholder { color: #484f58; }
  .result { background: #161b22; border: 1px solid #30363d; border-radius: 8px; padding: 1.5rem; width: 100%; max-width: 600px; min-height: 80px; line-height: 1.8; }
  .result .english { color: #58a6ff; font-size: 1.15rem; }
  .result .detail { color: #8b949e; font-size: 0.9rem; margin-top: 0.75rem; }
  .result .next { color: #3fb950; font-size: 0.85rem; margin-top: 0.5rem; }
  .result .error { color: #f85149; }
  .examples { margin-top: 2rem; width: 100%; max-width: 600px; }
  .examples h3 { color: #484f58; font-size: 0.85rem; margin-bottom: 0.75rem; text-transform: uppercase; letter-spacing: 0.1em; }
  .ex { display: inline-block; background: #161b22; border: 1px solid #21262d; border-radius: 4px; padding: 0.35rem 0.65rem; margin: 0.2rem; cursor: pointer; font-size: 0.85rem; color: #8b949e; font-family: monospace; }
  .ex:hover { border-color: #58a6ff; color: #58a6ff; }
  .footer { margin-top: 3rem; color: #30363d; font-size: 0.75rem; text-align: center; }
  .footer a { color: #484f58; text-decoration: none; }
</style>
</head>
<body>
<h1>cron.explain</h1>
<p class="sub">Paste a cron expression. Get English.</p>

<div class="input-row">
  <input id="cron" type="text" placeholder="*/5 * * * *" autofocus>
</div>
<div class="result" id="result">
  <span class="english">Type a cron expression above</span>
</div>

<div class="examples">
  <h3>Try these</h3>
  <span class="ex" onclick="tryEx('*/5 * * * *')">*/5 * * * *</span>
  <span class="ex" onclick="tryEx('0 9 * * 1-5')">0 9 * * 1-5</span>
  <span class="ex" onclick="tryEx('0 0 1 * *')">0 0 1 * *</span>
  <span class="ex" onclick="tryEx('30 4 * * SUN')">30 4 * * SUN</span>
  <span class="ex" onclick="tryEx('0 */2 * * *')">0 */2 * * *</span>
  <span class="ex" onclick="tryEx('15 10 * * 1,3,5')">15 10 * * 1,3,5</span>
  <span class="ex" onclick="tryEx('0 0 * * *')">0 0 * * *</span>
  <span class="ex" onclick="tryEx('5 4 * * SUN')">5 4 * * SUN</span>
</div>

<div class="footer">
  Built by Atreus — March 23, 2026<br>
  <a href="http://localhost:8889">Play "Two Terminals"</a>
</div>

<script>
const DAYS = {0:'Sunday',1:'Monday',2:'Tuesday',3:'Wednesday',4:'Thursday',5:'Friday',6:'Saturday',7:'Sunday',SUN:'Sunday',MON:'Monday',TUE:'Tuesday',WED:'Wednesday',THU:'Thursday',FRI:'Friday',SAT:'Saturday'};
const MONTHS = {1:'January',2:'February',3:'March',4:'April',5:'May',6:'June',7:'July',8:'August',9:'September',10:'October',11:'November',12:'December'};

function tryEx(v) { document.getElementById('cron').value = v; explain(); }

document.getElementById('cron').addEventListener('input', explain);

function explain() {
  const val = document.getElementById('cron').value.trim();
  const el = document.getElementById('result');
  if (!val) { el.innerHTML = '<span class="english">Type a cron expression above</span>'; return; }

  const parts = val.split(/\s+/);
  if (parts.length < 5 || parts.length > 6) {
    el.innerHTML = '<span class="error">Expected 5 fields: minute hour day-of-month month day-of-week</span>';
    return;
  }

  try {
    const [min, hour, dom, month, dow] = parts;
    const phrases = [];

    // Minute
    if (min === '*') phrases.push('every minute');
    else if (min.startsWith('*/')) phrases.push(`every ${min.slice(2)} minutes`);
    else if (min.includes(',')) phrases.push(`at minutes ${min}`);
    else if (min.includes('-')) phrases.push(`minutes ${min}`);
    else phrases.push(`at minute ${min}`);

    // Hour
    if (hour === '*') { /* already covered */ }
    else if (hour.startsWith('*/')) phrases.push(`every ${hour.slice(2)} hours`);
    else if (hour.includes(',')) phrases.push(`during hours ${hour}`);
    else if (hour.includes('-')) phrases.push(`between ${fmtHour(hour.split('-')[0])} and ${fmtHour(hour.split('-')[1])}`);
    else phrases.push(`at ${fmtHour(hour)}`);

    // Day of month
    if (dom !== '*') {
      if (dom.startsWith('*/')) phrases.push(`every ${dom.slice(2)} days`);
      else if (dom.includes(',')) phrases.push(`on days ${dom} of the month`);
      else phrases.push(`on day ${dom} of the month`);
    }

    // Month
    if (month !== '*') {
      if (month.includes(',')) phrases.push(`in ${month.split(',').map(m => MONTHS[m] || m).join(', ')}`);
      else if (month.includes('-')) { const [a,b] = month.split('-'); phrases.push(`from ${MONTHS[a]||a} through ${MONTHS[b]||b}`); }
      else phrases.push(`in ${MONTHS[month] || month}`);
    }

    // Day of week
    if (dow !== '*') {
      if (dow.includes('-')) {
        const [a,b] = dow.split('-');
        phrases.push(`${DAYS[a]||a} through ${DAYS[b]||b}`);
      } else if (dow.includes(',')) {
        phrases.push(`on ${dow.split(',').map(d => DAYS[d]||d).join(', ')}`);
      } else {
        phrases.push(`on ${DAYS[dow] || 'day ' + dow}`);
      }
    }

    // Build English
    let english = phrases.join(', ');
    english = english.charAt(0).toUpperCase() + english.slice(1);

    // Friendly summary
    let summary = '';
    if (min === '0' && hour === '0' && dom === '*' && month === '*' && dow === '*') summary = 'Once a day at midnight';
    else if (min === '0' && hour === '*') summary = 'Once every hour, on the hour';
    else if (min.startsWith('*/') && hour === '*' && dom === '*') summary = `Every ${min.slice(2)} minutes, around the clock`;
    else if (min !== '*' && hour !== '*' && dow !== '*' && dom === '*') summary = `A weekly schedule`;
    else if (dom !== '*' && month === '*') summary = 'Monthly schedule';

    let html = `<div class="english">${english}</div>`;
    if (summary) html += `<div class="detail">${summary}</div>`;

    el.innerHTML = html;
  } catch(e) {
    el.innerHTML = `<span class="error">Could not parse: ${e.message}</span>`;
  }
}

function fmtHour(h) {
  const n = parseInt(h);
  if (isNaN(n)) return h;
  if (n === 0) return '12:00 AM (midnight)';
  if (n === 12) return '12:00 PM (noon)';
  if (n < 12) return `${n}:00 AM`;
  return `${n-12}:00 PM`;
}

// Auto-explain if something's in the box
explain();
</script>
</body>
</html>