2
2
import cronstrue from ' cronstrue' ;
3
3
import ctz from ' countries-and-timezones' ;
4
4
import getTimezoneOffset from ' get-timezone-offset' ;
5
- import { getCronType , getLastExecutionTimes , isCronValid } from ' ./crontab-generator.service' ;
5
+ import { type CronType , getLastExecutionTimes , isCronValid } from ' ./crontab-generator.service' ;
6
6
import { useStyleStore } from ' @/stores/style.store' ;
7
7
import { useQueryParamOrStorage } from ' @/composable/queryParams' ;
8
8
@@ -20,10 +20,13 @@ const cronstrueConfig = reactive({
20
20
21
21
// getTimezoneOffset(tz.name, now) / 60
22
22
const browserTimezone = Intl .DateTimeFormat ().resolvedOptions ().timeZone ;
23
- const allTimezones = Object .values (ctz .getAllTimezones ()).map (tz => ({
24
- value: tz .name ,
25
- label: ` ${tz .name === browserTimezone ? ' Browser TZ - ' : ' ' }${tz .name } (${tz .utcOffset === tz .dstOffset ? tz .utcOffsetStr : ` ${tz .utcOffsetStr }/${tz .dstOffsetStr } ` }) ` ,
26
- }));
23
+ const allTimezones = Object .values (ctz .getAllTimezones ()).map ((tz ) => {
24
+ const timezoneUTCDSTOffset = tz .utcOffset === tz .dstOffset ? tz .utcOffsetStr : ` ${tz .utcOffsetStr }/${tz .dstOffsetStr } ` ;
25
+ return {
26
+ value: tz .name ,
27
+ label: ` ${tz .name === browserTimezone ? ' Browser TZ - ' : ' ' }${tz .name } (${timezoneUTCDSTOffset }) ` ,
28
+ };
29
+ });
27
30
const currentTimezone = useQueryParamOrStorage ({ name: ' tz' , storageName: ' crongen:tz' , defaultValue: browserTimezone });
28
31
watchEffect (() => {
29
32
cronstrueConfig .tzOffset = - getTimezoneOffset (currentTimezone .value , new Date ()) / 60 ;
@@ -136,19 +139,24 @@ const awsHelpers = [
136
139
},
137
140
];
138
141
139
- const cronType = computed ({
140
- get() {
141
- return getCronType ( cron . value );
142
- } ,
143
- set (newCronType ) {
142
+ const defaultAWSCronExpression = ' 0 0 ? * 1 * ' ;
143
+ const defaultStandardCronExpression = ' 40 * * * * ' ;
144
+ const cronType = ref < CronType >( ' standard ' );
145
+ watch ( cronType ,
146
+ (newCronType ) => {
144
147
if (newCronType === ' aws' ) {
145
- cron .value = ' 0 0 ? * 1 *' ;
148
+ if (! cron .value || cron .value === defaultStandardCronExpression ) {
149
+ cron .value = defaultAWSCronExpression ;
150
+ }
146
151
}
147
- else {
148
- cron .value = ' 40 * * * *' ;
152
+ else if (newCronType === ' standard' ) {
153
+ if (! cron .value || cron .value === defaultAWSCronExpression ) {
154
+ cron .value = defaultStandardCronExpression ;
155
+ }
149
156
}
150
157
},
151
- });
158
+ );
159
+
152
160
const getHelpers = computed (() => {
153
161
if (cronType .value === ' aws' ) {
154
162
return awsHelpers ;
@@ -165,7 +173,7 @@ const cronString = computed(() => {
165
173
166
174
const cronValidationRules = [
167
175
{
168
- validator : (value : string ) => isCronValid (value ),
176
+ validator : (value : string ) => isCronValid (value , cronType . value ),
169
177
message: ' This cron is invalid' ,
170
178
},
171
179
];
@@ -245,7 +253,7 @@ const executionTimesString = computed(() => {
245
253
</c-card >
246
254
<c-card >
247
255
<pre v-if =" cronType === 'standard'" >
248
- -- Standard CRON Syntax --
256
+ -- Standard CRON Syntax --
249
257
┌──────────── [optional] seconds (0 - 59)
250
258
| ┌────────── minute (0 - 59)
251
259
| | ┌──────── hour (0 - 23)
@@ -256,7 +264,7 @@ const executionTimesString = computed(() => {
256
264
* * * * * * command</pre >
257
265
258
266
<pre v-if =" cronType === 'aws'" >
259
- -- AWS CRON Syntax --
267
+ -- AWS CRON Syntax --
260
268
┌──────────── minute (0 - 59)
261
269
| ┌────────── hour (0 - 23)
262
270
| | ┌──────── day of month (1 - 31) OR ? OR L OR W
0 commit comments