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
|
<script setup lang="ts">
import cronstrue from 'cronstrue';
import { isValidCron } from 'cron-validator';
import { useStyleStore } from '@/stores/style.store';
function isCronValid(v: string) {
return isValidCron(v, { allowBlankDay: true, alias: true, seconds: true });
}
const styleStore = useStyleStore();
const cron = ref('40 * * * *');
const cronstrueConfig = reactive({
verbose: true,
dayOfWeekStartIndexZero: true,
use24HourTimeFormat: true,
throwExceptionOnParseError: true,
});
const helpers = [
{
symbol: '*',
meaning: 'Any value',
example: '* * * *',
equivalent: 'Every minute',
},
{
symbol: '-',
meaning: 'Range of values',
example: '1-10 * * *',
equivalent: 'Minutes 1 through 10',
},
{
symbol: ',',
meaning: 'List of values',
example: '1,10 * * *',
equivalent: 'At minutes 1 and 10',
},
{
symbol: '/',
meaning: 'Step values',
example: '*/10 * * *',
equivalent: 'Every 10 minutes',
},
{
symbol: '@yearly',
meaning: 'Once every year at midnight of 1 January',
example: '@yearly',
equivalent: '0 0 1 1 *',
},
{
symbol: '@annually',
meaning: 'Same as @yearly',
example: '@annually',
equivalent: '0 0 1 1 *',
},
{
symbol: '@monthly',
meaning: 'Once a month at midnight on the first day',
example: '@monthly',
equivalent: '0 0 1 * *',
},
{
symbol: '@weekly',
meaning: 'Once a week at midnight on Sunday morning',
example: '@weekly',
equivalent: '0 0 * * 0',
},
{
symbol: '@daily',
meaning: 'Once a day at midnight',
example: '@daily',
equivalent: '0 0 * * *',
},
{
symbol: '@midnight',
meaning: 'Same as @daily',
example: '@midnight',
equivalent: '0 0 * * *',
},
{
symbol: '@hourly',
meaning: 'Once an hour at the beginning of the hour',
example: '@hourly',
equivalent: '0 * * * *',
},
{
symbol: '@reboot',
meaning: 'Run at startup',
example: '',
equivalent: '',
},
];
const cronString = computed(() => {
if (isCronValid(cron.value)) {
return cronstrue.toString(cron.value, cronstrueConfig);
}
return ' ';
});
const cronValidationRules = [
{
validator: (value: string) => isCronValid(value),
message: 'This cron is invalid',
},
];
</script>
<template>
<c-card>
<div mx-auto max-w-sm>
<c-input-text
v-model:value="cron"
size="large"
placeholder="* * * * *"
:validation-rules="cronValidationRules"
mb-3
/>
</div>
<div class="cron-string">
{{ cronString }}
</div>
<n-divider />
<div flex justify-center>
<n-form :show-feedback="false" label-width="170" label-placement="left">
<n-form-item label="Verbose">
<n-switch v-model:value="cronstrueConfig.verbose" />
</n-form-item>
<n-form-item label="Use 24 hour time format">
<n-switch v-model:value="cronstrueConfig.use24HourTimeFormat" />
</n-form-item>
<n-form-item label="Days start at 0">
<n-switch v-model:value="cronstrueConfig.dayOfWeekStartIndexZero" />
</n-form-item>
</n-form>
</div>
</c-card>
<c-card>
<pre>
┌──────────── [optional] seconds (0 - 59)
| ┌────────── minute (0 - 59)
| | ┌──────── hour (0 - 23)
| | | ┌────── day of month (1 - 31)
| | | | ┌──── month (1 - 12) OR jan,feb,mar,apr ...
| | | | | ┌── day of week (0 - 6, sunday=0) OR sun,mon ...
| | | | | |
* * * * * * command</pre>
<div v-if="styleStore.isSmallScreen">
<c-card v-for="{ symbol, meaning, example, equivalent } in helpers" :key="symbol" mb-3 important:border-none>
<div>
Symbol: <strong>{{ symbol }}</strong>
</div>
<div>
Meaning: <strong>{{ meaning }}</strong>
</div>
<div>
Example:
<strong><code>{{ example }}</code></strong>
</div>
<div>
Equivalent: <strong>{{ equivalent }}</strong>
</div>
</c-card>
</div>
<n-table v-else size="small">
<thead>
<tr>
<th class="text-left" scope="col">
Symbol
</th>
<th class="text-left" scope="col">
Meaning
</th>
<th class="text-left" scope="col">
Example
</th>
<th class="text-left" scope="col">
Equivalent
</th>
</tr>
</thead>
<tbody>
<tr v-for="{ symbol, meaning, example, equivalent } in helpers" :key="symbol">
<td>{{ symbol }}</td>
<td>{{ meaning }}</td>
<td>
<code>{{ example }}</code>
</td>
<td>{{ equivalent }}</td>
</tr>
</tbody>
</n-table>
</c-card>
</template>
<style lang="less" scoped>
::v-deep(input) {
font-size: 30px;
font-family: monospace;
padding: 5px;
text-align: center;
}
.cron-string {
text-align: center;
font-size: 22px;
opacity: 0.8;
margin: 5px 0 15px;
}
pre {
overflow: auto;
padding: 10px 0;
}
</style>
|