-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): implements the every-at cron syntax (#45)
* wip for every beginning at changes. * revert to original * Initial implementation. * Initial implementation. * Final changes for everyAt implementation. * fix(core): remove node-gyp. * fix(core): make every-at feature disabled by default with option to enable. * fix(core): move every-at tests to their own tests. * feat(core): make the everyAtSyntaxEnabled dynamic * fix(core): change prop name * fix(core): make enableEveryAt dynamic & locale tweak * feat(vuetify): add enableEveryAt prop * feat(vuetify): add enableEveryAt prop * feat(light): add enableEveryAt prop * refactor: rename everyXatY to everyAt --------- Co-authored-by: brandon.arino@carvana.com <brandon.arino@carvana.com> Co-authored-by: Andreas Bichinger <andreas.bichinger@gmail.com>
- Loading branch information
1 parent
21d11c1
commit 4c9f33c
Showing
13 changed files
with
672 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// x/y | ||
import types from '../types' | ||
const { EveryAtColumn } = types | ||
|
||
let re = /^\d+\/\d+$/ | ||
|
||
function buildArray(min, max, at, every) { | ||
let res = [] | ||
for(let i = at; i <= max; i+=every){ | ||
if(i >= min){ | ||
res.push(i) | ||
} | ||
} | ||
return res.length > 0 ? res : null | ||
} | ||
|
||
function strToArray(str, {min, max}){ | ||
if(!re.test(str)){ | ||
return null | ||
} | ||
|
||
let [atStr, everyStr] = str.split('/') | ||
let at = parseInt(atStr) | ||
let every = parseInt(everyStr) | ||
|
||
return buildArray(min, max, at, every) | ||
} | ||
|
||
function arrayToStr(arr, field){ | ||
let {min, max} = field | ||
|
||
if(arr.length < 3){ | ||
return null | ||
} | ||
|
||
let at = arr[0] | ||
let step = arr[1] - arr[0] | ||
|
||
if(step <= 1){ | ||
return null | ||
} | ||
|
||
let computedArray = buildArray(min, max, at, step) | ||
if (arr.length !== computedArray.length) { | ||
return null | ||
} | ||
|
||
let missing = arr.filter((i) => !computedArray.includes(i)) | ||
if (missing.length > 0) { | ||
return null | ||
} | ||
|
||
return new EveryAtColumn(field, step, at) | ||
} | ||
|
||
export default { | ||
strToArray, | ||
arrayToStr | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.