faker icon indicating copy to clipboard operation
faker copied to clipboard

feat: add system.cron

Open nhammond101 opened this issue 2 years ago • 4 comments

Adds new functionality to generate cron expressions.

New Function:

  • faker.system.cron()

Usage:

faker.system.cron():

// generates a random cron expression
console.log(faker.system.cron()): // '45 23 * * 6'

supports an optional options object, which currently has a year component

// generates a random cron expression with a year
console.log(faker.system.cron()): // '45 23 * * 6 2067'

Unit tests for the functions added.

nhammond101 avatar May 01 '22 10:05 nhammond101

Codecov Report

Merging #897 (e73eca9) into main (7f8b871) will decrease coverage by 0.00%. The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #897      +/-   ##
==========================================
- Coverage   99.63%   99.62%   -0.01%     
==========================================
  Files        2160     2160              
  Lines      240541   240614      +73     
  Branches     1014     1015       +1     
==========================================
+ Hits       239652   239710      +58     
- Misses        868      883      +15     
  Partials       21       21              
Impacted Files Coverage Δ
src/modules/system/index.ts 100.00% <100.00%> (ø)
src/modules/internet/user-agent.ts 82.53% <0.00%> (-3.97%) :arrow_down:

codecov[bot] avatar May 01 '22 10:05 codecov[bot]

Targeting it for v6.3, but I don't think it will make it so fast We plan to work on v7 in next "sprint"

Shinigami92 avatar May 01 '22 10:05 Shinigami92

Should we add some range for the cron: E.g. yearly, daily, ... (nothing precise, just some generaly direction)

ST-DDT avatar May 01 '22 11:05 ST-DDT

Should we also try to generate some more advanced cron strings like 23 0-20/2 * * *?

i'd like to, I wanted to get the simplest expressions generated first and potentially gauge demand

nhammond101 avatar May 01 '22 17:05 nhammond101

@nhammond101 Could you please update this PR?

ST-DDT avatar Aug 16 '22 09:08 ST-DDT

Please rebase your commits/PR:

git fetch --all
git rebase origin/main
git push -f

(assuming origin is the main faker repository)

Alternatively, we can do that for you, but then you have to reset your local checkout.

ST-DDT avatar Aug 25 '22 21:08 ST-DDT

@Shinigami92 if you get a few minutes, would you post your approach?

nhammond101 avatar Aug 26 '22 14:08 nhammond101

if you get a few minutes, would you post your approach?

See here: https://github.com/faker-js/faker/pull/897#discussion_r956063709

Shinigami92 avatar Aug 26 '22 14:08 Shinigami92