Skip to content

Commit d9f9f1c

Browse files
authored
Merge pull request #9 from FreaKzero/feat/quarterly
feat: quarterly feature
2 parents c84796e + fb3c0fc commit d9f9f1c

3 files changed

Lines changed: 36 additions & 6 deletions

File tree

index.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const langParser = (pattern, string) => {
22
const matchyear = /yearly/.test(string);
33
const matchweek = /weekly/.test(string);
4+
const matchquarter = /quarterly/.test(string);
45
if (matchyear) {
56
return pattern.map((e, idx) => {
67
if ([3, 4].indexOf(idx) > -1) {
@@ -18,7 +19,7 @@ const langParser = (pattern, string) => {
1819
pattern[3] = '*/7';
1920
let changed = false;
2021
return pattern.map((e, idx) => {
21-
if (idx < 4 && e === '*' && !changed) {
22+
if (idx < 3 && e === '*' && !changed) {
2223
return 0;
2324
} else if (idx === 5) {
2425
return '*';
@@ -28,6 +29,17 @@ const langParser = (pattern, string) => {
2829
});
2930
}
3031

32+
if (matchquarter) {
33+
pattern[4] = '*/3';
34+
let changed = false;
35+
return pattern.map((e, idx) => {
36+
if (idx < 3 && e === '*' && !changed) {
37+
return 0;
38+
}
39+
changed = true;
40+
return e;
41+
});
42+
}
3143
return pattern;
3244
};
3345

readme.md

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Be sure when you want to use intervals that you dont use the _at_ token in your
9696

9797
### Tokens:
9898

99-
`second, minute, hour, day, month`
99+
`second, minute, hour, day, month`
100100

101101
Examples:
102102

@@ -106,24 +106,40 @@ on december every 1 hour
106106
every 12 hours
107107
```
108108

109-
### Special Tokens
109+
### Special Tokens
110110

111111
## Yearly
112+
112113
Always will run on first of january at 0:00 if no time is given.
113114
Weekdays are not possible with this expression and will be overwritten.
114115

115-
Examples:
116+
Examples:
117+
116118
```
117119
yearly
118120
yearly at 9:30
119121
```
120122

121123
## Weekly
122-
Weekly will run on every 7th day of month (*/7) at 0:00 if no time is given.
124+
125+
Weekly will run on every 7th day of month (\*/7) at 0:00 if no time is given.
123126
Weekdays are not possible with this expression and will be overwritten.
124127

125-
Examples:
128+
Examples:
129+
126130
```
127131
weekly at 9:30
128132
weekly in 15 minute intervals on january
129133
```
134+
135+
## Quarterly
136+
137+
Quarterly will run on every 3rd month of year (\*/3) at 0:00 if no time is given.
138+
Weekdays are possible
139+
140+
Examples:
141+
142+
```
143+
quarterly at 9:30
144+
quarterly at 9:30 on mondays
145+
```

test.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ test('weekly in 15 minute intervals on january', '0 */15 * */7 1 *');
5858
test('weekly on january', '0 0 0 */7 1 *');
5959
test('weekly at 9:30:15', '15 30 9 */7 * *');
6060
test('weekly at 9:30', '0 30 9 */7 * *');
61+
test('quarterly', '0 0 0 * */3 *');
62+
test('quarterly at 9:30 on mondays', '0 30 9 * */3 1');
6163

6264
if (process.env.TESTWATCH) {
6365
process.stdout.write('\u001b[3J\u001b[2J\u001b[1J');

0 commit comments

Comments
 (0)